From 01c06da832a513fa7206dcb4cecc88d3d909d54c Mon Sep 17 00:00:00 2001 From: petern Date: Thu, 26 Nov 2009 17:19:03 +0000 Subject: [PATCH] Gui progress git-svn-id: file:///home/vcs/svn/jsweeper/trunk@6 6611ac79-6612-48ef-a1e9-b906f853523e --- src/config.cpp | 3 +- src/config.h | 1 + src/gui.cpp | 181 ++++++++++++++++++++++++++++++--- src/gui.h | 68 ++++++++++++- src/jack.cpp | 21 +--- src/jack.h | 2 + src/jsweeper.cpp | 3 +- src/jsweeper.glade | 240 ++++++++++++++++++++++++++++++++------------ src/matrix.cpp | 15 ++- src/matrix.h | 12 ++- src/portmanager.cpp | 30 ++++++ src/portmanager.h | 1 + 12 files changed, 468 insertions(+), 109 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index d911afa..db3a42c 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -22,6 +22,7 @@ void Config::Read() CellPadding = group->GetValue("cellpadding", 3); FontSize = group->GetValue("fontsize", 10); FontFace = group->GetValue("fontface", "Sans"); + SeparateByPortType = group->GetValue("separatebyporttype", false); ExpandClients = group->GetValue("expandclients", true); ExpandGroups = group->GetValue("expandgroups", false); @@ -54,7 +55,7 @@ void Config::Write() group->SetValue("cellpadding", CellPadding); group->SetValue("fontsize", FontSize); group->SetValue("fontface", FontFace); - + group->SetValue("separatebyporttype", SeparateByPortType); group->SetValue("expandclients", ExpandClients); group->SetValue("expandgroups", ExpandGroups); diff --git a/src/config.h b/src/config.h index a10487c..8c931ad 100644 --- a/src/config.h +++ b/src/config.h @@ -15,6 +15,7 @@ public: int FontSize; std::string FontFace; + bool SeparateByPortType; bool ExpandClients; bool ExpandGroups; diff --git a/src/gui.cpp b/src/gui.cpp index fc6591e..eecffd1 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -10,21 +10,14 @@ Glib::RefPtr g_builder; Gui::Gui(BaseObjectType *cobject, const Glib::RefPtr &builder) : Gtk::Window(cobject), - m_scrolledwindow_audio(NULL), - m_scrolledwindow_midi(NULL) + m_vbox(NULL), + m_matrix_audio(NULL), + m_matrix_midi(NULL), + m_closing(false) { - builder->get_widget("scrolledwindow_audio", m_scrolledwindow_audio); - builder->get_widget("scrolledwindow_midi", m_scrolledwindow_midi); - - if (m_scrolledwindow_audio != NULL) { - m_scrolledwindow_audio->add(m_matrix); - } - if (m_scrolledwindow_midi != NULL) { - m_scrolledwindow_midi->add(m_matrix); - } - - m_matrix.parent = this; + builder->get_widget("vbox1", m_vbox); + SetPortTypeSeparation(); Refresh(); Glib::signal_idle().connect(sigc::mem_fun(*this, &Gui::on_idle)); @@ -35,6 +28,76 @@ Gui::Gui(BaseObjectType *cobject, const Glib::RefPtr &builder) Gui::~Gui() { + m_closing = true; + delete m_matrix_audio; + delete m_matrix_midi; +} + +void Gui::SetPortTypeSeparation() +{ + if (cfg.SeparateByPortType) { + if (m_matrix_audio && m_matrix_midi) return; + + m_scrolledwindow_audio.remove(); + m_scrolledwindow_midi.remove(); + + if (m_notebook.pages().size() > 0) { + m_notebook.remove(m_scrolledwindow_audio); + m_notebook.remove(m_scrolledwindow_midi); + } + + if (m_vbox->children().size() == 3) { + m_vbox->remove(m_scrolledwindow_audio); + } + + delete m_matrix_audio; + delete m_matrix_midi; + + m_matrix_audio = new Matrix(PT_AUDIO); + m_matrix_midi = new Matrix(PT_MIDI); + + m_notebook.pages().clear(); + + m_notebook.pages().push_back( + Gtk::Notebook_Helpers::TabElem(m_scrolledwindow_audio, "Audio")); + m_scrolledwindow_audio.add(*m_matrix_audio); + m_scrolledwindow_audio.show(); + + m_notebook.pages().push_back( + Gtk::Notebook_Helpers::TabElem(m_scrolledwindow_midi, "MIDI")); + m_scrolledwindow_midi.add(*m_matrix_midi); + m_scrolledwindow_midi.show(); + + m_notebook.show(); + m_notebook.signal_switch_page().connect(sigc::mem_fun(*this, &Gui::on_notebook_switch_page)); + + m_vbox->pack_start(m_notebook); + } else { + if (m_matrix_audio && !m_matrix_midi) return; + + m_scrolledwindow_audio.remove(); + m_scrolledwindow_midi.remove(); + + if (m_notebook.pages().size() > 0) { + m_notebook.remove(m_scrolledwindow_audio); + m_notebook.remove(m_scrolledwindow_midi); + } + + if (m_vbox->children().size() == 3) { + m_vbox->remove(m_notebook); + } + + delete m_matrix_audio; + delete m_matrix_midi; + + m_matrix_audio = new Matrix(PT_ALL); + m_matrix_midi = NULL; + + m_scrolledwindow_audio.add(*m_matrix_audio); + m_scrolledwindow_audio.show(); + + m_vbox->pack_start(m_scrolledwindow_audio); + } } Gui *Gui::Open() @@ -50,11 +113,22 @@ Gui *Gui::Open() void Gui::Refresh() { - m_matrix.Refresh(); + if (m_closing) return; + + if (cfg.SeparateByPortType) { + int page = m_notebook.get_current_page(); + + if (page == 0 && m_matrix_audio != NULL) m_matrix_audio->Refresh(); + if (page == 1 && m_matrix_midi != NULL) m_matrix_midi->Refresh(); + } else { + if (m_matrix_audio != NULL) m_matrix_audio->Refresh(); + } } bool Gui::on_idle() { + if (m_closing) return false; + if (jack.ProcessEvents()) { Refresh(); queue_draw(); @@ -65,9 +139,66 @@ bool Gui::on_idle() return true; } +void Gui::on_notebook_switch_page(GtkNotebookPage * /* page */, guint /* page_num */) +{ + if (m_closing) return; + + Refresh(); +} + Preferences::Preferences(BaseObjectType *cobject, const Glib::RefPtr &builder) : Gtk::Dialog(cobject) { + builder->get_widget("button_preferences_close", button_preferences_close); + + builder->get_widget("check_separate_port_type", check_separate_port_type); + builder->get_widget("check_expand_clients", check_expand_clients); + builder->get_widget("check_expand_groups", check_expand_groups); + + builder->get_widget("check_default_location", check_default_location); + builder->get_widget("filechooser_custom_location", filechooser_custom_location); + + builder->get_widget("check_activate_connections", check_activate_connections); + builder->get_widget("treeview_connections", treeview_connections); + builder->get_widget("button_connections_add", button_connections_add); + builder->get_widget("button_connections_remove", button_connections_remove); + builder->get_widget("button_connections_edit", button_connections_edit); + builder->get_widget("button_connections_up", button_connections_up); + builder->get_widget("button_connections_down", button_connections_down); + + builder->get_widget("check_activate_aliases", check_activate_aliases); + builder->get_widget("treeview_aliases", treeview_aliases); + builder->get_widget("button_aliases_add", button_aliases_add); + builder->get_widget("button_aliases_remove", button_aliases_remove); + builder->get_widget("button_aliases_edit", button_aliases_edit); + builder->get_widget("button_aliases_up", button_aliases_up); + builder->get_widget("button_aliases_down", button_aliases_down); + + builder->get_widget("fontbutton_font", fontbutton_font); + builder->get_widget("spin_cell_padding", spin_cell_padding); + + builder->get_widget("colorbutton_background", colour_background); + builder->get_widget("colorbutton_clients", colour_clients); + builder->get_widget("colorbutton_port_groups", colour_port_groups); + builder->get_widget("colorbutton_ports_audio", colour_ports_audio); + builder->get_widget("colorbutton_ports_midi", colour_ports_midi); + builder->get_widget("colorbutton_text", colour_text); + builder->get_widget("colorbutton_grid_client", colour_grid_client); + builder->get_widget("colorbutton_grid_group", colour_grid_group); + builder->get_widget("colorbutton_grid_port", colour_grid_port); + + check_separate_port_type->set_active(cfg.SeparateByPortType); + check_expand_clients->set_active(cfg.ExpandClients); + check_expand_groups->set_active(cfg.ExpandGroups); + + fontbutton_font->set_font_name(cfg.FontFace); + spin_cell_padding->set_value(cfg.CellPadding); + + button_preferences_close->signal_clicked().connect(sigc::mem_fun(*this, &Preferences::on_preferences_close_click)); + + check_separate_port_type->signal_clicked().connect(sigc::mem_fun(*this, &Preferences::on_check_separate_port_type_click)); + check_expand_clients->signal_clicked().connect(sigc::mem_fun(*this, &Preferences::on_check_expand_clients_click)); + check_expand_groups->signal_clicked().connect(sigc::mem_fun(*this, &Preferences::on_check_expand_groups_click)); } Preferences *Preferences::Open() @@ -76,3 +207,25 @@ Preferences *Preferences::Open() g_builder->get_widget_derived("dialog_preferences", window); return window; } + +void Preferences::on_preferences_close_click() +{ + hide(); +} + +void Preferences::on_check_separate_port_type_click() +{ + cfg.SeparateByPortType = check_separate_port_type->get_active(); + g->SetPortTypeSeparation(); + g->Refresh(); +} + +void Preferences::on_check_expand_clients_click() +{ + cfg.ExpandClients = check_expand_clients->get_active(); +} + +void Preferences::on_check_expand_groups_click() +{ + cfg.ExpandGroups = check_expand_groups->get_active(); +} diff --git a/src/gui.h b/src/gui.h index f672c3e..2cb9955 100644 --- a/src/gui.h +++ b/src/gui.h @@ -9,9 +9,15 @@ extern Glib::RefPtr g_builder; class Gui : public Gtk::Window { private: - Gtk::ScrolledWindow *m_scrolledwindow_audio; - Gtk::ScrolledWindow *m_scrolledwindow_midi; - Matrix m_matrix; + Gtk::Notebook m_notebook; + Gtk::ScrolledWindow m_scrolledwindow_audio; + Gtk::ScrolledWindow m_scrolledwindow_midi; + + Gtk::VBox *m_vbox; + Matrix *m_matrix_audio; + Matrix *m_matrix_midi; + + bool m_closing; public: Gui(BaseObjectType *cobject, const Glib::RefPtr &builder); @@ -19,17 +25,73 @@ public: static Gui *Open(); virtual ~Gui(); + void SetPortTypeSeparation(); void Refresh(); protected: bool on_idle(); + void on_notebook_switch_page(GtkNotebookPage * /* page */, guint /* page_num */); }; class Preferences : public Gtk::Dialog { +private: + Gtk::Button *button_preferences_close; + + // Grid behaviour + Gtk::CheckButton *check_separate_port_type; + Gtk::CheckButton *check_expand_clients; + Gtk::CheckButton *check_expand_groups; + + // Session + Gtk::CheckButton *check_default_location; + Gtk::FileChooserButton *filechooser_custom_location; + + // Connections + Gtk::CheckButton *check_activate_connections; + Gtk::TreeView *treeview_connections; + Gtk::Button *button_connections_add; + Gtk::Button *button_connections_remove; + Gtk::Button *button_connections_edit; + Gtk::Button *button_connections_up; + Gtk::Button *button_connections_down; + + // Aliases + Gtk::CheckButton *check_activate_aliases; + Gtk::TreeView *treeview_aliases; + Gtk::Button *button_aliases_add; + Gtk::Button *button_aliases_remove; + Gtk::Button *button_aliases_edit; + Gtk::Button *button_aliases_up; + Gtk::Button *button_aliases_down; + + // Grid layout + Gtk::FontButton *fontbutton_font; + Gtk::SpinButton *spin_cell_padding; + + // Colours + Gtk::ColorButton *colour_background; + Gtk::ColorButton *colour_clients; + Gtk::ColorButton *colour_port_groups; + Gtk::ColorButton *colour_ports_audio; + Gtk::ColorButton *colour_ports_midi; + Gtk::ColorButton *colour_text; + Gtk::ColorButton *colour_grid_client; + Gtk::ColorButton *colour_grid_group; + Gtk::ColorButton *colour_grid_port; + public: Preferences(BaseObjectType *cobject, const Glib::RefPtr &builder); static Preferences *Open(); + +protected: + void on_preferences_close_click(); + + void on_check_separate_port_type_click(); + void on_check_expand_clients_click(); + void on_check_expand_groups_click(); }; +extern Gui *g; + #endif // GUI_H diff --git a/src/jack.cpp b/src/jack.cpp index c6240a2..26f6fc0 100644 --- a/src/jack.cpp +++ b/src/jack.cpp @@ -39,25 +39,7 @@ void JackDriver::Connect() jack_activate(m_client); - const char **ports = jack_get_ports(m_client, NULL, NULL, 0); - - for (int i = 0; ports[i] != NULL; ++i) { - pm.Add(jack_port_by_name(m_client, ports[i])); - } - - for (int i = 0; ports[i] != NULL; ++i) { - jack_port_t *port = jack_port_by_name(m_client, ports[i]); - if (jack_port_flags(port) & JackPortIsInput) { - const char **connections = jack_port_get_all_connections(m_client, port); - if (connections != NULL) { - for (int j = 0; connections[j] != NULL; ++j) { - pm.Connect(port, jack_port_by_name(m_client, connections[j])); - } - free(connections); - } - } - } - free(ports); + pm.Refresh(); return; } @@ -150,4 +132,3 @@ void JackDriver::Disconnect(jack_port_t *a, jack_port_t *b) { jack_disconnect(m_client, jack_port_name(a), jack_port_name(b)); } - diff --git a/src/jack.h b/src/jack.h index 17a9390..40889d5 100644 --- a/src/jack.h +++ b/src/jack.h @@ -62,6 +62,8 @@ public: void Connect(jack_port_t *a, jack_port_t *b); void Disconnect(jack_port_t *a, jack_port_t *b); + + jack_client_t *GetClient() { return m_client; } }; extern JackDriver jack; diff --git a/src/jsweeper.cpp b/src/jsweeper.cpp index 2190b42..c9c956c 100644 --- a/src/jsweeper.cpp +++ b/src/jsweeper.cpp @@ -6,6 +6,7 @@ PortManager pm; JackDriver jack; Config cfg; +Gui *g; int main(int argc, char **argv) { @@ -17,7 +18,7 @@ int main(int argc, char **argv) jack.Connect(); - Gui *g = Gui::Open(); + g = Gui::Open(); kit.run(*g); delete g; diff --git a/src/jsweeper.glade b/src/jsweeper.glade index c13be3e..e26e446 100644 --- a/src/jsweeper.glade +++ b/src/jsweeper.glade @@ -1,6 +1,6 @@ - + JACK Sweeper @@ -153,64 +153,7 @@ - - True - True - - - True - True - GTK_POLICY_AUTOMATIC - GTK_POLICY_AUTOMATIC - GTK_SHADOW_IN - - - - - - False - - - - - True - Audio - - - tab - False - - - - - True - True - GTK_POLICY_AUTOMATIC - GTK_POLICY_AUTOMATIC - GTK_SHADOW_IN - - - - - - 1 - - - - - True - MIDI - - - tab - 1 - False - - - - - 1 - + @@ -219,6 +162,7 @@ False + GTK_PACK_END 2 @@ -277,7 +221,7 @@ True 6 - + True True Use separate pane for MIDI ports @@ -898,8 +842,8 @@ True - 4 - 2 + 5 + 4 6 6 @@ -940,7 +884,7 @@ True 0 - Port tabs: + Audio port tabs: 3 @@ -995,7 +939,7 @@ - + True True True @@ -1010,6 +954,174 @@ GTK_EXPAND + + + True + 0 + MIDI port tabs: + + + 4 + 5 + GTK_FILL + + + + + True + True + True + 0 + #000000000000 + + + 1 + 2 + 4 + 5 + GTK_EXPAND + + + + + True + 0 + Foreground: + + + 2 + 3 + GTK_FILL + + + + + True + True + True + 0 + #000000000000 + + + 3 + 4 + + + + + + True + True + True + 0 + #000000000000 + + + 3 + 4 + 1 + 2 + + + + + + True + True + True + 0 + #000000000000 + + + 3 + 4 + 2 + 3 + + + + + + True + True + True + 0 + #000000000000 + + + 3 + 4 + 3 + 4 + + + + + + True + + + 3 + 4 + 4 + 5 + GTK_FILL + + + + + True + 0 + Grid lines (clients): + + + 2 + 3 + 1 + 2 + GTK_FILL + + + + + True + 0 + Grid lines (groups): + + + 2 + 3 + 2 + 3 + GTK_FILL + + + + + True + 0 + Grid lines (ports): + + + 2 + 3 + 3 + 4 + GTK_FILL + + + + + True + + + 2 + 3 + 4 + 5 + GTK_FILL + + 1 diff --git a/src/matrix.cpp b/src/matrix.cpp index 4d7663b..e5e35ae 100644 --- a/src/matrix.cpp +++ b/src/matrix.cpp @@ -8,8 +8,8 @@ const Rect Rect::None = Rect(0, 0, -1, -1); -Matrix::Matrix() : - m_client_width(0), m_client_height(0), m_port_width(0), m_port_height(0), m_separation(0) +Matrix::Matrix(PortType port_type) : + m_client_width(0), m_client_height(0), m_port_width(0), m_port_height(0), m_separation(0), m_port_type(port_type) { set_size_request(0, 0); show(); @@ -45,6 +45,9 @@ void Matrix::Refresh() PortList::iterator plit; for (plit = pm.m_ports.begin(); plit != pm.m_ports.end(); ++plit) { Port *p = *plit; + + if (m_port_type != PT_ALL && m_port_type != (p->m_is_midi ? PT_MIDI : PT_AUDIO)) continue; + p->rect = Rect::None; } @@ -52,6 +55,8 @@ void Matrix::Refresh() for (clit = pm.m_clients.begin(); clit != pm.m_clients.end(); ++clit) { Client *c = *clit; + if (m_port_type != PT_ALL && m_port_type != (c->m_is_midi ? PT_MIDI : PT_AUDIO)) continue; + cr->get_text_extents(c->m_name, c->extents); int width = c->extents.width + cfg.CellPadding * 2; @@ -149,6 +154,8 @@ void Matrix::Refresh() for (clit = pm.m_clients.begin(); clit != pm.m_clients.end(); ++clit) { Client *c = *clit; + if (m_port_type != PT_ALL && m_port_type != (c->m_is_midi ? PT_MIDI : PT_AUDIO)) continue; + if (c->m_is_input) { r.left = x; r.top = cfg.CellPadding; @@ -282,7 +289,6 @@ void Matrix::Refresh() m_height = h; set_size_request(w, h); -// parent->set_size_request(w + 20, h + 20); } static void SetColour(Cairo::RefPtr cr, Colour &c) @@ -337,6 +343,9 @@ bool Matrix::on_expose_event(GdkEventExpose *event) ClientList::iterator clit; for (clit = pm.m_clients.begin(); clit != pm.m_clients.end(); ++clit) { Client *c = *clit; + + if (m_port_type != PT_ALL && m_port_type != (c->m_is_midi ? PT_MIDI : PT_AUDIO)) continue; + r = c->rect; if (c->m_is_input) { diff --git a/src/matrix.h b/src/matrix.h index e635979..2fd9d5e 100644 --- a/src/matrix.h +++ b/src/matrix.h @@ -8,6 +8,12 @@ typedef std::list BaseList; +enum PortType { + PT_ALL, + PT_AUDIO, + PT_MIDI +}; + class Matrix : public Gtk::DrawingArea { private: @@ -19,17 +25,17 @@ private: int m_width; int m_height; + PortType m_port_type; + BaseList across; BaseList down; public: - Matrix(); + Matrix(PortType port_type); virtual ~Matrix(); void Refresh(); - Gtk::Window *parent; - protected: void Box(Cairo::RefPtr cr, Colour &c, Rect &rect); virtual bool on_expose_event(GdkEventExpose *event); diff --git a/src/portmanager.cpp b/src/portmanager.cpp index 37ca217..aac7bd6 100644 --- a/src/portmanager.cpp +++ b/src/portmanager.cpp @@ -5,6 +5,36 @@ #include "portmanager.h" #include "config.h" +void PortManager::Refresh() +{ + // Clear all information + m_clients.clear(); + m_ports.clear(); + + jack_client_t *client = jack.GetClient(); + + const char **ports = jack_get_ports(client, NULL, NULL, 0); + + for (int i = 0; ports[i] != NULL; ++i) { + Add(jack_port_by_name(client, ports[i])); + } + + for (int i = 0; ports[i] != NULL; ++i) { + jack_port_t *port = jack_port_by_name(client, ports[i]); + if (jack_port_flags(port) & JackPortIsInput) { + const char **connections = jack_port_get_all_connections(client, port); + if (connections != NULL) { + for (int j = 0; connections[j] != NULL; ++j) { + pm.Connect(port, jack_port_by_name(client, connections[j])); + } + free(connections); + } + } + } + + free(ports); +} + void PortManager::Add(jack_port_t *port) { std::string jack_name = jack_port_name(port); diff --git a/src/portmanager.h b/src/portmanager.h index 57f39af..8aeb6ed 100644 --- a/src/portmanager.h +++ b/src/portmanager.h @@ -20,6 +20,7 @@ public: AliasList m_aliases; public: + void Refresh(); void Add(jack_port_t *port); void Delete(jack_port_t *port);