[SCM] calf/master: + DSSI: move OSC server code into separate file, remove dependency of OSC client code on Glib, include OSC code in non-GUI libraries

js at users.alioth.debian.org js at users.alioth.debian.org
Tue May 7 15:38:50 UTC 2013


The following commit has been merged in the master branch:
commit 465160adbbfa20d3abec4f84e72fde9a04b68e86
Author: Krzysztof Foltman <wdev at foltman.com>
Date:   Mon Jan 19 00:25:50 2009 +0000

    + DSSI: move OSC server code into separate file, remove dependency of OSC client code on Glib, include OSC code in non-GUI libraries
    
    This is in preparation for adding OSC sending code to DSSI plugins (for GUI updates).

diff --git a/src/Makefile.am b/src/Makefile.am
index d26e85d..eaef565 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -50,7 +50,7 @@ calfbenchmark_CXXFLAGS = $(AM_CXXFLAGS) -DTEST_OSC
 calfbenchmark_LDADD += libcalfgui.la
 endif
 
-calf_la_SOURCES = modules.cpp modules_dsp.cpp modules_small.cpp giface.cpp monosynth.cpp organ.cpp osctl.cpp plugin.cpp preset.cpp synth.cpp utils.cpp
+calf_la_SOURCES = modules.cpp modules_dsp.cpp modules_small.cpp giface.cpp monosynth.cpp organ.cpp osctl.cpp osctlnet.cpp plugin.cpp preset.cpp synth.cpp utils.cpp
 if USE_DEBUG
 calf_la_LDFLAGS = -rpath $(ladspadir) -avoid-version -module -lexpat -disable-static
 else
@@ -70,7 +70,7 @@ libcalfstatic_la_SOURCES = modules.cpp modules_dsp.cpp modules_small.cpp giface.
 libcalfstatic_la_LDFLAGS = -static -lexpat -disable-shared
 
 if USE_GUI
-libcalfgui_la_SOURCES = gui.cpp ctl_curve.cpp ctl_keyboard.cpp ctl_led.cpp preset_gui.cpp custom_ctl.cpp osctl.cpp osctlnet.cpp main_win.cpp utils.cpp
+libcalfgui_la_SOURCES = gui.cpp ctl_curve.cpp ctl_keyboard.cpp ctl_led.cpp preset_gui.cpp custom_ctl.cpp osctl.cpp osctlnet.cpp osctlserv.cpp main_win.cpp utils.cpp
 libcalfgui_la_LDFLAGS = -static -disable-shared
 endif
 
diff --git a/src/benchmark.cpp b/src/benchmark.cpp
index 3602c32..0b4f0a8 100644
--- a/src/benchmark.cpp
+++ b/src/benchmark.cpp
@@ -26,6 +26,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <config.h>
+#include <glib.h>
 #include <calf/audio_fx.h>
 
 #ifdef BENCHMARK_PLUGINS
@@ -45,6 +46,7 @@ using namespace dsp;
 #ifdef TEST_OSC
 #include <calf/osctl.h>
 #include <calf/osctlnet.h>
+#include <calf/osctlserv.h>
 using namespace osctl;
 #endif
 
diff --git a/src/calf/Makefile.am b/src/calf/Makefile.am
index 9fa6ca9..f5ca0c3 100644
--- a/src/calf/Makefile.am
+++ b/src/calf/Makefile.am
@@ -5,5 +5,5 @@ calf_HEADERS = audio_fx.h benchmark.h biquad.h buffer.h custom_ctl.h \
     delay.h envelope.h fft.h fixed_point.h giface.h gui.h inertia.h jackhost.h ladspa_wrap.h loudness.h \
     lv2_contexts.h lv2_data_access.h lv2_event.h lv2_string_port.h lv2_ui.h lv2_uri_map.h lv2-midiport.h lv2helpers.h lv2wrap.h \
     main_win.h metadata.h modules.h modules_dev.h modules_small.h modules_synths.h modulelist.h \
-    multichorus.h onepole.h organ.h osc.h osctl.h osctlnet.h plugininfo.h preset.h \
+    multichorus.h onepole.h organ.h osc.h osctl.h osctlnet.h osctlserv.h plugininfo.h preset.h \
     preset_gui.h primitives.h synth.h utils.h wave.h
diff --git a/src/calf/osctl.h b/src/calf/osctl.h
index 0914a24..ed46a4f 100644
--- a/src/calf/osctl.h
+++ b/src/calf/osctl.h
@@ -19,6 +19,9 @@
  * Boston, MA 02111-1307, USA.
  */
 
+#ifndef __CALF_OSCTL_H
+#define __CALF_OSCTL_H
+
 #include <string>
 #include <vector>
 #include <string.h>
@@ -539,3 +542,5 @@ struct osc_message_dump: public osc_message_sink<OscStream>
 };
 
 };
+
+#endif
diff --git a/src/calf/osctlnet.h b/src/calf/osctlnet.h
index 7d18cf3..62382ff 100644
--- a/src/calf/osctlnet.h
+++ b/src/calf/osctlnet.h
@@ -22,37 +22,21 @@
 #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) {}
