[SCM] calf/master: + DSSI, OSC: separated OSC support into two parts, data structure support and network support
js at users.alioth.debian.org
js at users.alioth.debian.org
Tue May 7 15:37:09 UTC 2013
The following commit has been merged in the master branch:
commit 10f6be0014c6fccfffa2ba262435c56c7cb69838
Author: kfoltman <kfoltman at 78b06b96-2940-0410-b7fc-879d825d01d8>
Date: Sat Apr 12 15:33:09 2008 +0000
+ DSSI, OSC: separated OSC support into two parts, data structure support and network support
git-svn-id: https://calf.svn.sourceforge.net/svnroot/calf/trunk@156 78b06b96-2940-0410-b7fc-879d825d01d8
diff --git a/src/Makefile.am b/src/Makefile.am
index 0bc479d..2750673 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -56,7 +56,7 @@ libcalfstatic_la_SOURCES = modules.cpp giface.cpp monosynth.cpp organ.cpp osctl.
libcalfstatic_la_LDFLAGS = -static -lexpat
if USE_GUI
-libcalfgui_la_SOURCES = gui.cpp preset_gui.cpp custom_ctl.cpp osctl.cpp main_win.cpp
+libcalfgui_la_SOURCES = gui.cpp preset_gui.cpp custom_ctl.cpp osctl.cpp osctlnet.cpp main_win.cpp
libcalfgui_la_LDFLAGS = -static
endif
diff --git a/src/calf/osctl.h b/src/calf/osctl.h
index f353d0f..f907917 100644
--- a/src/calf/osctl.h
+++ b/src/calf/osctl.h
@@ -22,7 +22,6 @@
#include <string>
#include <vector>
#include <string.h>
-#include <glib.h>
#include <errno.h>
#include <netinet/in.h>
#include <netdb.h>
@@ -172,40 +171,4 @@ struct osc_message_dump: public osc_message_sink
virtual void receive_osc_message(std::string address, std::string type_tag, const std::vector<osc_data> &args);
};
-struct osc_socket
-{
- GIOChannel *ioch;
- int socket, srcid;
- std::string prefix;
-
- osc_socket() : ioch(NULL), socket(-1), srcid(0) {}
- void bind(const char *hostaddr = "0.0.0.0", int port = 0);
- std::string get_uri() const;
- virtual void on_bind() {}
- virtual ~osc_socket();
-};
-
-struct osc_server: public osc_socket
-{
- static osc_message_dump dump;
- osc_message_sink *sink;
-
- osc_server() : sink(&dump) {}
-
- virtual void on_bind();
-
- static gboolean on_data(GIOChannel *channel, GIOCondition cond, void *obj);
- void parse_message(const char *buffer, int len);
-};
-
-struct osc_client: public osc_socket
-{
- sockaddr_in addr;
-
- void set_addr(const char *hostaddr, int port);
- void set_url(const char *url);
- bool send(const std::string &address, const std::vector<osc_data> &args);
- bool send(const std::string &address);
-};
-
};
diff --git a/src/calf/osctlnet.h b/src/calf/osctlnet.h
new file mode 100644
index 0000000..d177cf0
--- /dev/null
+++ b/src/calf/osctlnet.h
@@ -0,0 +1,68 @@
+/* Calf DSP Library
+ * Open Sound Control UDP support
+ *
+ * Copyright (C) 2007 Krzysztof Foltman
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __CALF_OSCTLNET_H
+#define __CALF_OSCTLNET_H
+
+#include <glib.h>
+
+namespace osctl
+{
+
+struct osc_socket
+{
+ GIOChannel *ioch;
+ int socket, srcid;
+ std::string prefix;
+
+ osc_socket() : ioch(NULL), socket(-1), srcid(0) {}
+ void bind(const char *hostaddr = "0.0.0.0", int port = 0);
+ std::string get_uri() const;
+ virtual void on_bind() {}
+ virtual ~osc_socket();
+};
+
+struct osc_server: public osc_socket
+{
+ static osc_message_dump dump;
+ osc_message_sink *sink;
+
+ osc_server() : sink(&dump) {}
+
+ virtual void on_bind();
+
+ static gboolean on_data(GIOChannel *channel, GIOCondition cond, void *obj);
+ void parse_message(const char *buffer, int len);
+};
+
+struct osc_client: public osc_socket
+{
+ sockaddr_in addr;
+
+ void set_addr(const char *hostaddr, int port);
+ void set_url(const char *url);
+ bool send(const std::string &address, const std::vector<osc_data> &args);
+ bool send(const std::string &address);
+};
+
+};
+
+#endif
diff --git a/src/dssigui.cpp b/src/dssigui.cpp
index 7ced5b8..2ca7f7f 100644
--- a/src/dssigui.cpp
+++ b/src/dssigui.cpp
@@ -33,6 +33,7 @@ using namespace dsp;
using namespace synth;
#include <calf/osctl.h>
+#include <calf/osctlnet.h>
using namespace osctl;
#define debug_printf(...)
diff --git a/src/osctl.cpp b/src/osctl.cpp
index 95d5036..8172ec2 100644
--- a/src/osctl.cpp
+++ b/src/osctl.cpp
@@ -165,8 +165,6 @@ void osc_stream::write(const vector<osc_data> &data)
write(data[pos++]);
}
-osc_message_dump osc_server::dump;
-
void osc_message_dump::receive_osc_message(std::string address, std::string type_tag, const std::vector<osc_data> &args)
{
printf("address: %s, type tag: %s\n", address.c_str(), type_tag.c_str());
@@ -176,143 +174,3 @@ void osc_message_dump::receive_osc_message(std::string address, std::string type
}
}
-void osc_server::parse_message(const char *buffer, int len)
-{
- vector<osc_data> data;
- osc_stream str(string(buffer, len));
- str.read("ss", data);
- if (!data[0].strval.empty() && data[0].strval[0] == '/'
- &&!data[1].strval.empty() && data[1].strval[0] == ',')
- {
- vector<osc_data> data2;
- str.read(data[1].strval.substr(1).c_str(), data2);
- sink->receive_osc_message(data[0].strval, data[1].strval, data2);
- }
-}
-
-void osc_socket::bind(const char *hostaddr, int port)
-{
- socket = ::socket(PF_INET, SOCK_DGRAM, 0);
- if (socket < 0)
- throw osc_net_exception("socket");
-
- sockaddr_in sadr;
- sadr.sin_family = AF_INET;
- sadr.sin_port = htons(port);
- inet_aton(hostaddr, &sadr.sin_addr);
- if (::bind(socket, (sockaddr *)&sadr, sizeof(sadr)) < 0)
- throw osc_net_exception("bind");
- on_bind();
-}
-
-std::string osc_socket::get_uri() const
-{
- sockaddr_in sadr;
- socklen_t len = sizeof(sadr);
- if (getsockname(socket, (sockaddr *)&sadr, &len) < 0)
- throw osc_net_exception("getsockname");
-
- char name[INET_ADDRSTRLEN], buf[32];
-
- inet_ntop(AF_INET, &sadr.sin_addr, name, INET_ADDRSTRLEN);
- sprintf(buf, "%d", ntohs(sadr.sin_port));
-
- return string("osc.udp://") + name + ":" + buf + prefix;
-}
-
-osc_socket::~osc_socket()
-{
- if (ioch)
- g_source_remove(srcid);
- close(socket);
-}
-
-void osc_server::on_bind()
-{
- ioch = g_io_channel_unix_new(socket);
- srcid = g_io_add_watch(ioch, G_IO_IN, on_data, this);
-}
-
-gboolean osc_server::on_data(GIOChannel *channel, GIOCondition cond, void *obj)
-{
- osc_server *self = (osc_server *)obj;
- char buf[16384];
- int len = recv(self->socket, buf, 16384, 0);
- if (len > 0)
- {
- if (buf[0] == '/')
- {
- self->parse_message(buf, len);
- }
- if (buf[0] == '#')
- {
- // XXXKF bundles are not supported yet
- }
- }
- return TRUE;
-}
-
-void osc_client::set_addr(const char *hostaddr, int port)
-{
- addr.sin_family = AF_INET;
- addr.sin_port = htons(port);
- inet_aton(hostaddr, &addr.sin_addr);
-}
-
-void osc_client::set_url(const char *url)
-{
- if (strncmp(url, "osc.udp://", 10))
- throw osc_net_bad_address(url);
- url += 10;
-
- const char *pos = strchr(url, ':');
- const char *pos2 = strchr(url, '/');
- if (!pos || !pos2)
- throw osc_net_bad_address(url);
-
- // XXXKF perhaps there is a default port for osc.udp?
- if (pos2 - pos < 0)
- throw osc_net_bad_address(url);
-
- string hostname = string(url, pos - url);
- int port = atoi(pos + 1);
- prefix = string(pos2);
- printf("hostname %s port %d\n", hostname.c_str(), port);
-
- addr.sin_family = AF_INET;
- addr.sin_port = htons(port);
-
- hostent *he = gethostbyname(hostname.c_str());
- if (!he)
- throw osc_net_dns_exception("gethostbyname");
-
- addr.sin_addr = *(struct in_addr *)he->h_addr;
-}
-
-bool osc_client::send(const std::string &address, const std::vector<osc_data> &args)
-{
- vector<osc_data> data;
- std::string type_tag = ",";
- osc_stream str;
- str.write(prefix + address);
- for (unsigned int i = 0; i < args.size(); i++)
- type_tag += char(args[i].type);
- str.write(type_tag);
-
- for (unsigned int i = 0; i < args.size(); i++)
- str.write(args[i]);
-
- // printf("sending %s\n", str.buffer.c_str());
-
- return ::sendto(socket, str.buffer.data(), str.buffer.length(), 0, (sockaddr *)&addr, sizeof(addr)) == (int)str.buffer.length();
-}
-
-bool osc_client::send(const std::string &address)
-{
- vector<osc_data> data;
- std::string type_tag = ",";
- osc_stream str;
- str.write(prefix + address);
- str.write(type_tag);
- return ::sendto(socket, str.buffer.data(), str.buffer.length(), 0, (sockaddr *)&addr, sizeof(addr)) == (int)str.buffer.length();
-}
diff --git a/src/osctlnet.cpp b/src/osctlnet.cpp
new file mode 100644
index 0000000..c9e8754
--- /dev/null
+++ b/src/osctlnet.cpp
@@ -0,0 +1,154 @@
+#include <calf/osctl.h>
+#include <calf/osctlnet.h>
+#include <assert.h>
+#include <arpa/inet.h>
+#include <sys/socket.h>
+#include <stdlib.h>
+#include <sstream>
+
+using namespace osctl;
+using namespace std;
+
+void osc_server::parse_message(const char *buffer, int len)
+{
+ vector<osc_data> data;
+ osc_stream str(string(buffer, len));
+ str.read("ss", data);
+ if (!data[0].strval.empty() && data[0].strval[0] == '/'
+ &&!data[1].strval.empty() && data[1].strval[0] == ',')
+ {
+ vector<osc_data> data2;
+ str.read(data[1].strval.substr(1).c_str(), data2);
+ sink->receive_osc_message(data[0].strval, data[1].strval, data2);
+ }
+}
+
+void osc_socket::bind(const char *hostaddr, int port)
+{
+ socket = ::socket(PF_INET, SOCK_DGRAM, 0);
+ if (socket < 0)
+ throw osc_net_exception("socket");
+
+ sockaddr_in sadr;
+ sadr.sin_family = AF_INET;
+ sadr.sin_port = htons(port);
+ inet_aton(hostaddr, &sadr.sin_addr);
+ if (::bind(socket, (sockaddr *)&sadr, sizeof(sadr)) < 0)
+ throw osc_net_exception("bind");
+ on_bind();
+}
+
+std::string osc_socket::get_uri() const
+{
+ sockaddr_in sadr;
+ socklen_t len = sizeof(sadr);
+ if (getsockname(socket, (sockaddr *)&sadr, &len) < 0)
+ throw osc_net_exception("getsockname");
+
+ char name[INET_ADDRSTRLEN], buf[32];
+
+ inet_ntop(AF_INET, &sadr.sin_addr, name, INET_ADDRSTRLEN);
+ sprintf(buf, "%d", ntohs(sadr.sin_port));
+
+ return string("osc.udp://") + name + ":" + buf + prefix;
+}
+
+osc_socket::~osc_socket()
+{
+ if (ioch)
+ g_source_remove(srcid);
+ close(socket);
+}
+
+void osc_server::on_bind()
+{
+ ioch = g_io_channel_unix_new(socket);
+ srcid = g_io_add_watch(ioch, G_IO_IN, on_data, this);
+}
+
+gboolean osc_server::on_data(GIOChannel *channel, GIOCondition cond, void *obj)
+{
+ osc_server *self = (osc_server *)obj;
+ char buf[16384];
+ int len = recv(self->socket, buf, 16384, 0);
+ if (len > 0)
+ {
+ if (buf[0] == '/')
+ {
+ self->parse_message(buf, len);
+ }
+ if (buf[0] == '#')
+ {
+ // XXXKF bundles are not supported yet
+ }
+ }
+ return TRUE;
+}
+
+void osc_client::set_addr(const char *hostaddr, int port)
+{
+ addr.sin_family = AF_INET;
+ addr.sin_port = htons(port);
+ inet_aton(hostaddr, &addr.sin_addr);
+}
+
+void osc_client::set_url(const char *url)
+{
+ if (strncmp(url, "osc.udp://", 10))
+ throw osc_net_bad_address(url);
+ url += 10;
+
+ const char *pos = strchr(url, ':');
+ const char *pos2 = strchr(url, '/');
+ if (!pos || !pos2)
+ throw osc_net_bad_address(url);
+
+ // XXXKF perhaps there is a default port for osc.udp?
+ if (pos2 - pos < 0)
+ throw osc_net_bad_address(url);
+
+ string hostname = string(url, pos - url);
+ int port = atoi(pos + 1);
+ prefix = string(pos2);
+ printf("hostname %s port %d\n", hostname.c_str(), port);
+
+ addr.sin_family = AF_INET;
+ addr.sin_port = htons(port);
+
+ hostent *he = gethostbyname(hostname.c_str());
+ if (!he)
+ throw osc_net_dns_exception("gethostbyname");
+
+ addr.sin_addr = *(struct in_addr *)he->h_addr;
+}
+
+bool osc_client::send(const std::string &address, const std::vector<osc_data> &args)
+{
+ vector<osc_data> data;
+ std::string type_tag = ",";
+ osc_stream str;
+ str.write(prefix + address);
+ for (unsigned int i = 0; i < args.size(); i++)
+ type_tag += char(args[i].type);
+ str.write(type_tag);
+
+ for (unsigned int i = 0; i < args.size(); i++)
+ str.write(args[i]);
+
+ // printf("sending %s\n", str.buffer.c_str());
+
+ return ::sendto(socket, str.buffer.data(), str.buffer.length(), 0, (sockaddr *)&addr, sizeof(addr)) == (int)str.buffer.length();
+}
+
+bool osc_client::send(const std::string &address)
+{
+ vector<osc_data> data;
+ std::string type_tag = ",";
+ osc_stream str;
+ str.write(prefix + address);
+ str.write(type_tag);
+ return ::sendto(socket, str.buffer.data(), str.buffer.length(), 0, (sockaddr *)&addr, sizeof(addr)) == (int)str.buffer.length();
+}
+
+osc_message_dump osc_server::dump;
+
--
calf audio plugins packaging
More information about the pkg-multimedia-commits
mailing list