2010-01-04 10:27:37 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <iostream>
|
2009-11-29 11:38:34 +00:00
|
|
|
#include "config.h"
|
2009-11-25 09:22:48 +00:00
|
|
|
#include "jack.h"
|
|
|
|
#include "portmanager.h"
|
|
|
|
#include "gui.h"
|
2009-11-28 16:40:47 +00:00
|
|
|
#include "session_gui.h"
|
2009-11-29 11:38:34 +00:00
|
|
|
#include "preferences_gui.h"
|
2009-11-25 09:22:48 +00:00
|
|
|
|
2010-01-04 10:27:37 +00:00
|
|
|
#define PACKAGE_NAME "jsweeper"
|
|
|
|
|
2009-11-26 08:34:17 +00:00
|
|
|
Glib::RefPtr<Gtk::Builder> g_builder;
|
2009-11-25 09:22:48 +00:00
|
|
|
|
2009-11-26 08:34:17 +00:00
|
|
|
Gui::Gui(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &builder)
|
|
|
|
: Gtk::Window(cobject),
|
2009-11-26 17:19:03 +00:00
|
|
|
m_vbox(NULL),
|
|
|
|
m_matrix_audio(NULL),
|
|
|
|
m_matrix_midi(NULL),
|
|
|
|
m_closing(false)
|
2009-11-26 08:34:17 +00:00
|
|
|
{
|
2009-11-26 17:19:03 +00:00
|
|
|
builder->get_widget("vbox1", m_vbox);
|
2009-11-25 09:22:48 +00:00
|
|
|
|
2009-11-26 17:19:03 +00:00
|
|
|
SetPortTypeSeparation();
|
2009-11-25 09:22:48 +00:00
|
|
|
Refresh();
|
|
|
|
|
2009-12-20 23:33:26 +00:00
|
|
|
Glib::signal_timeout().connect(sigc::mem_fun(*this, &Gui::on_timeout), 50);
|
2009-11-26 10:38:37 +00:00
|
|
|
|
2009-11-26 23:38:32 +00:00
|
|
|
Glib::RefPtr<Gtk::UIManager> uim = Glib::RefPtr<Gtk::UIManager>::cast_static(builder->get_object("uimanager1"));
|
|
|
|
uim->get_action("/menubar1/menuitem1/menu_quit")->signal_activate().connect(sigc::mem_fun(*this, &Gui::on_quit));
|
|
|
|
uim->get_action("/menubar1/menuitem5/menu_session_open")->signal_activate().connect(sigc::mem_fun(*this, &Gui::on_session_open));
|
|
|
|
uim->get_action("/menubar1/menuitem5/menu_session_save")->signal_activate().connect(sigc::mem_fun(*this, &Gui::on_session_save));
|
|
|
|
uim->get_action("/menubar1/menuitem5/menu_session_save_as")->signal_activate().connect(sigc::mem_fun(*this, &Gui::on_session_save_as));
|
|
|
|
uim->get_action("/menubar1/menuitem5/menu_session_close")->signal_activate().connect(sigc::mem_fun(*this, &Gui::on_session_close));
|
|
|
|
uim->get_action("/menubar1/menuitem2/menu_preferences")->signal_activate().connect(sigc::mem_fun(*this, &Gui::on_preferences));
|
|
|
|
uim->get_action("/menubar1/menuitem3/menu_connect")->signal_activate().connect(sigc::mem_fun(*this, &Gui::on_connect));
|
|
|
|
uim->get_action("/menubar1/menuitem3/menu_disconnect")->signal_activate().connect(sigc::mem_fun(*this, &Gui::on_disconnect));
|
|
|
|
uim->get_action("/menubar1/menuitem4/menu_about")->signal_activate().connect(sigc::mem_fun(*this, &Gui::on_about));
|
2009-11-25 09:22:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Gui::~Gui()
|
|
|
|
{
|
2009-11-26 17:19:03 +00:00
|
|
|
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);
|
|
|
|
}
|
2009-11-25 09:22:48 +00:00
|
|
|
}
|
|
|
|
|
2010-01-04 10:27:37 +00:00
|
|
|
static void TryLoad(const char *filename)
|
|
|
|
{
|
|
|
|
struct stat out;
|
|
|
|
if (stat(filename, &out) == 0) {
|
|
|
|
g_builder = Gtk::Builder::create_from_file(filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-26 08:34:17 +00:00
|
|
|
Gui *Gui::Open()
|
|
|
|
{
|
|
|
|
if (g_builder == NULL) {
|
2010-01-04 10:27:37 +00:00
|
|
|
const char * const *dirs = g_get_system_data_dirs();
|
|
|
|
|
|
|
|
while (*dirs != NULL && g_builder == NULL) {
|
|
|
|
std::string path = *dirs;
|
|
|
|
path = Glib::build_filename(path, PACKAGE_NAME);
|
|
|
|
path = Glib::build_filename(path, "jsweeper.ui");
|
|
|
|
|
|
|
|
TryLoad(path.c_str());
|
|
|
|
|
|
|
|
dirs++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_builder == NULL) TryLoad("jsweeper.ui");
|
|
|
|
|
|
|
|
if (g_builder == NULL) {
|
|
|
|
std::cerr << "Failed to load jsweeper.ui!" << std::endl;
|
|
|
|
exit(-1);
|
|
|
|
}
|
2009-11-26 08:34:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Gui *window = NULL;
|
|
|
|
g_builder->get_widget_derived("window1", window);
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
2009-11-25 09:22:48 +00:00
|
|
|
void Gui::Refresh()
|
|
|
|
{
|
2009-11-26 17:19:03 +00:00
|
|
|
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();
|
|
|
|
}
|
2009-11-25 09:22:48 +00:00
|
|
|
}
|
|
|
|
|
2009-12-20 23:33:26 +00:00
|
|
|
bool Gui::on_timeout()
|
2009-11-25 09:22:48 +00:00
|
|
|
{
|
2009-11-26 17:19:03 +00:00
|
|
|
if (m_closing) return false;
|
|
|
|
|
2009-11-25 09:22:48 +00:00
|
|
|
if (jack.ProcessEvents()) {
|
|
|
|
Refresh();
|
|
|
|
queue_draw();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-11-26 17:19:03 +00:00
|
|
|
void Gui::on_notebook_switch_page(GtkNotebookPage * /* page */, guint /* page_num */)
|
|
|
|
{
|
|
|
|
if (m_closing) return;
|
|
|
|
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
2009-11-26 23:38:32 +00:00
|
|
|
void Gui::on_quit()
|
|
|
|
{
|
|
|
|
hide();
|
|
|
|
}
|
2009-11-27 17:19:30 +00:00
|
|
|
|
2009-11-26 23:38:32 +00:00
|
|
|
void Gui::on_session_open()
|
|
|
|
{
|
2009-11-27 17:19:30 +00:00
|
|
|
SessionOpenGui *sgui = SessionOpenGui::Open();
|
|
|
|
sgui->show();
|
2009-11-26 23:38:32 +00:00
|
|
|
}
|
2009-11-27 17:19:30 +00:00
|
|
|
|
2009-11-26 23:38:32 +00:00
|
|
|
void Gui::on_session_save()
|
|
|
|
{
|
|
|
|
}
|
2009-11-27 17:19:30 +00:00
|
|
|
|
2009-11-26 23:38:32 +00:00
|
|
|
void Gui::on_session_save_as()
|
|
|
|
{
|
2009-11-28 16:40:47 +00:00
|
|
|
SessionSaveGui *sgui = SessionSaveGui::Open();
|
|
|
|
sgui->show();
|
2009-11-26 23:38:32 +00:00
|
|
|
}
|
2009-11-27 17:19:30 +00:00
|
|
|
|
2009-11-26 23:38:32 +00:00
|
|
|
void Gui::on_session_close()
|
|
|
|
{
|
|
|
|
}
|
2009-11-27 17:19:30 +00:00
|
|
|
|
2009-11-26 23:38:32 +00:00
|
|
|
void Gui::on_preferences()
|
|
|
|
{
|
|
|
|
Preferences *p = Preferences::Open();
|
|
|
|
p->show();
|
|
|
|
}
|
2009-11-27 17:19:30 +00:00
|
|
|
|
2009-11-26 23:38:32 +00:00
|
|
|
void Gui::on_connect()
|
|
|
|
{
|
|
|
|
jack.Connect();
|
|
|
|
Refresh();
|
|
|
|
}
|
2009-11-27 17:19:30 +00:00
|
|
|
|
2009-11-26 23:38:32 +00:00
|
|
|
void Gui::on_disconnect()
|
|
|
|
{
|
|
|
|
jack.Disconnect();
|
|
|
|
Refresh();
|
|
|
|
}
|
2009-11-27 17:19:30 +00:00
|
|
|
|
2009-11-26 23:38:32 +00:00
|
|
|
void Gui::on_about()
|
|
|
|
{
|
|
|
|
Gtk::AboutDialog *about; g_builder->get_widget("aboutdialog1", about);
|
|
|
|
about->show();
|
|
|
|
}
|