[SCM] calf/master: More separation of GUI and core in calfjackhost.

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


The following commit has been merged in the master branch:
commit 4f1f6cf243c85c34e98c4556dcde94f99bdde013
Author: Krzysztof Foltman <wdev at foltman.com>
Date:   Sat Jan 1 16:33:08 2011 +0000

    More separation of GUI and core in calfjackhost.

diff --git a/src/Makefile.am b/src/Makefile.am
index d6eabd7..8cae7f3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -29,7 +29,7 @@ if USE_JACK
 AM_CXXFLAGS += $(JACK_DEPS_CFLAGS)
 noinst_LTLIBRARIES += libcalfgui.la
 bin_PROGRAMS += calfjackhost 
-calfjackhost_SOURCES = host_session.cpp jack_client.cpp jackhost.cpp main_win.cpp session_mgr.cpp
+calfjackhost_SOURCES = gtk_session_env.cpp host_session.cpp jack_client.cpp jackhost.cpp gtk_main_win.cpp session_mgr.cpp
 calfjackhost_LDADD = libcalfgui.la calf.la $(JACK_DEPS_LIBS) $(GUI_DEPS_LIBS) $(FLUIDSYNTH_DEPS_LIBS)
 if USE_LASH
 AM_CXXFLAGS += $(LASH_DEPS_CFLAGS)
diff --git a/src/calf/Makefile.am b/src/calf/Makefile.am
index 3a735d5..9f3c6bf 100644
--- a/src/calf/Makefile.am
+++ b/src/calf/Makefile.am
@@ -1,10 +1,11 @@
 noinst_HEADERS = audio_fx.h benchmark.h biquad.h buffer.h custom_ctl.h \
     ctl_curve.h ctl_keyboard.h ctl_led.h ctl_vumeter.h \
-    delay.h envelope.h fft.h fixed_point.h giface.h gui.h gui_config.h gui_controls.h inertia.h jackhost.h \
+    delay.h envelope.h fft.h fixed_point.h giface.h gtk_session_env.h gtk_main_win.h \
+    gui.h gui_config.h gui_controls.h inertia.h jackhost.h \
     host_session.h ladspa_wrap.h loudness.h \
     lv2_data_access.h lv2_event.h lv2_external_ui.h \
     lv2_persist.h lv2_persist2.h lv2_progress.h lv2_ui.h lv2_uri_map.h lv2helpers.h lv2wrap.h \
-    main_win.h metadata.h modmatrix.h \
+    metadata.h modmatrix.h \
     modules.h modules_comp.h modules_dev.h modules_dist.h modules_eq.h modules_mod.h modules_synths.h \
     modulelist.h \
     multichorus.h onepole.h organ.h osc.h osctl.h osctlnet.h osctl_glib.h plugin_tools.h preset.h \