+    osc_socket() : 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
-{
-    osc_message_dump<osc_strstream, std::ostream> dump;
-    osc_message_sink<osc_strstream> *sink;
-    
-    osc_server() : dump(std::cout), 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;
diff --git a/src/calf/osctlnet.h b/src/calf/osctlserv.h
similarity index 61%
copy from src/calf/osctlnet.h
copy to src/calf/osctlserv.h
index 7d18cf3..fa8d79a 100644
--- a/src/calf/osctlnet.h
+++ b/src/calf/osctlserv.h
@@ -1,7 +1,7 @@
 /* Calf DSP Library
- * Open Sound Control UDP support
+ * Open Sound Control UDP server support
  *
- * Copyright (C) 2007 Krzysztof Foltman
+ * Copyright (C) 2007-2009 Krzysztof Foltman
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -19,48 +19,28 @@
  * Boston, MA 02111-1307, USA.
  */
 
-#ifndef __CALF_OSCTLNET_H
-#define __CALF_OSCTLNET_H
+#ifndef __CALF_OSCTLSERV_H
+#define __CALF_OSCTLSERV_H
 
 #include <glib.h>
+#include "osctlnet.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
 {
+    GIOChannel *ioch;
     osc_message_dump<osc_strstream, std::ostream> dump;
     osc_message_sink<osc_strstream> *sink;
     
-    osc_server() : dump(std::cout), sink(&dump) {}
+    osc_server() : ioch(NULL), dump(std::cout), 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, osctl::osc_typed_strstream &stream);
-    bool send(const std::string &address);
+    ~osc_server();
 };
 
 };
diff --git a/src/dssigui.cpp b/src/dssigui.cpp
index f0054ae..dfc6c4f 100644
--- a/src/dssigui.cpp
+++ b/src/dssigui.cpp
@@ -27,6 +27,7 @@
 #include <calf/main_win.h>
 #include <calf/osctl.h>
 #include <calf/osctlnet.h>
+#include <calf/osctlserv.h>
 
 using namespace std;
 using namespace dsp;
diff --git a/src/osctlnet.cpp b/src/osctlnet.cpp
index fd8afd5..d9a682d 100644
--- a/src/osctlnet.cpp
+++ b/src/osctlnet.cpp
@@ -1,3 +1,23 @@
+/* Calf DSP Library
+ * Open Sound Control UDP support
+ *
+ * Copyright (C) 2007-2009 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.
+ */
 #include <calf/osctl.h>
 #include <calf/osctlnet.h>
 #include <assert.h>
@@ -9,83 +29,6 @@
 using namespace osctl;
 using namespace std;
 
-void osc_server::parse_message(const char *buffer, int len)
-{
-    osctl::string_buffer buf(string(buffer, len));
-    osc_strstream str(buf);
-    string address, type_tag;
-    str >> address;
-    str >> type_tag;
-    // cout << "Address " << address << " type tag " << type_tag << endl << flush;
-    if (!address.empty() && address[0] == '/'
-      &&!type_tag.empty() && type_tag[0] == ',')
-    {
-        sink->receive_osc_message(address, type_tag.substr(1), str);
-    }
-}
-
-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;
diff --git a/src/osctlnet.cpp b/src/osctlserv.cpp
similarity index 55%
copy from src/osctlnet.cpp
copy to src/osctlserv.cpp
index fd8afd5..7d12e0e 100644
--- a/src/osctlnet.cpp
+++ b/src/osctlserv.cpp
@@ -1,5 +1,26 @@
+/* Calf DSP Library
+ * Open Sound Control UDP server support
+ *
+ * Copyright (C) 2007-2009 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.
+ */
+
 #include <calf/osctl.h>
-#include <calf/osctlnet.h>
+#include <calf/osctlserv.h>
 #include <assert.h>
 #include <arpa/inet.h>
 #include <sys/socket.h>
@@ -56,8 +77,6 @@ std::string osc_socket::get_uri() const
 
 osc_socket::~osc_socket()
 {
-    if (ioch)
-        g_source_remove(srcid);
     close(socket);
 }
 
@@ -86,60 +105,8 @@ gboolean osc_server::on_data(GIOChannel *channel, GIOCondition cond, void *obj)
     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, osctl::osc_typed_strstream &stream)
-{
-    std::string type_tag = "," + stream.type_buffer->data;
-    osc_inline_strstream hdr;
-    hdr << prefix + address << "," + stream.type_buffer->data;
-    string str = hdr.data + stream.buffer.data;
-    
-    // printf("sending %s\n", str.buffer.c_str());
-
-    return ::sendto(socket, str.data(), str.length(), 0, (sockaddr *)&addr, sizeof(addr)) == (int)str.length();
-}
-
-bool osc_client::send(const std::string &address)
+osc_server::~osc_server()
 {
-    osc_inline_strstream hdr;
-    hdr << prefix + address << ",";
-    
-    return ::sendto(socket, hdr.data.data(), hdr.data.length(), 0, (sockaddr *)&addr, sizeof(addr)) == (int)hdr.data.length();
+    if (ioch)
+        g_source_remove(srcid);
 }
-

-- 
calf audio plugins packaging



More information about the pkg-multimedia-commits mailing list