[SCM] calf/master: More cleanups.

js at users.alioth.debian.org js at users.alioth.debian.org
Tue May 7 15:40:03 UTC 2013


The following commit has been merged in the master branch:
commit e7c7552fc6999ae2dd515ee0e86ce6f861948f08
Author: Krzysztof Foltman <wdev at foltman.com>
Date:   Tue Apr 6 23:23:38 2010 +0100

    More cleanups.
    
    Refactor GUI condition checking into separate interface (avoids creating dummy
    main window objects). Put OSC client and basic server in the same file, and
    leave only glib-dependent code in the separate file. Remove duplicated old
    OSC testing code from DSSI GUI implementation. Remove some of the duplicate
    includes. Move closing LASH session into host_session.

diff --git a/src/Makefile.am b/src/Makefile.am
index 9efba46..0526ad1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -61,7 +61,7 @@ calf_la_LDFLAGS = -rpath $(ladspadir) -avoid-version -module -lexpat -disable-st
 endif
 
 if USE_LV2_GUI
-calflv2gui_la_SOURCES = gui.cpp gui_controls.cpp ctl_curve.cpp ctl_keyboard.cpp ctl_led.cpp custom_ctl.cpp modules.cpp giface.cpp preset.cpp synth.cpp lv2gui.cpp main_win.cpp osctl.cpp osctlnet.cpp osctlserv.cpp utils.cpp
+calflv2gui_la_SOURCES = gui.cpp gui_controls.cpp ctl_curve.cpp ctl_keyboard.cpp ctl_led.cpp custom_ctl.cpp modules.cpp giface.cpp preset.cpp synth.cpp lv2gui.cpp main_win.cpp osctl.cpp osctlnet.cpp utils.cpp
 if USE_DEBUG
 calflv2gui_la_LDFLAGS = -rpath $(lv2dir) -avoid-version -module -lexpat $(GUI_DEPS_LIBS) -disable-static
 else
@@ -73,7 +73,7 @@ libcalfstatic_la_SOURCES = audio_fx.cpp modules.cpp modules_dsp.cpp fluidsynth.c
 libcalfstatic_la_LDFLAGS = -static -lexpat -disable-shared  $(FLUIDSYNTH_DEPS_LIBS)
 
 if USE_GUI
-libcalfgui_la_SOURCES = gui.cpp gui_controls.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_SOURCES = gui.cpp gui_controls.cpp ctl_curve.cpp ctl_keyboard.cpp ctl_led.cpp preset_gui.cpp custom_ctl.cpp osctl.cpp osctlnet.cpp osctl_glib.cpp main_win.cpp utils.cpp
 libcalfgui_la_LDFLAGS = -static -disable-shared
 endif
 
diff --git a/src/benchmark.cpp b/src/benchmark.cpp
index 64c0ff1..a1799c4 100644
--- a/src/benchmark.cpp
+++ b/src/benchmark.cpp
@@ -45,7 +45,7 @@ using namespace dsp;
 #ifdef TEST_OSC
 #include <calf/osctl.h>
 #include <calf/osctlnet.h>
-#include <calf/osctlserv.h>
+#include <calf/osctl_glib.h>
 using namespace osctl;
 #endif
 
diff --git a/src/calf/Makefile.am b/src/calf/Makefile.am
index b233562..73845fe 100644
--- a/src/calf/Makefile.am
+++ b/src/calf/Makefile.am
@@ -6,5 +6,5 @@ noinst_HEADERS = audio_fx.h benchmark.h biquad.h buffer.h custom_ctl.h \
     lv2_progress.h lv2_polymorphic_port.h lv2_string_port.h lv2_ui.h \
     lv2_uri_map.h lv2-midiport.h lv2helpers.h lv2wrap.h \
     main_win.h metadata.h modmatrix.h modules.h modules_dev.h modules_synths.h modulelist.h \
-    multichorus.h onepole.h organ.h osc.h osctl.h osctlnet.h osctlserv.h preset.h \
+    multichorus.h onepole.h organ.h osc.h osctl.h osctlnet.h osctl_glib.h preset.h \
     preset_gui.h primitives.h synth.h utils.h vumeter.h wave.h waveshaping.h
