[SCM] calf/master: Start sorting out dependencies between session code and GUI code.
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 9493be2b0d99f3da9b08b561de3e7f84ad81d070
Author: Krzysztof Foltman <wdev at foltman.com>
Date: Sat Jan 1 15:40:52 2011 +0000
Start sorting out dependencies between session code and GUI code.
diff --git a/src/calf/gui.h b/src/calf/gui.h
index ea9355c..2da572c 100644
--- a/src/calf/gui.h
+++ b/src/calf/gui.h
@@ -173,15 +173,32 @@ public:
};
/// Interface used by the plugin to communicate with the main hosting window
-struct main_window_iface
+struct main_window_iface: public progress_report_iface
{
- virtual void set_owner(main_window_owner_iface *owner)=0;
-
- virtual void add_plugin(plugin_ctl_iface *plugin)=0;
- virtual void del_plugin(plugin_ctl_iface *plugin)=0;
+ /// Set owner pointer
+ virtual void set_owner(main_window_owner_iface *owner) = 0;
+ /// Add a condition to the list of conditions supported by the host
+ virtual void add_condition(const std::string &name) = 0;
+ /// Create the actual window associated with this interface
+ virtual void create() = 0;
+ /// Add the plugin to the window
+ virtual void add_plugin(plugin_ctl_iface *plugin) = 0;
+ /// Remove the plugin from the window
+ virtual void del_plugin(plugin_ctl_iface *plugin) = 0;
+ /// Refresh the plugin UI
+ virtual void refresh_plugin(plugin_ctl_iface *plugin) = 0;
+ /// Bind the plugin window to the plugin
+ virtual void set_window(plugin_ctl_iface *plugin, plugin_gui_window *window) = 0;
+ /// Refresh preset lists on all windows (if, for example, a new preset has been created)
+ virtual void refresh_all_presets(bool builtin_too) = 0;
+ /// Default open file operation
+ virtual void open_file() = 0;
+ /// Default save file operation
+ virtual bool save_file() = 0;
+ /// Called to clean up when host quits
+ virtual void on_closed() = 0;
+
- virtual void set_window(plugin_ctl_iface *plugin, plugin_gui_window *window)=0;
- virtual void refresh_all_presets(bool builtin_too)=0;
virtual ~main_window_iface() {}
};
@@ -192,7 +209,16 @@ struct main_window_owner_iface
virtual char *open_file(const char *name) = 0;
virtual char *save_file(const char *name) = 0;
virtual void reorder_plugins() = 0;
+ /// Return JACK client name (or its counterpart) to put in window title bars
virtual std::string get_client_name() const = 0;
+ /// Called on 'destroy' event of the main window
+ virtual void on_main_window_destroy() = 0;
+ /// Called from idle handler
+ virtual void on_idle() = 0;
+ /// Get the file name of the current rack
+ virtual std::string get_current_filename() const = 0;
+ /// Set the file name of the current rack
+ virtual void set_current_filename(const std::string &name) = 0;
virtual ~main_window_owner_iface() {}
};
diff --git a/src/calf/host_session.h b/src/calf/host_session.h
index 5b832c6..b55bd6b 100644
--- a/src/calf/host_session.h
+++ b/src/calf/host_session.h
@@ -31,7 +31,7 @@ namespace calf_plugins {
class main_window;
-class host_session: public main_window_owner_iface, public calf_plugins::progress_report_iface, public session_client_iface
+class host_session: public main_window_owner_iface, public session_client_iface
{
private:
static host_session *instance;
@@ -54,6 +54,10 @@ public:
std::map<int, std::string> presets;
/// Selected session manager (if any).
session_manager_iface *session_manager;
+ /// Save has been requested from SIGUSR1 handler
+ volatile bool save_file_on_next_idle_call;
+ /// File name of the current rack
+ std::string current_filename;
// these are not saved
jack_client client;
@@ -61,9 +65,8 @@ public:
int autoconnect_midi_index;
std::set<int> chains;
std::vector<jack_host *> plugins;
- main_window *main_win;
+ main_window_iface *main_win;
std::set<std::string> instances;
- GtkWidget *progress_window;
plugin_gui_window *gui_win;
host_session();
@@ -73,20 +76,19 @@ public:
void connect();
void close();
bool activate_preset(int plugin, const std::string &preset, bool builtin);
- virtual void new_plugin(const char *name);
- virtual void remove_plugin(plugin_ctl_iface *plugin);
void remove_all_plugins();
- void reorder_plugins();
std::string get_next_instance_name(const std::string &effect_name);
- /// Create a toplevel window with progress bar
- GtkWidget *create_progress_window();
- /// Implementation of progress_report_iface function
- void report_progress(float percentage, const std::string &message);
-
/// Set handler for SIGUSR1 that LADISH uses to invoke Save function
void set_ladish_handler();
+ /// SIGUSR1 handler
+ static void sigusr1handler(int signum);
+
+ /// Client name for window title bar
+ std::string get_client_name() const;
+
+public:
/// Implementation of open file functionality (TODO)
virtual char *open_file(const char *name);
/// Implementation of save file functionality
@@ -97,11 +99,13 @@ public:
/// Save to session manager
virtual void save(session_save_iface *);
- /// SIGUSR1 handler
- static void sigusr1handler(int signum);
-
- /// Client name for window title bar
- std::string get_client_name() const;
+ virtual void new_plugin(const char *name);
+ virtual void remove_plugin(plugin_ctl_iface *plugin);
+ virtual void on_main_window_destroy();
+ virtual void on_idle();
+ virtual void reorder_plugins();
+ virtual std::string get_current_filename() const;
+ virtual void set_current_filename(const std::string &name);
};
};
diff --git a/src/calf/main_win.h b/src/calf/main_win.h
index 8e03358..3a61b2d 100644
--- a/src/calf/main_win.h
+++ b/src/calf/main_win.h
@@ -53,16 +53,16 @@ namespace calf_plugins {
GtkActionGroup *std_actions, *plugin_actions;
std::map<plugin_ctl_iface *, plugin_strip *> plugins;
std::vector<plugin_ctl_iface *> plugin_queue;
- std::string prefix;
bool is_closed;
bool draw_rackmounts;
int source_id;
main_window_owner_iface *owner;
- std::string current_filename;
calf_utils::config_notifier_iface *notifier;
protected:
- volatile bool save_file_on_next_idle_call;
+ GtkWidget *progress_window;
+
+ protected:
plugin_strip *create_strip(plugin_ctl_iface *plugin);
void update_strip(plugin_ctl_iface *plugin);
static gboolean on_idle(void *data);
@@ -70,6 +70,8 @@ namespace calf_plugins {
static void add_plugin_action(GtkWidget *src, gpointer data);
void display_error(const char *error, const char *filename);
void on_config_change();
+ /// Create a toplevel window with progress bar
+ GtkWidget *create_progress_window();
public:
main_window();
@@ -81,7 +83,6 @@ namespace calf_plugins {
void refresh_all_presets(bool builtin_too);
void refresh_plugin(plugin_ctl_iface *plugin);
void on_closed();
- void close_guis();
void open_gui(plugin_ctl_iface *plugin);
void create();
void open_file();
@@ -89,6 +90,10 @@ namespace calf_plugins {
bool save_file_as();
void save_file_from_sighandler();
void show_rack_ears(bool show);
+ /// Implementation of progress_report_iface function
+ virtual void report_progress(float percentage, const std::string &message);
+ /// Mark condition as true
+ virtual void add_condition(const std::string &name);
private:
static const GtkActionEntry actions[];
static void on_open_action(GtkWidget *widget, main_window *main);
diff --git a/src/host_session.cpp b/src/host_session.cpp
index 337023e..de8d621 100644
--- a/src/host_session.cpp
+++ b/src/host_session.cpp
@@ -40,7 +40,6 @@ host_session::host_session()
client_name = "calf";
main_win = new main_window;
main_win->set_owner(this);
- progress_window = NULL;
autoconnect_midi_index = -1;
gui_win = NULL;
session_manager = NULL;
@@ -65,7 +64,7 @@ void host_session::add_plugin(string name, string preset, string instance_name)
{
if (instance_name.empty())
instance_name = get_next_instance_name(name);
- jack_host *jh = create_jack_host(name.c_str(), instance_name, this);
+ jack_host *jh = create_jack_host(name.c_str(), instance_name, main_win);
if (!jh) {
string s =
#define PER_MODULE_ITEM(name, isSynth, jackname) jackname ", "
@@ -92,36 +91,6 @@ void host_session::add_plugin(string name, string preset, string instance_name)
}
}
-void host_session::report_progress(float percentage, const std::string &message)
-{
- if (percentage < 100)
- {
- if (!progress_window) {
- progress_window = create_progress_window();
- gtk_window_set_modal (GTK_WINDOW (progress_window), TRUE);
- if (main_win->toplevel)
- gtk_window_set_transient_for (GTK_WINDOW (progress_window), main_win->toplevel);
- }
- gtk_widget_show(progress_window);
- GtkWidget *pbar = gtk_bin_get_child (GTK_BIN (progress_window));
- if (!message.empty())
- gtk_progress_bar_set_text (GTK_PROGRESS_BAR (pbar), message.c_str());
- gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (pbar), percentage / 100.0);
- }
- else
- {
- if (progress_window) {
- gtk_window_set_modal (GTK_WINDOW (progress_window), FALSE);
- gtk_widget_destroy (progress_window);
- progress_window = NULL;
- }
- }
-
- while (gtk_events_pending ())
- gtk_main_iteration ();
-}
-
-
void host_session::create_plugins_from_list()
{
for (unsigned int i = 0; i < plugin_names.size(); i++) {
@@ -129,17 +98,7 @@ void host_session::create_plugins_from_list()
}
}
-GtkWidget *host_session::create_progress_window()
-{
- GtkWidget *tlw = gtk_window_new ( GTK_WINDOW_TOPLEVEL );
- gtk_window_set_type_hint (GTK_WINDOW (tlw), GDK_WINDOW_TYPE_HINT_DIALOG);
- GtkWidget *pbar = gtk_progress_bar_new();
- gtk_container_add (GTK_CONTAINER(tlw), pbar);
- gtk_widget_show_all (pbar);
- return tlw;
-}
-
-static void window_destroy_cb(GtkWindow *window, gpointer data)
+void host_session::on_main_window_destroy()
{
gtk_main_quit();
}
@@ -151,19 +110,17 @@ void host_session::open()
if (!midi_name.empty()) client.midi_name = midi_name;
client.open(client_name.c_str());
- main_win->prefix = client_name + " - ";
- main_win->conditions.insert("jackhost");
- main_win->conditions.insert("directlink");
- main_win->conditions.insert("configure");
+ main_win->add_condition("jackhost");
+ main_win->add_condition("directlink");
+ main_win->add_condition("configure");
if (!session_manager || !session_manager->is_being_restored())
create_plugins_from_list();
main_win->create();
- gtk_signal_connect(GTK_OBJECT(main_win->toplevel), "destroy", G_CALLBACK(window_destroy_cb), NULL);
}
void host_session::new_plugin(const char *name)
{
- jack_host *jh = create_jack_host(name, get_next_instance_name(name), this);
+ jack_host *jh = create_jack_host(name, get_next_instance_name(name), main_win);
if (!jh)
return;
instances.insert(jh->instance_name);
@@ -315,7 +272,7 @@ void host_session::connect()
load_name = "";
}
}
- main_win->current_filename = load_name;
+ set_current_filename(load_name);
}
if (session_manager)
session_manager->connect("calf-" + client_name);
@@ -326,7 +283,6 @@ void host_session::close()
if (session_manager)
session_manager->disconnect();
main_win->on_closed();
- main_win->close_guis();
client.deactivate();
client.delete_plugins();
client.close();
@@ -489,7 +445,17 @@ void host_session::save(session_save_iface *stream)
void host_session::sigusr1handler(int signum)
{
- instance->main_win->save_file_from_sighandler();
+ instance->save_file_on_next_idle_call = true;
+}
+
+void host_session::on_idle()
+{
+ if (save_file_on_next_idle_call)
+ {
+ save_file_on_next_idle_call = false;
+ main_win->save_file();
+ printf("LADISH Level 1 support: file '%s' saved\n", get_current_filename().c_str());
+ }
}
void host_session::set_ladish_handler()
@@ -514,3 +480,13 @@ std::string host_session::get_client_name() const
{
return client.name;
}
+
+std::string host_session::get_current_filename() const
+{
+ return current_filename;
+}
+
+void host_session::set_current_filename(const std::string &name)
+{
+ current_filename = name;
+}
diff --git a/src/main_win.cpp b/src/main_win.cpp
index ae72913..1d18210 100644
--- a/src/main_win.cpp
+++ b/src/main_win.cpp
@@ -34,6 +34,7 @@ main_window::main_window()
owner = NULL;
notifier = NULL;
is_closed = true;
+ progress_window = NULL;
}
static const char *ui_xml =
@@ -437,7 +438,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, this);
- gui_win->create(plugin, (prefix + plugin->get_metadata_iface()->get_label()).c_str(), plugin->get_metadata_iface()->get_id());
+ gui_win->create(plugin, (owner->get_client_name() + " - " + plugin->get_metadata_iface()->get_label()).c_str(), plugin->get_metadata_iface()->get_id());
gtk_widget_show(GTK_WIDGET(gui_win->toplevel));
plugins[plugin]->gui_win = gui_win;
}
@@ -481,6 +482,11 @@ std::string main_window::make_plugin_list(GtkActionGroup *actions)
return s + plugin_post_xml;
}
+static void window_destroy_cb(GtkWindow *window, gpointer data)
+{
+ ((main_window *)data)->owner->on_main_window_destroy();
+}
+
void main_window::create()
{
toplevel = GTK_WINDOW(gtk_window_new (GTK_WINDOW_TOPLEVEL));
@@ -537,6 +543,7 @@ void main_window::create()
notifier = get_config_db()->add_listener(this);
on_config_change();
+ gtk_signal_connect(GTK_OBJECT(toplevel), "destroy", G_CALLBACK(window_destroy_cb), this);
}
void main_window::on_config_change()
@@ -551,17 +558,6 @@ void main_window::refresh_plugin(plugin_ctl_iface *plugin)
plugins[plugin]->gui_win->gui->refresh();
}
-void main_window::close_guis()
-{
- for (std::map<plugin_ctl_iface *, plugin_strip *>::iterator i = plugins.begin(); i != plugins.end(); i++)
- {
- if (i->second && i->second->gui_win) {
- i->second->gui_win->close();
- }
- }
- plugins.clear();
-}
-
void main_window::on_closed()
{
if (notifier)
@@ -573,6 +569,14 @@ void main_window::on_closed()
g_source_remove(source_id);
is_closed = true;
toplevel = NULL;
+
+ for (std::map<plugin_ctl_iface *, plugin_strip *>::iterator i = plugins.begin(); i != plugins.end(); i++)
+ {
+ if (i->second && i->second->gui_win) {
+ i->second->gui_win->close();
+ }
+ }
+ plugins.clear();
}
static inline float LVL(float value)
@@ -583,12 +587,7 @@ static inline float LVL(float value)
gboolean main_window::on_idle(void *data)
{
main_window *self = (main_window *)data;
- if (self->save_file_on_next_idle_call)
- {
- self->save_file_on_next_idle_call = false;
- self->save_file();
- printf("LADISH Level 1 support: file '%s' saved\n", self->current_filename.c_str());
- }
+ self->owner->on_idle();
for (std::map<plugin_ctl_iface *, plugin_strip *>::iterator i = self->plugins.begin(); i != self->plugins.end(); i++)
{
if (i->second)
@@ -612,11 +611,6 @@ gboolean main_window::on_idle(void *data)
return TRUE;
}
-void main_window::save_file_from_sighandler()
-{
- save_file_on_next_idle_call = true;
-}
-
void main_window::open_file()
{
GtkWidget *dialog;
@@ -633,7 +627,7 @@ void main_window::open_file()
if (error)
display_error(error, filename);
else
- current_filename = filename;
+ owner->set_current_filename(filename);
g_free (filename);
free (error);
}
@@ -642,13 +636,13 @@ void main_window::open_file()
bool main_window::save_file()
{
- if (current_filename.empty())
+ if (owner->get_current_filename().empty())
return save_file_as();
- const char *error = owner->save_file(current_filename.c_str());
+ const char *error = owner->save_file(owner->get_current_filename().c_str());
if (error)
{
- display_error(error, current_filename.c_str());
+ display_error(error, owner->get_current_filename().c_str());
return false;
}
return true;
@@ -672,7 +666,7 @@ bool main_window::save_file_as()
display_error(error, filename);
else
{
- current_filename = filename;
+ owner->set_current_filename(filename);
success = true;
}
g_free (filename);
@@ -689,3 +683,48 @@ void main_window::display_error(const char *error, const char *filename)
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
}
+
+GtkWidget *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);
+ GtkWidget *pbar = gtk_progress_bar_new();
+ gtk_container_add (GTK_CONTAINER(tlw), pbar);
+ gtk_widget_show_all (pbar);
+ return tlw;
+}
+
+void main_window::report_progress(float percentage, const std::string &message)
+{
+ if (percentage < 100)
+ {
+ if (!progress_window) {
+ progress_window = create_progress_window();
+ gtk_window_set_modal (GTK_WINDOW (progress_window), TRUE);
+ if (toplevel)
+ gtk_window_set_transient_for (GTK_WINDOW (progress_window), toplevel);
+ }
+ gtk_widget_show(progress_window);
+ GtkWidget *pbar = gtk_bin_get_child (GTK_BIN (progress_window));
+ if (!message.empty())
+ gtk_progress_bar_set_text (GTK_PROGRESS_BAR (pbar), message.c_str());
+ gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (pbar), percentage / 100.0);
+ }
+ else
+ {
+ if (progress_window) {
+ gtk_window_set_modal (GTK_WINDOW (progress_window), FALSE);
+ gtk_widget_destroy (progress_window);
+ progress_window = NULL;
+ }
+ }
+
+ while (gtk_events_pending ())
+ gtk_main_iteration ();
+}
+
+void main_window::add_condition(const std::string &name)
+{
+ conditions.insert(name);
+}
+
--
calf audio plugins packaging
More information about the pkg-multimedia-commits
mailing list