diff --git a/src/calf/main_win.h b/src/calf/gtk_main_win.h
similarity index 79%
rename from src/calf/main_win.h
rename to src/calf/gtk_main_win.h
index 3a61b2d..24f5355 100644
--- a/src/calf/main_win.h
+++ b/src/calf/gtk_main_win.h
@@ -1,7 +1,7 @@
 /* Calf DSP Library Utility Application - calfjackhost
  * GUI - main window
  *
- * Copyright (C) 2007 Krzysztof Foltman
+ * Copyright (C) 2007-2011 Krzysztof Foltman
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -26,12 +26,12 @@
 
 namespace calf_plugins {
 
-    class main_window: public main_window_iface, public gui_environment, public calf_utils::config_listener_iface
+    class gtk_main_window: public main_window_iface, public gui_environment, public calf_utils::config_listener_iface
     {
     public:
         struct plugin_strip
         {
-            main_window *main_win;
+            gtk_main_window *main_win;
             plugin_ctl_iface *plugin;
             plugin_gui_window *gui_win;
             GtkWidget *name, *button, *midi_in, *audio_in[2], *audio_out[2], *extra, *leftBox, *rightBox;
@@ -39,9 +39,9 @@ namespace calf_plugins {
         
         struct add_plugin_params
         {
-            main_window *main_win;
+            gtk_main_window *main_win;
             std::string name;
-            add_plugin_params(main_window *_main_win, const std::string &_name)
+            add_plugin_params(gtk_main_window *_main_win, const std::string &_name)
             : main_win(_main_win), name(_name) {}
         };
         
@@ -74,7 +74,7 @@ namespace calf_plugins {
         GtkWidget *create_progress_window();        
 
     public:
-        main_window();
+        gtk_main_window();
         void set_owner(main_window_owner_iface *_owner) { owner = _owner; }
         void new_plugin(const char *name) { owner->new_plugin(name); }
         void add_plugin(plugin_ctl_iface *plugin);
@@ -94,14 +94,16 @@ namespace calf_plugins {
         virtual void report_progress(float percentage, const std::string &message);
         /// Mark condition as true
         virtual void add_condition(const std::string &name);
+        /// Display an error dialog
+        virtual void show_error(const std::string &text);
     private:
         static const GtkActionEntry actions[];
-        static void on_open_action(GtkWidget *widget, main_window *main);
-        static void on_save_action(GtkWidget *widget, main_window *main);
-        static void on_save_as_action(GtkWidget *widget, main_window *main);
-        static void on_preferences_action(GtkWidget *widget, main_window *main);
-        static void on_reorder_action(GtkWidget *widget, main_window *main);
-        static void on_exit_action(GtkWidget *widget, main_window *main);
+        static void on_open_action(GtkWidget *widget, gtk_main_window *main);
+        static void on_save_action(GtkWidget *widget, gtk_main_window *main);
+        static void on_save_as_action(GtkWidget *widget, gtk_main_window *main);
+        static void on_preferences_action(GtkWidget *widget, gtk_main_window *main);
+        static void on_reorder_action(GtkWidget *widget, gtk_main_window *main);
+        static void on_exit_action(GtkWidget *widget, gtk_main_window *main);
     };
 };
 
diff --git a/src/calf/gtk_session_env.h b/src/calf/gtk_session_env.h
new file mode 100644
index 0000000..bb2285e
--- /dev/null
+++ b/src/calf/gtk_session_env.h
@@ -0,0 +1,37 @@
+/* Calf DSP Library Utility Application - calfjackhost
+ * GTK+ implementation of session_environment_iface.
+ *
+ * Copyright (C) 2007-2011 Krzysztof Foltman
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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/gui.h>
+
+namespace calf_plugins
+{
+
+class gtk_session_environment: public session_environment_iface
+{
+public:
+    virtual void init_gui(int &argc, char **&argv);
+    virtual void start_gui_loop();
+    virtual void quit_gui_loop();
+    virtual main_window_iface *create_main_window();
+    ~gtk_session_environment();
+};
+    
+};
diff --git a/src/calf/gui.h b/src/calf/gui.h
index 2da572c..a01f039 100644
--- a/src/calf/gui.h
+++ b/src/calf/gui.h
@@ -1,6 +1,6 @@
 /* Calf DSP Library
  * Universal GUI module
- * Copyright (C) 2007 Krzysztof Foltman
+ * Copyright (C) 2007-2011 Krzysztof Foltman
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -142,18 +142,33 @@ public:
     static void xml_element_end(void *data, const char *element);
 };
 
+class main_window_iface;
 class main_window_owner_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 bool check_condition(const char *name) = 0;
     virtual calf_utils::config_db_iface *get_config_db() = 0;
     virtual calf_utils::gui_config *get_config() = 0;
     virtual ~gui_environment_iface() {}
 };
 
+/// An interface that wraps UI-dependent elements of the session
+struct session_environment_iface
+{
+    /// Called to initialise the UI libraries
+    virtual void init_gui(int &argc, char **&argv) = 0;
+    /// Create an appropriate version of the main window
+    virtual main_window_iface *create_main_window() = 0;
+    /// Called to start the UI loop
+    virtual void start_gui_loop() = 0;
+    /// Called from within event handlers to finish the UI loop
+    virtual void quit_gui_loop() = 0;
+    virtual ~session_environment_iface() {}
+};
+
 /// Trivial implementation of gui_environment_iface
 class gui_environment: public gui_environment_iface
 {
@@ -197,6 +212,8 @@ struct main_window_iface: public progress_report_iface
     virtual bool save_file() = 0;
     /// Called to clean up when host quits
     virtual void on_closed() = 0;
+    /// Show an error message
+    virtual void show_error(const std::string &text) = 0;
     
     
     virtual ~main_window_iface() {}
diff --git a/src/calf/host_session.h b/src/calf/host_session.h
index b55bd6b..a92a166 100644
--- a/src/calf/host_session.h
+++ b/src/calf/host_session.h
@@ -1,7 +1,7 @@
 /* Calf DSP Library Utility Application - calfjackhost
  * Class for managing calfjackhost's session.
  *
- * Copyright (C) 2007-2010 Krzysztof Foltman
+ * Copyright (C) 2007-2011 Krzysztof Foltman
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -68,8 +68,9 @@ public:
     main_window_iface *main_win;
     std::set<std::string> instances;
     plugin_gui_window *gui_win;
+    session_environment_iface *session_env;
     
-    host_session();
+    host_session(session_environment_iface *);
     void open();
     void add_plugin(std::string name, std::string preset, std::string instance_name = std::string());
     void create_plugins_from_list();
diff --git a/src/main_win.cpp b/src/gtk_main_win.cpp
similarity index 90%
rename from src/main_win.cpp
rename to src/gtk_main_win.cpp
index 1d18210..a6e6d77 100644
--- a/src/main_win.cpp
+++ b/src/gtk_main_win.cpp
@@ -1,6 +1,6 @@
 /* Calf DSP Library
  * GUI main window.
- * Copyright (C) 2007 Krzysztof Foltman
+ * Copyright (C) 2007-2011 Krzysztof Foltman
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -23,12 +23,12 @@
 #include <calf/giface.h>
 #include <calf/gui.h>
 #include <calf/preset.h>
-#include <calf/main_win.h>
+#include <calf/gtk_main_win.h>
 
 using namespace calf_plugins;
 using namespace std;
 
-main_window::main_window()
+gtk_main_window::gtk_main_window()
 {
     toplevel = NULL;
     owner = NULL;
@@ -56,7 +56,7 @@ static const char *ui_xml =
 "</ui>\n"
 ;
 
-const GtkActionEntry main_window::actions[] = {
+const GtkActionEntry gtk_main_window::actions[] = {
     { "FileMenuAction", NULL, "_File", NULL, "File-related operations", NULL },
     { "FileOpen", GTK_STOCK_OPEN, "_Open", "<Ctrl>O", "Open a rack file", (GCallback)on_open_action },
     { "FileSave", GTK_STOCK_SAVE, "_Save", "<Ctrl>S", "Save a rack file", (GCallback)on_save_action },
@@ -68,27 +68,27 @@ const GtkActionEntry main_window::actions[] = {
     { "FileQuit", GTK_STOCK_QUIT, "_Quit", "<Ctrl>Q", "Exit application", (GCallback)on_exit_action },
 };
 
-void main_window::on_open_action(GtkWidget *widget, main_window *main)
+void gtk_main_window::on_open_action(GtkWidget *widget, gtk_main_window *main)
 {
     main->open_file();
 }
 
-void main_window::on_save_action(GtkWidget *widget, main_window *main)
+void gtk_main_window::on_save_action(GtkWidget *widget, gtk_main_window *main)
 {
     main->save_file();
 }
 
-void main_window::on_save_as_action(GtkWidget *widget, main_window *main)
+void gtk_main_window::on_save_as_action(GtkWidget *widget, gtk_main_window *main)
 {
     main->save_file_as();
 }
 
-void main_window::on_reorder_action(GtkWidget *widget, main_window *main)
+void gtk_main_window::on_reorder_action(GtkWidget *widget, gtk_main_window *main)
 {
     main->owner->reorder_plugins();
 }
 
-void main_window::on_preferences_action(GtkWidget *widget, main_window *main)
+void gtk_main_window::on_preferences_action(GtkWidget *widget, gtk_main_window *main)
 {
     GtkBuilder *prefs_builder = gtk_builder_new();
     GError *error = NULL;
@@ -118,12 +118,12 @@ void main_window::on_preferences_action(GtkWidget *widget, main_window *main)
     g_object_unref(G_OBJECT(prefs_builder));
 }
 
-void main_window::on_exit_action(GtkWidget *widget, main_window *main)
+void gtk_main_window::on_exit_action(GtkWidget *widget, gtk_main_window *main)
 {
     gtk_widget_destroy(GTK_WIDGET(main->toplevel));
 }
 
-void main_window::add_plugin(plugin_ctl_iface *plugin)
+void gtk_main_window::add_plugin(plugin_ctl_iface *plugin)
 {
     if (toplevel)
     {
@@ -137,7 +137,7 @@ void main_window::add_plugin(plugin_ctl_iface *plugin)
     }
 }
 
-void main_window::del_plugin(plugin_ctl_iface *plugin)
+void gtk_main_window::del_plugin(plugin_ctl_iface *plugin)
 {
     if (!plugins.count(plugin))
         return;
@@ -181,7 +181,7 @@ void main_window::del_plugin(plugin_ctl_iface *plugin)
     gtk_table_resize(GTK_TABLE(strips_table), rows - 4, cols);
 }
 
-void main_window::set_window(plugin_ctl_iface *plugin, plugin_gui_window *gui_win)
+void gtk_main_window::set_window(plugin_ctl_iface *plugin, plugin_gui_window *gui_win)
 {
     if (!plugins.count(plugin))
         return;
@@ -193,7 +193,7 @@ void main_window::set_window(plugin_ctl_iface *plugin, plugin_gui_window *gui_wi
         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(strip->button), gui_win != NULL);    
 }
 
-void main_window::refresh_all_presets(bool builtin_too)
+void gtk_main_window::refresh_all_presets(bool builtin_too)
 {
     for (std::map<plugin_ctl_iface *, plugin_strip *>::iterator i = plugins.begin(); i != plugins.end(); i++)
     {
@@ -206,7 +206,7 @@ void main_window::refresh_all_presets(bool builtin_too)
 }
 
 static gboolean
-gui_button_pressed(GtkWidget *button, main_window::plugin_strip *strip)
+gui_button_pressed(GtkWidget *button, gtk_main_window::plugin_strip *strip)
 {
     GtkToggleButton *tb = GTK_TOGGLE_BUTTON(button);
     if ((gtk_toggle_button_get_active(tb) != 0) == (strip->gui_win != NULL))
@@ -221,13 +221,13 @@ gui_button_pressed(GtkWidget *button, main_window::plugin_strip *strip)
 }
 
 static gboolean
-extra_button_pressed(GtkWidget *button, main_window::plugin_strip *strip)
+extra_button_pressed(GtkWidget *button, gtk_main_window::plugin_strip *strip)
 {
     strip->main_win->owner->remove_plugin(strip->plugin);
     return TRUE;
 }
 
-void main_window::show_rack_ears(bool show)
+void gtk_main_window::show_rack_ears(bool show)
 {
     for (std::map<plugin_ctl_iface *, plugin_strip *>::iterator i = plugins.begin(); i != plugins.end(); i++)
     {
@@ -244,7 +244,7 @@ void main_window::show_rack_ears(bool show)
     }
 }
 
-main_window::plugin_strip *main_window::create_strip(plugin_ctl_iface *plugin)
+gtk_main_window::plugin_strip *gtk_main_window::create_strip(plugin_ctl_iface *plugin)
 {
     plugin_strip *strip = new plugin_strip;
     strip->main_win = this;
@@ -428,14 +428,14 @@ main_window::plugin_strip *main_window::create_strip(plugin_ctl_iface *plugin)
     return strip;
 }
 
-void main_window::update_strip(plugin_ctl_iface *plugin)
+void gtk_main_window::update_strip(plugin_ctl_iface *plugin)
 {
     // plugin_strip *strip = plugins[plugin];
     // assert(strip);
     
 }
 
-void main_window::open_gui(plugin_ctl_iface *plugin)
+void gtk_main_window::open_gui(plugin_ctl_iface *plugin)
 {
     plugin_gui_window *gui_win = new plugin_gui_window(this, this);
     gui_win->create(plugin, (owner->get_client_name() + " - " + plugin->get_metadata_iface()->get_label()).c_str(), plugin->get_metadata_iface()->get_id());
@@ -456,7 +456,7 @@ static const char *plugin_post_xml =
 "</ui>\n"
 ;
 
-void main_window::add_plugin_action(GtkWidget *src, gpointer data)
+void gtk_main_window::add_plugin_action(GtkWidget *src, gpointer data)
 {
     add_plugin_params *app = (add_plugin_params *)data;
     app->main_win->new_plugin(app->name.c_str());
@@ -464,10 +464,10 @@ void main_window::add_plugin_action(GtkWidget *src, gpointer data)
 
 static void action_destroy_notify(gpointer data)
 {
-    delete (main_window::add_plugin_params *)data;
+    delete (gtk_main_window::add_plugin_params *)data;
 }
 
-std::string main_window::make_plugin_list(GtkActionGroup *actions)
+std::string gtk_main_window::make_plugin_list(GtkActionGroup *actions)
 {
     string s = plugin_pre_xml;
     const plugin_registry::plugin_vector &plugins = plugin_registry::instance().get_all();
@@ -484,10 +484,10 @@ std::string main_window::make_plugin_list(GtkActionGroup *actions)
 
 static void window_destroy_cb(GtkWindow *window, gpointer data)
 {
-    ((main_window *)data)->owner->on_main_window_destroy();
+    ((gtk_main_window *)data)->owner->on_main_window_destroy();
 }
 
-void main_window::create()
+void gtk_main_window::create()
 {
     toplevel = GTK_WINDOW(gtk_window_new (GTK_WINDOW_TOPLEVEL));
     gtk_window_set_title(toplevel, (owner->get_client_name() + " - Calf JACK Host").c_str());
@@ -546,19 +546,19 @@ void main_window::create()
     gtk_signal_connect(GTK_OBJECT(toplevel), "destroy", G_CALLBACK(window_destroy_cb), this);
 }
 
-void main_window::on_config_change()
+void gtk_main_window::on_config_change()
 {
     get_config()->load(get_config_db());
     show_rack_ears(get_config()->rack_ears);    
 }
 
-void main_window::refresh_plugin(plugin_ctl_iface *plugin)
+void gtk_main_window::refresh_plugin(plugin_ctl_iface *plugin)
 {
     if (plugins[plugin]->gui_win)
         plugins[plugin]->gui_win->gui->refresh();
 }
 
-void main_window::on_closed()
+void gtk_main_window::on_closed()
 {
     if (notifier)
     {
@@ -584,9 +584,9 @@ static inline float LVL(float value)
     return sqrt(value) * 0.75;
 }
 
-gboolean main_window::on_idle(void *data)
+gboolean gtk_main_window::on_idle(void *data)
 {
-    main_window *self = (main_window *)data;
+    gtk_main_window *self = (gtk_main_window *)data;
     self->owner->on_idle();
     for (std::map<plugin_ctl_iface *, plugin_strip *>::iterator i = self->plugins.begin(); i != self->plugins.end(); i++)
     {
@@ -611,7 +611,7 @@ gboolean main_window::on_idle(void *data)
     return TRUE;
 }
 
-void main_window::open_file()
+void gtk_main_window::open_file()
 {
     GtkWidget *dialog;
     dialog = gtk_file_chooser_dialog_new ("Open File",
@@ -634,7 +634,7 @@ void main_window::open_file()
     gtk_widget_destroy (dialog);
 }
 
-bool main_window::save_file()
+bool gtk_main_window::save_file()
 {
     if (owner->get_current_filename().empty())
         return save_file_as();
@@ -648,7 +648,7 @@ bool main_window::save_file()
     return true;
 }
 
-bool main_window::save_file_as()
+bool gtk_main_window::save_file_as()
 {
     GtkWidget *dialog;
     bool success = false;
@@ -676,7 +676,7 @@ bool main_window::save_file_as()
     return success;
 }
 
-void main_window::display_error(const char *error, const char *filename)
+void gtk_main_window::display_error(const char *error, const char *filename)
 {
     GtkWidget *dialog;
     dialog = gtk_message_dialog_new_with_markup (toplevel, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, error, filename, NULL);
@@ -684,7 +684,7 @@ void main_window::display_error(const char *error, const char *filename)
     gtk_widget_destroy (dialog);
 }
 
-GtkWidget *main_window::create_progress_window()
+GtkWidget *gtk_main_window::create_progress_window()
 {
     GtkWidget *tlw = gtk_window_new ( GTK_WINDOW_TOPLEVEL );
     gtk_window_set_type_hint (GTK_WINDOW (tlw), GDK_WINDOW_TYPE_HINT_DIALOG);
@@ -694,7 +694,7 @@ GtkWidget *main_window::create_progress_window()
     return tlw;
 }
 
-void main_window::report_progress(float percentage, const std::string &message)
+void gtk_main_window::report_progress(float percentage, const std::string &message)
 {
     if (percentage < 100)
     {
@@ -723,8 +723,14 @@ void main_window::report_progress(float percentage, const std::string &message)
         gtk_main_iteration ();
 }
 
-void main_window::add_condition(const std::string &name)
+void gtk_main_window::add_condition(const std::string &name)
 {
     conditions.insert(name);
 }
 
+void gtk_main_window::show_error(const std::string &text)
+{
+    GtkWidget *widget = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", text.c_str());
+    gtk_dialog_run (GTK_DIALOG (widget));
+    gtk_widget_destroy (widget);
+}
diff --git a/src/gtk_session_env.cpp b/src/gtk_session_env.cpp
new file mode 100644
index 0000000..3abae46
--- /dev/null
+++ b/src/gtk_session_env.cpp
@@ -0,0 +1,50 @@
+/* Calf DSP Library Utility Application - calfjackhost
+ * GTK+ implementation of session_environment_iface.
+ *
+ * Copyright (C) 2007-2011 Krzysztof Foltman
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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/gtk_session_env.h>
+#include <calf/gtk_main_win.h>
+
+using namespace calf_plugins;
+
+void gtk_session_environment::init_gui(int &argc, char **&argv)
+{
+    gtk_rc_add_default_file(PKGLIBDIR "calf.rc");
+    gtk_init(&argc, &argv);
+}
+
+main_window_iface *gtk_session_environment::create_main_window()
+{
+    return new gtk_main_window;
+}
+
+void gtk_session_environment::start_gui_loop()
+{
+    gtk_main();
+}
+
+void gtk_session_environment::quit_gui_loop()
+{
+    gtk_main_quit();
+}
+
+gtk_session_environment::~gtk_session_environment()
+{
+}
diff --git a/src/host_session.cpp b/src/host_session.cpp
index de8d621..ab5742c 100644
--- a/src/host_session.cpp
+++ b/src/host_session.cpp
@@ -1,7 +1,7 @@
 /* Calf DSP Library Utility Application - calfjackhost
  * A class that contains a JACK host session
  *
- * Copyright (C) 2007-2010 Krzysztof Foltman
+ * Copyright (C) 2007-2011 Krzysztof Foltman
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -23,7 +23,6 @@
 #include <calf/host_session.h>
 #include <calf/gui.h>
 #include <calf/preset.h>
-#include <calf/main_win.h>
 #include <getopt.h>
 #include <sys/stat.h>
 
@@ -35,15 +34,17 @@ using namespace calf_plugins;
 
 host_session *host_session::instance = NULL;
 
-host_session::host_session()
+host_session::host_session(session_environment_iface *se)
 {
     client_name = "calf";
-    main_win = new main_window;
-    main_win->set_owner(this);
+    session_env = se;
     autoconnect_midi_index = -1;
     gui_win = NULL;
     session_manager = NULL;
     only_load_if_exists = false;
+
+    main_win = session_env->create_main_window();
+    main_win->set_owner(this);
 }
 
 std::string host_session::get_next_instance_name(const std::string &effect_name)
@@ -100,7 +101,7 @@ void host_session::create_plugins_from_list()
 
 void host_session::on_main_window_destroy()
 {
-    gtk_main_quit();
+    session_env->quit_gui_loop();
 }
 
 void host_session::open()
@@ -257,20 +258,13 @@ void host_session::connect()
                     suppress_error = true;
             }
             // If the file is optional and it didn't exist, suppress the error
-            if (suppress_error)
-            {
-                g_free(error);
-                // keep the load_name for any later save
-            }
-            else
+            if (!suppress_error)
             {
-                GtkWidget *widget = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Cannot load '%s': %s", load_name.c_str(), error);
-                gtk_dialog_run (GTK_DIALOG (widget));
-                gtk_widget_destroy (widget);
+                main_win->show_error("Cannot load '" + load_name + "': " + error);
                 
-                g_free(error);
                 load_name = "";
             }
+            g_free(error);
         }
         set_current_filename(load_name);
     }
diff --git a/src/jackhost.cpp b/src/jackhost.cpp
index c20431a..31f2567 100644
--- a/src/jackhost.cpp
+++ b/src/jackhost.cpp
@@ -1,7 +1,7 @@
 /* Calf DSP Library Utility Application - calfjackhost
  * Standalone application module wrapper example.
  *
- * Copyright (C) 2007 Krzysztof Foltman
+ * Copyright (C) 2007-2011 Krzysztof Foltman
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -21,6 +21,7 @@
 #include <jack/midiport.h>
 #include <calf/host_session.h>
 #include <calf/preset.h>
+#include <calf/gtk_session_env.h>
 #include <getopt.h>
 
 using namespace std;
@@ -309,10 +310,9 @@ void print_help(char *argv[])
 int main(int argc, char *argv[])
 {
     g_type_init();
-    host_session sess;
-
-    gtk_rc_add_default_file(PKGLIBDIR "calf.rc");
-    gtk_init(&argc, &argv);
+    
+    host_session sess(new gtk_session_environment());
+    sess.session_env->init_gui(argc, argv);
     
     // Scan the options for the first time to find switches like --help, -h or -?
     // This avoids starting communication with LASH when displaying help text.
@@ -413,11 +413,8 @@ int main(int argc, char *argv[])
         sess.connect();
         sess.client.activate();
         sess.set_ladish_handler();
-        gtk_main();
-        
+        sess.session_env->start_gui_loop();
         sess.close();
-        // this is now done on preset add
-        // save_presets(get_preset_filename().c_str());
     }
     catch(std::exception &e)
     {

-- 
calf audio plugins packaging



More information about the pkg-multimedia-commits mailing list