diff --git a/src/calf/giface.h b/src/calf/giface.h
index c07f6df..4982d40 100644
--- a/src/calf/giface.h
+++ b/src/calf/giface.h
@@ -21,9 +21,9 @@
 #ifndef CALF_GIFACE_H
 #define CALF_GIFACE_H
 
+#include <config.h>
 #include <stdint.h>
 #include <stdlib.h>
-#include <pthread.h>
 #include <exception>
 #include <string>
 #include <complex>
diff --git a/src/calf/gui.h b/src/calf/gui.h
index c4a8d88..e657673 100644
--- a/src/calf/gui.h
+++ b/src/calf/gui.h
@@ -141,10 +141,26 @@ public:
 };
 
 class main_window_owner_iface;
-    
-class main_window_iface
+
+/// A class used to inform the plugin GUIs about the environment they run in
+/// (currently: what plugin features are accessible)
+struct gui_environment_iface
+{
+    virtual bool check_condition(const char *name)=0;
+    virtual ~gui_environment_iface() {}
+};
+
+/// Trivial implementation of gui_environment_iface
+class gui_environment: public gui_environment_iface
 {
 public:
+    std::set<std::string> conditions;
+    virtual bool check_condition(const char *name) { return conditions.count(name) != 0; }
+};
+
+/// Interface used by the plugin to communicate with the main hosting window
+struct main_window_iface
+{
     virtual void set_owner(main_window_owner_iface *owner)=0;
 
     virtual void add_plugin(plugin_ctl_iface *plugin)=0;
@@ -152,13 +168,11 @@ public:
     
     virtual void set_window(plugin_ctl_iface *plugin, plugin_gui_window *window)=0;
     virtual void refresh_all_presets(bool builtin_too)=0;
-    virtual bool check_condition(const char *name)=0;
     virtual ~main_window_iface() {}
 };
 
-class main_window_owner_iface
+struct main_window_owner_iface
 {
-public:
     virtual void new_plugin(const char *name) = 0;
     virtual void remove_plugin(plugin_ctl_iface *plugin) = 0;
     virtual char *open_file(const char *name) = 0;
@@ -173,10 +187,11 @@ public:
     GtkWindow *toplevel;
     GtkUIManager *ui_mgr;
     GtkActionGroup *std_actions, *builtin_preset_actions, *user_preset_actions, *command_actions;
+    gui_environment_iface *environment;
     main_window_iface *main;
     int source_id;
 
-    plugin_gui_window(main_window_iface *_main);
+    plugin_gui_window(gui_environment_iface *_env, main_window_iface *_main);
     std::string make_gui_preset_list(GtkActionGroup *grp, bool builtin, char &ch);
     std::string make_gui_command_list(GtkActionGroup *grp);
     void fill_gui_presets(bool builtin, char &ch);
diff --git a/src/calf/host_session.h b/src/calf/host_session.h
index 90733ac..af03af8 100644
--- a/src/calf/host_session.h
+++ b/src/calf/host_session.h
@@ -21,7 +21,13 @@
 #ifndef CALF_HOST_SESSION_H
 #define CALF_HOST_SESSION_H
 
-#include <calf/jackhost.h>
+#include <config.h>
+
+#if USE_LASH
+#include <lash/lash.h>
+#endif
+#include "gui.h"
+#include "jackhost.h"
 
 namespace calf_plugins {
 
diff --git a/src/calf/jackhost.h b/src/calf/jackhost.h
index 30133a9..5cdd508 100644
--- a/src/calf/jackhost.h
+++ b/src/calf/jackhost.h
@@ -21,17 +21,14 @@
 #ifndef __CALF_JACKHOST_H
 #define __CALF_JACKHOST_H
 
+#include <config.h>
+
 #if USE_JACK
 
-#include <jack/jack.h>
-#include <jack/midiport.h>
-#if USE_LASH
-#include <lash/lash.h>
-#endif
-#include "gui.h"
 #include "utils.h"
 #include "vumeter.h"
 #include <pthread.h>
+#include <jack/jack.h>
 
 namespace calf_plugins {
 
diff --git a/src/calf/main_win.h b/src/calf/main_win.h
index 4056b59..e69c9dc 100644
--- a/src/calf/main_win.h
+++ b/src/calf/main_win.h
@@ -31,7 +31,7 @@
 
 namespace calf_plugins {
 
-    class main_window: public main_window_iface
+    class main_window: public main_window_iface, public gui_environment
     {
     public:
         struct plugin_strip
@@ -57,7 +57,6 @@ namespace calf_plugins {
         GtkUIManager *ui_mgr;
         GtkActionGroup *std_actions, *plugin_actions;
         std::map<plugin_ctl_iface *, plugin_strip *> plugins;
-        std::set<std::string> conditions;
         std::vector<plugin_ctl_iface *> plugin_queue;
         std::string prefix;
         bool is_closed;
@@ -85,13 +84,8 @@ namespace calf_plugins {
         void refresh_plugin(plugin_ctl_iface *plugin);
         void on_closed();
         void close_guis();
-        void open_gui(plugin_ctl_iface *plugin);
-        bool check_condition(const char *cond) {
-            return conditions.count(cond) != 0;
-        }
-    
+        void open_gui(plugin_ctl_iface *plugin);    
         void create();
-        
         void open_file();
         void save_file();
         void save_file_as();
diff --git a/src/calf/osctlserv.h b/src/calf/osctl_glib.h
similarity index 76%
copy from src/calf/osctlserv.h
copy to src/calf/osctl_glib.h
index 84535c8..3242602 100644
--- a/src/calf/osctlserv.h
+++ b/src/calf/osctl_glib.h
@@ -19,8 +19,8 @@
  * Boston, MA  02110-1301  USA
  */
 
-#ifndef __CALF_OSCTLSERV_H
-#define __CALF_OSCTLSERV_H
+#ifndef __CALF_OSCTLGLIB_H
+#define __CALF_OSCTLGLIB_H
 
 #include <glib.h>
 #include "osctlnet.h"
@@ -28,20 +28,7 @@
 namespace osctl
 {
     
-
-    
-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) {}
-    
-    void read_from_socket();
-    void parse_message(const char *buffer, int len);    
-    ~osc_server();
-};
-
+/// Glib main loop based implementation of OSC server.
 struct osc_glib_server: public osc_server
 {
     GIOChannel *ioch;
diff --git a/src/calf/osctlnet.h b/src/calf/osctlnet.h
index 5117be0..c619cf7 100644
--- a/src/calf/osctlnet.h
+++ b/src/calf/osctlnet.h
@@ -51,6 +51,21 @@ struct osc_client: public osc_socket
     bool send(const std::string &address);
 };
 
+/// Base implementation for OSC server - requires the interfacing code
+/// to poll periodically for messages. Alternatively, one can use
+/// osc_glib_server that hooks into glib main loop.
+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) {}
+    
+    void read_from_socket();
+    void parse_message(const char *buffer, int len);    
+    ~osc_server();
+};
+
 };
 
 #endif
diff --git a/src/dssigui.cpp b/src/dssigui.cpp
index 01a9f1c..8041193 100644
--- a/src/dssigui.cpp
+++ b/src/dssigui.cpp
@@ -27,7 +27,7 @@
 #include <calf/main_win.h>
 #include <calf/osctl.h>
 #include <calf/osctlnet.h>
-#include <calf/osctlserv.h>
+#include <calf/osctl_glib.h>
 
 using namespace std;
 using namespace dsp;
@@ -36,39 +36,6 @@ using namespace osctl;
 
 #define debug_printf(...)
 
-#if 0
-void osctl_test()
-{
-    string sdata = string("\000\000\000\003123\000test\000\000\000\000\000\000\000\001\000\000\000\002", 24);
-    osc_stream is(sdata);
-    vector<osc_data> data;
-    is.read("bsii", data);
-    assert(is.pos == sdata.length());
-    assert(data.size() == 4);
-    assert(data[0].type == osc_blob);
-    assert(data[1].type == osc_string);
-    assert(data[2].type == osc_i32);
-    assert(data[3].type == osc_i32);
-    assert(data[0].strval == "123");
-    assert(data[1].strval == "test");
-    assert(data[2].i32val == 1);
-    assert(data[3].i32val == 2);
-    osc_stream os("");
-    os.write(data);
-    assert(os.buffer == sdata);
-    osc_server srv;
-    srv.bind("0.0.0.0", 4541);
-    
-    osc_client cli;
-    cli.bind("0.0.0.0", 0);
-    cli.set_addr("0.0.0.0", 4541);
-    if (!cli.send("/blah", data))
-        g_error("Could not send the OSC message");
-    
-    g_main_loop_run(g_main_loop_new(NULL, FALSE));
-}
-#endif
-
 struct cairo_params
 {
     enum { HAS_COLOR = 1, HAS_WIDTH = 2 };
@@ -283,10 +250,9 @@ GMainLoop *mainloop;
 
 static bool osc_debug = false;
 
-struct dssi_osc_server: public osc_glib_server, public osc_message_sink<osc_strstream>
+struct dssi_osc_server: public osc_glib_server, public osc_message_sink<osc_strstream>, public gui_environment
 {
     plugin_proxy *plugin;
-    main_window *main_win;
     plugin_gui_window *window;
     string effect_name, title;
     osc_client cli;
@@ -300,8 +266,7 @@ struct dssi_osc_server: public osc_glib_server, public osc_message_sink<osc_strs
     
     dssi_osc_server()
     : plugin(NULL)
-    , main_win(new main_window)
-    , window(new plugin_gui_window(main_win))
+    , window(new plugin_gui_window(this, NULL))
     {
         sink = this;
         source_id = 0;
@@ -341,8 +306,8 @@ struct dssi_osc_server: public osc_glib_server, public osc_message_sink<osc_strs
     {
         plugin->client = &cli;
         plugin->send_osc = true;
-        ((main_window *)window->main)->conditions.insert("dssi");
-        ((main_window *)window->main)->conditions.insert("directlink");
+        conditions.insert("dssi");
+        conditions.insert("directlink");
         window->create(plugin, title.c_str(), effect_name.c_str());
         plugin->gui = window->gui;
         gtk_signal_connect(GTK_OBJECT(window->toplevel), "destroy", G_CALLBACK(on_destroy), this);
diff --git a/src/gui.cpp b/src/gui.cpp
index 11888ee..19270f7 100644
--- a/src/gui.cpp
+++ b/src/gui.cpp
@@ -249,7 +249,7 @@ void plugin_gui::xml_element_start(const char *element, const char *attributes[]
             state = false;
             cond.erase(0, 1);
         }
-        if (window->main->check_condition(cond.c_str()) == state)
+        if (window->environment->check_condition(cond.c_str()) == state)
             return;
         ignore_stack = 1;
         return;
@@ -550,7 +550,7 @@ static const char *command_post_xml =
 "</ui>\n"
 ;
 
-plugin_gui_window::plugin_gui_window(main_window_iface *_main)
+plugin_gui_window::plugin_gui_window(gui_environment_iface *_env, main_window_iface *_main)
 {
     toplevel = NULL;
     ui_mgr = NULL;
@@ -558,6 +558,7 @@ plugin_gui_window::plugin_gui_window(main_window_iface *_main)
     builtin_preset_actions = NULL;
     user_preset_actions = NULL;
     command_actions = NULL;
+    environment = _env;
     main = _main;
     assert(main);
 }
@@ -694,7 +695,8 @@ void plugin_gui_window::create(plugin_ctl_iface *_jh, const char *title, const c
     // printf("size set %dx%d\n", wx, wy);
     // gtk_scrolled_window_set_vadjustment(GTK_SCROLLED_WINDOW(sw), GTK_ADJUSTMENT(gtk_adjustment_new(0, 0, req.height, 20, 100, 100)));
     gtk_signal_connect (GTK_OBJECT (toplevel), "destroy", G_CALLBACK (window_destroyed), (plugin_gui_window *)this);
-    main->set_window(gui->plugin, this);
+    if (main)
+        main->set_window(gui->plugin, this);
 
     source_id = g_timeout_add_full(G_PRIORITY_LOW, 1000/30, on_idle, this, NULL); // 30 fps should be enough for everybody
     gtk_ui_manager_ensure_update(ui_mgr);
@@ -713,7 +715,8 @@ plugin_gui_window::~plugin_gui_window()
 {
     if (source_id)
         g_source_remove(source_id);
-    main->set_window(gui->plugin, NULL);
+    if (main)
+        main->set_window(gui->plugin, NULL);
     delete gui;
 }
 
diff --git a/src/host_session.cpp b/src/host_session.cpp
index 6e1cbb3..cd484cc 100644
--- a/src/host_session.cpp
+++ b/src/host_session.cpp
@@ -19,24 +19,13 @@
  * 02110-1301, USA.
  */
 
-#include <set>
-#include <getopt.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <config.h>
-#include <glade/glade.h>
-#include <jack/jack.h>
 #include <calf/giface.h>
 #include <calf/host_session.h>
-#include <calf/modules.h>
-#include <calf/modules_dev.h>
-#include <calf/organ.h>
 #include <calf/gui.h>
 #include <calf/preset.h>
 #include <calf/preset_gui.h>
 #include <calf/main_win.h>
-#include <calf/utils.h>
-#include <stdio.h>
+#include <getopt.h>
 
 using namespace std;
 using namespace calf_utils;
@@ -322,6 +311,10 @@ void host_session::close()
     client.deactivate();
     client.delete_plugins();
     client.close();
+#if USE_LASH && !USE_LASH_0_6
+    if (lash_args)
+        lash_args_destroy(lash_args);
+#endif
 }
 
 static string stripfmt(string x)
diff --git a/src/jack_client.cpp b/src/jack_client.cpp
index c8557a9..65719d3 100644
--- a/src/jack_client.cpp
+++ b/src/jack_client.cpp
@@ -19,12 +19,7 @@
  * 02110-1301, USA.
  */
 
-#include <set>
-#include <getopt.h>
 #include <stdint.h>
-#include <stdlib.h>
-#include <config.h>
-#include <glade/glade.h>
 #include <jack/jack.h>
 #include <calf/giface.h>
 #include <calf/jackhost.h>
diff --git a/src/jackhost.cpp b/src/jackhost.cpp
index 566da1a..58a4b2e 100644
--- a/src/jackhost.cpp
+++ b/src/jackhost.cpp
@@ -18,24 +18,13 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  * 02110-1301, USA.
  */
-#include <set>
-#include <getopt.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <config.h>
 #include <glade/glade.h>
-#include <jack/jack.h>
-#include <calf/giface.h>
+#include <jack/midiport.h>
 #include <calf/host_session.h>
 #include <calf/modules.h>
 #include <calf/modules_dev.h>
 #include <calf/organ.h>
-#include <calf/gui.h>
-#include <calf/preset.h>
-#include <calf/preset_gui.h>
-#include <calf/main_win.h>
-#include <calf/utils.h>
-#include <stdio.h>
+#include <getopt.h>
 
 using namespace std;
 using namespace calf_utils;
@@ -369,11 +358,6 @@ int main(int argc, char *argv[])
         sess.client.activate();
         gtk_main();
         sess.close();
-        
-#if USE_LASH && !USE_LASH_0_6
-        if (sess.lash_args)
-            lash_args_destroy(sess.lash_args);
-#endif
         // this is now done on preset add
         // save_presets(get_preset_filename().c_str());
     }
diff --git a/src/lv2gui.cpp b/src/lv2gui.cpp
index 7401c7a..1cb667e 100644
--- a/src/lv2gui.cpp
+++ b/src/lv2gui.cpp
@@ -18,23 +18,16 @@
  * Boston, MA  02110-1301  USA
  */
 #include <assert.h>
-#include <getopt.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <config.h>
 #include <sys/wait.h>
 #include <calf/giface.h>
 #include <calf/gui.h>
-#include <calf/main_win.h>
 #include <calf/lv2_data_access.h>
 #include <calf/lv2_string_port.h>
 #include <calf/lv2_ui.h>
 #include <calf/lv2_uri_map.h>
 #include <calf/lv2_external_ui.h>
 #include <calf/osctlnet.h>
-#include <calf/osctlserv.h>
 #include <calf/preset_gui.h>
-#include <calf/utils.h>
 #include <calf/lv2helpers.h>
 
 using namespace std;
@@ -234,20 +227,26 @@ void plugin_proxy_base::enable_all_sends()
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
 /// Plugin controller that uses LV2 host with help of instance/data access to remotely
 /// control a plugin from the GUI
-struct lv2_plugin_proxy: public plugin_ctl_iface, public plugin_proxy_base
+struct lv2_plugin_proxy: public plugin_ctl_iface, public plugin_proxy_base, public gui_environment
 {
     /// Plugin GTK+ GUI object pointer
     plugin_gui *gui;
     /// Glib source ID for update timer
     int source_id;
+    /// Conditional variables for XML GUI
+    std::set<std::string> conditions;
     
     lv2_plugin_proxy(const plugin_metadata_iface *md, LV2UI_Write_Function wf, LV2UI_Controller c, const LV2_Feature* const* f)
     : plugin_proxy_base(md, wf, c, f)
     {
         gui = NULL;
-        instance = NULL;
+        if (instance)
+            conditions.insert("directlink");
+        conditions.insert("lv2gui");    
     }
     
     virtual float get_param_value(int param_no) {
@@ -283,7 +282,6 @@ struct lv2_plugin_proxy: public plugin_ctl_iface, public plugin_proxy_base
     virtual const plugin_metadata_iface *get_metadata_iface() const { return plugin_metadata; }
     /// Override for a method in plugin_ctl_iface - trivial delegation to base class
     virtual const line_graph_iface *get_line_graph_iface() const { return plugin_proxy_base::get_line_graph_iface(); }
-    
 };
 
 static gboolean plugin_on_idle(void *data)
@@ -310,12 +308,7 @@ LV2UI_Handle gui_instantiate(const struct _LV2UI_Descriptor* descriptor,
     
     gtk_rc_parse(PKGLIBDIR "calf.rc");
     
-    // dummy window
-    main_window *main = new main_window;
-    if (proxy->instance)
-        main->conditions.insert("directlink");
-    main->conditions.insert("lv2gui");    
-    plugin_gui_window *window = new plugin_gui_window(main);
+    plugin_gui_window *window = new plugin_gui_window(proxy, NULL);
     plugin_gui *gui = new plugin_gui(window);
     const char *xml = proxy->plugin_metadata->get_gui_xml();
     assert(xml);
diff --git a/src/main_win.cpp b/src/main_win.cpp
index 352b53c..f085791 100644
--- a/src/main_win.cpp
+++ b/src/main_win.cpp
@@ -395,7 +395,7 @@ void main_window::update_strip(plugin_ctl_iface *plugin)
 
 void main_window::open_gui(plugin_ctl_iface *plugin)
 {
-    plugin_gui_window *gui_win = new plugin_gui_window(this);
+    plugin_gui_window *gui_win = new plugin_gui_window(this, this);
     gui_win->create(plugin, (prefix + plugin->get_metadata_iface()->get_label()).c_str(), plugin->get_metadata_iface()->get_id());
     gtk_widget_show_all(GTK_WIDGET(gui_win->toplevel));
     plugins[plugin]->gui_win = gui_win; 
diff --git a/src/osctl.cpp b/src/osctl.cpp
index 583ce2d..a89ed52 100644
--- a/src/osctl.cpp
+++ b/src/osctl.cpp
@@ -8,32 +8,6 @@
 using namespace osctl;
 using namespace std;
 
-#if 0
-std::string osc_data::to_string() const
-{
-    std::stringstream ss;
-    switch(type)
-    {
-    case osc_i32: ss << i32val; break;
-    case osc_i64: ss << (int64_t)tsval; break;
-    case osc_f32: ss << f32val; break;
-    case osc_ts: ss << tsval; break;
-    case osc_string: return strval;
-    case osc_string_alt: return strval;
-    case osc_blob: return strval;
-    case osc_true: return "TRUE";
-    case osc_false: return "FALSE";
-    case osc_nil: return "NIL";
-    case osc_inf: return "INF";
-    case osc_start_array: return "[";
-    case osc_end_array: return "]";
-    default:
-        return "?";
-    }
-    return ss.str();
-}
-#endif
-
 const char *osctl::osc_type_name(osc_type type)
 {
     switch(type)
@@ -59,122 +33,3 @@ const char *osctl::osc_type_name(osc_type type)
     }
 }
 
-#if 0
-void osc_stream::read(osc_type type, osc_data &od)
-{
-    od.type = type;
-    switch(type)
-    {
-    case osc_i32:
-    case osc_f32:
-        copy_from(&od.i32val, 4);
-        od.i32val = ntohl(od.i32val);
-        break;
-    case osc_ts:
-        copy_from(&od.tsval, 8);
-        if (ntohl(1) != 1) {
-            uint32_t a = ntohl(od.tsval), b = ntohl(od.tsval >> 32);
-            od.tsval = (((uint64_t)a) << 32) | b;
-        }
-        break;
-    case osc_string:
-    case osc_string_alt:
-    {
-        int len = 0, maxlen = 0;
-        maxlen = buffer.length() - pos;
-        while(len < maxlen && buffer[pos + len])
-            len++;
-        od.strval = buffer.substr(pos, len);
-        pos += (len + 4) &~ 3;
-        break;
-    }
-    case osc_blob: {
-        copy_from(&od.i32val, 4);
-        od.i32val = ntohl(od.i32val);
-        od.strval = buffer.substr(pos, od.i32val);
-        pos += (od.i32val + 3) &~ 3;
-        break;
-    }
-    case osc_true:
-    case osc_false:
-    case osc_nil:
-        return;
-    default:
-        assert(0);
-    }
-}
-
-void osc_stream::write(const osc_data &od)
-{
-    uint32_t val;
-    switch(od.type)
-    {
-    case osc_i32:
-    case osc_f32:
-    {
-        val = ntohl(od.i32val);
-        buffer += string((const char *)&val, 4);
-        break;
-    }
-    case osc_ts: {
-        uint64_t ts = od.tsval;
-        if (ntohl(1) != 1) {
-            uint32_t a = ntohl(od.tsval), b = ntohl(od.tsval >> 32);
-            ts = (((uint64_t)a) << 32) | b;
-        }
-        buffer += string((const char *)&ts, 8);        
-        break;
-    }
-    case osc_string:
-    case osc_string_alt:
-    {
-        buffer += od.strval;
-        val = 0;
-        buffer += string((const char *)&val, 4 - (od.strval.length() & 3));
-        break;
-    }
-    case osc_blob:
-    {
-        val = ntohl(od.strval.length());
-        buffer += string((const char *)&val, 4);
-        buffer += od.strval;
-        val = 0;
-        buffer += string((const char *)&val, 4 - (od.strval.length() & 3));
-        break;
-    }
-    case osc_true:
-    case osc_false:
-    case osc_nil:
-        return;
-    default:
-        assert(0);
-    }
-}
-    
-void osc_stream::read(const char *tags, vector<osc_data> &data)
-{
-    while(*tags)
-    {
-        data.push_back(osc_data());
-        read((osc_type)*tags++, *data.rbegin());
-    }
-}
-
-void osc_stream::write(const vector<osc_data> &data)
-{
-    unsigned int pos = 0;
-    
-    while(pos < data.size())
-        write(data[pos++]);
-}
-
-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());
-    for (unsigned int i = 0; i < args.size(); i++)
-    {
-        printf("argument %d is %s\n", i, args[i].to_string().c_str());
-    }
-}
-
-#endif
diff --git a/src/calf/osctlserv.h b/src/osctl_glib.cpp
similarity index 55%
rename from src/calf/osctlserv.h
rename to src/osctl_glib.cpp
index 84535c8..92465e0 100644
--- a/src/calf/osctlserv.h
+++ b/src/osctl_glib.cpp
@@ -19,41 +19,29 @@
  * Boston, MA  02110-1301  USA
  */
 
-#ifndef __CALF_OSCTLSERV_H
-#define __CALF_OSCTLSERV_H
+#include <calf/osctl.h>
+#include <calf/osctl_glib.h>
+#include <assert.h>
+#include <sys/socket.h>
 
-#include <glib.h>
-#include "osctlnet.h"
+using namespace osctl;
+using namespace std;
 
-namespace osctl
-{
-    
+void osc_glib_server::on_bind()
+{    
+    ioch = g_io_channel_unix_new(socket);
+    srcid = g_io_add_watch(ioch, G_IO_IN, on_data, this);
+}
 
-    
-struct osc_server: public osc_socket
+gboolean osc_glib_server::on_data(GIOChannel *channel, GIOCondition cond, void *obj)
 {
-    osc_message_dump<osc_strstream, std::ostream> dump;
-    osc_message_sink<osc_strstream> *sink;
-    
-    osc_server() : dump(std::cout), sink(&dump) {}
-    
-    void read_from_socket();
-    void parse_message(const char *buffer, int len);    
-    ~osc_server();
-};
+    osc_server *self = (osc_server *)obj;
+    self->read_from_socket();
+    return TRUE;
+}
 
-struct osc_glib_server: public osc_server
+osc_glib_server::~osc_glib_server()
 {
-    GIOChannel *ioch;
-    
-    osc_glib_server() : ioch(NULL) {}
-    
-    virtual void on_bind();
-    
-    static gboolean on_data(GIOChannel *channel, GIOCondition cond, void *obj);
-    ~osc_glib_server();
-};
-
-};
-
-#endif
+    if (ioch)
+        g_source_remove(srcid);
+}
diff --git a/src/osctlnet.cpp b/src/osctlnet.cpp
index e108468..85c65b6 100644
--- a/src/osctlnet.cpp
+++ b/src/osctlnet.cpp
@@ -124,3 +124,42 @@ bool osc_client::send(const std::string &address)
     return ::sendto(socket, hdr.data.data(), hdr.data.length(), 0, (sockaddr *)&addr, sizeof(addr)) == (int)hdr.data.length();
 }
 
+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_server::read_from_socket()
+{
+    do {
+        char buf[16384];
+        int len = recv(socket, buf, 16384, MSG_DONTWAIT);
+        if (len > 0)
+        {
+            if (buf[0] == '/')
+            {
+                parse_message(buf, len);
+            }
+            if (buf[0] == '#')
+            {
+                // XXXKF bundles are not supported yet
+            }
+        }
+        else
+            break;
+    } while(1);
+}
+
+osc_server::~osc_server()
+{
+}
diff --git a/src/osctlserv.cpp b/src/osctlserv.cpp
deleted file mode 100644
index 2c9e4b2..0000000
--- a/src/osctlserv.cpp
+++ /dev/null
@@ -1,90 +0,0 @@
-/* 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., 51 Franklin Street, Fifth Floor, 
- * Boston, MA  02110-1301  USA
- */
-
-#include <calf/osctl.h>
-#include <calf/osctlserv.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)
-{
-    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_server::read_from_socket()
-{
-    do {
-        char buf[16384];
-        int len = recv(socket, buf, 16384, MSG_DONTWAIT);
-        if (len > 0)
-        {
-            if (buf[0] == '/')
-            {
-                parse_message(buf, len);
-            }
-            if (buf[0] == '#')
-            {
-                // XXXKF bundles are not supported yet
-            }
-        }
-        else
-            break;
-    } while(1);
-}
-
-osc_server::~osc_server()
-{
-}
-
-void osc_glib_server::on_bind()
-{    
-    ioch = g_io_channel_unix_new(socket);
-    srcid = g_io_add_watch(ioch, G_IO_IN, on_data, this);
-}
-
-gboolean osc_glib_server::on_data(GIOChannel *channel, GIOCondition cond, void *obj)
-{
-    osc_server *self = (osc_server *)obj;
-    self->read_from_socket();
-    return TRUE;
-}
-
-osc_glib_server::~osc_glib_server()
-{
-    if (ioch)
-        g_source_remove(srcid);
-}
diff --git a/src/preset_gui.cpp b/src/preset_gui.cpp
index 8240480..86adf92 100644
--- a/src/preset_gui.cpp
+++ b/src/preset_gui.cpp
@@ -101,7 +101,8 @@ void calf_plugins::store_preset(GtkWindow *toplevel, plugin_gui *gui)
         tmp.add(sp);
         get_user_presets() = tmp;
         get_user_presets().save(tmp.get_preset_filename(false).c_str());
-        gui->window->main->refresh_all_presets(false);
+        if (gui->window->main)
+            gui->window->main->refresh_all_presets(false);
     }
     //gtk_window_set_transient_for(GTK_WINDOW(store_preset_dlg), toplevel);
 }

-- 
calf audio plugins packaging



More information about the pkg-multimedia-commits mailing list