summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/GladeFile.hpp55
-rw-r--r--src/LashDriver.cpp1
-rw-r--r--src/Makefile.am27
-rw-r--r--src/Patchage.cpp86
-rw-r--r--src/Patchage.hpp28
-rw-r--r--src/StateManager.cpp61
-rw-r--r--src/StateManager.hpp8
7 files changed, 113 insertions, 153 deletions
diff --git a/src/GladeFile.hpp b/src/GladeFile.hpp
new file mode 100644
index 0000000..fb4c474
--- /dev/null
+++ b/src/GladeFile.hpp
@@ -0,0 +1,55 @@
+/* This file is part of Patchage.
+ * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
+ *
+ * Patchage 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 of the License, or (at your option) any later
+ * version.
+ *
+ * Patchage 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 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 St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef GLADEFILE_HPP
+#define GLADEFILE_HPP
+
+#include <string>
+#include <fstream>
+#include <sstream>
+#include <stdexcept>
+#include <libglademm/xml.h>
+
+
+class GladeFile
+{
+public:
+ static Glib::RefPtr<Gnome::Glade::Xml> open(const std::string& base_name) {
+ Glib::RefPtr<Gnome::Glade::Xml> xml;
+
+ // Check for the .glade file in current directory
+ std::string glade_filename = std::string("./").append(base_name).append(".glade");
+ std::ifstream fs(glade_filename.c_str());
+ if (fs.fail()) { // didn't find it, check DATA_PATH
+ fs.clear();
+ glade_filename = std::string(DATA_DIR).append("/").append(base_name).append(".glade");
+
+ fs.open(glade_filename.c_str());
+ if (fs.fail()) {
+ std::ostringstream ss;
+ ss << "Unable to find " << base_name << "glade in current directory or "
+ << DATA_DIR << std::endl;
+ throw std::runtime_error(ss.str());
+ }
+ fs.close();
+ }
+
+ return Gnome::Glade::Xml::create(glade_filename);
+ }
+};
+
+#endif //GLADEFILE_HPP
diff --git a/src/LashDriver.cpp b/src/LashDriver.cpp
index eeab10c..d29261d 100644
--- a/src/LashDriver.cpp
+++ b/src/LashDriver.cpp
@@ -88,7 +88,6 @@ void
LashDriver::on_save_file(const string& directory)
{
cout << "[LashDriver] LASH Save File - " << directory << endl;
- _app->store_window_location();
_app->state_manager()->save(directory + "/locations");
}
diff --git a/src/Makefile.am b/src/Makefile.am
index 24a5ec0..6d7a63d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,4 @@
-AM_CXXFLAGS = -I.. -I$(top_srcdir)/raul -I$(top_srcdir)/flowcanvas -DPKGDATADIR=\"$(pkgdatadir)\" @GTHREAD_CFLAGS@ @LIBGLADEMM_CFLAGS@ @GNOMECANVASMM_CFLAGS@ @JACK_CFLAGS@ @ALSA_CFLAGS@ @LASH_CFLAGS@
+AM_CXXFLAGS = -I.. -I$(top_srcdir)/raul -I$(top_srcdir)/flowcanvas -DDATA_DIR=\"$(pkgdatadir)\" @GTHREAD_CFLAGS@ @LIBGLADEMM_CFLAGS@ @GNOMECANVASMM_CFLAGS@ @JACK_CFLAGS@ @ALSA_CFLAGS@ @LASH_CFLAGS@
patchage_LDADD = @GTHREAD_LIBS@ @LIBGLADEMM_LIBS@ @GNOMECANVASMM_LIBS@ @JACK_LIBS@ @ALSA_LIBS@ @LASH_LIBS@ @RAUL_LIBS@ @FLOWCANVAS_LIBS@
EXTRA_DIST = patchage.gladep
@@ -8,21 +8,22 @@ dist_sharefiles_DATA = patchage.glade
bin_PROGRAMS = patchage
patchage_SOURCES = \
- main.cpp \
- Patchage.hpp \
- Patchage.cpp \
- JackSettingsDialog.hpp \
- StateManager.hpp \
- StateManager.cpp \
- PatchageModule.hpp \
- PatchagePort.hpp \
Driver.hpp \
- PatchageEvent.hpp \
- PatchageEvent.cpp \
- JackDriver.hpp \
+ GladeFile.hpp \
JackDriver.cpp \
+ JackDriver.hpp \
+ JackSettingsDialog.hpp \
+ Patchage.cpp \
+ Patchage.hpp \
+ PatchageCanvas.cpp \
PatchageCanvas.hpp \
- PatchageCanvas.cpp
+ PatchageEvent.cpp \
+ PatchageEvent.hpp \
+ PatchageModule.hpp \
+ PatchagePort.hpp \
+ StateManager.cpp \
+ StateManager.hpp \
+ main.cpp
if WITH_LASH
patchage_SOURCES += LashDriver.hpp LashDriver.cpp
diff --git a/src/Patchage.cpp b/src/Patchage.cpp
index c52513d..0991380 100644
--- a/src/Patchage.cpp
+++ b/src/Patchage.cpp
@@ -24,18 +24,19 @@
#include <jack/statistics.h>
#include CONFIG_H_PATH
+#include "GladeFile.hpp"
+#include "JackDriver.hpp"
+#include "JackSettingsDialog.hpp"
#include "Patchage.hpp"
+#include "PatchageCanvas.hpp"
#include "PatchageEvent.hpp"
#include "StateManager.hpp"
-#include "PatchageCanvas.hpp"
-#include "JackDriver.hpp"
-#include "JackSettingsDialog.hpp"
-#ifdef HAVE_LASH
-#include "LashDriver.hpp"
-#endif
#ifdef HAVE_ALSA
#include "AlsaDriver.hpp"
#endif
+#ifdef HAVE_LASH
+#include "LashDriver.hpp"
+#endif
using namespace std;
@@ -72,19 +73,20 @@ gtkmm_set_width_for_given_text (Gtk::Widget &w, const gchar *text,
Patchage::Patchage(int argc, char** argv)
-: _pane_closed(false),
- _update_pane_position(true),
- _user_pane_position(0),
+ : xml(GladeFile::open("patchage"))
#ifdef HAVE_LASH
- _lash_driver(NULL),
+ , _lash_driver(NULL)
#endif
#ifdef HAVE_ALSA
- _alsa_driver(NULL),
+ , _alsa_driver(NULL)
#endif
- _jack_driver(NULL),
- _state_manager(NULL),
- _refresh(false),
- _enable_refresh(true)
+ , _jack_driver(NULL)
+ , _state_manager(NULL)
+ , _refresh(false)
+ , _enable_refresh(true)
+ , _pane_closed(false)
+ , _update_pane_position(true)
+ , _user_pane_position(0)
{
_settings_filename = getenv("HOME");
_settings_filename += "/.patchagerc";
@@ -104,26 +106,6 @@ Patchage::Patchage(int argc, char** argv)
_lash_driver = new LashDriver(this, argc, argv);
#endif
- Glib::RefPtr<Gnome::Glade::Xml> xml;
-
- // Check for the .glade file in current directory
- string glade_filename = "./patchage.glade";
- ifstream fs(glade_filename.c_str());
- if (fs.fail()) { // didn't find it, check PKGDATADIR
- fs.clear();
- glade_filename = PKGDATADIR;
- glade_filename += "/patchage.glade";
-
- fs.open(glade_filename.c_str());
- if (fs.fail()) {
- cerr << "Unable to find patchage.glade in current directory or " << PKGDATADIR << "." << endl;
- exit(EXIT_FAILURE);
- }
- fs.close();
- }
-
- xml = Gnome::Glade::Xml::create(glade_filename);
-
xml->get_widget("patchage_win", _main_window);
xml->get_widget_derived("jack_settings_win", _jack_settings_dialog);
xml->get_widget("about_win", _about_window);
@@ -420,20 +402,6 @@ Patchage::update_state()
if (module)
module->load_location();
}
-
- //cerr << "[Patchage] Resizing window: (" << _state_manager->get_window_size().x
- // << "," << _state_manager->get_window_size().y << ")" << endl;
-
- _main_window->resize(
- static_cast<int>(_state_manager->get_window_size().x),
- static_cast<int>(_state_manager->get_window_size().y));
-
- //cerr << "[Patchage] Moving window: (" << _state_manager->get_window_location().x
- // << "," << _state_manager->get_window_location().y << ")" << endl;
-
- _main_window->move(
- static_cast<int>(_state_manager->get_window_location().x),
- static_cast<int>(_state_manager->get_window_location().y));
}
@@ -582,7 +550,6 @@ Patchage::menu_alsa_disconnect()
void
Patchage::menu_store_positions()
{
- store_window_location();
_state_manager->save(_settings_filename);
}
@@ -711,25 +678,6 @@ Patchage::menu_help_about()
}
-/** Update the stored window location and size in the StateManager (in memory).
- */
-void
-Patchage::store_window_location()
-{
- int loc_x, loc_y, size_x, size_y;
- _main_window->get_position(loc_x, loc_y);
- _main_window->get_size(size_x, size_y);
- Coord window_location;
- window_location.x = loc_x;
- window_location.y = loc_y;
- Coord window_size;
- window_size.x = size_x;
- window_size.y = size_y;
- _state_manager->set_window_location(window_location);
- _state_manager->set_window_size(window_size);
-}
-
-
void
Patchage::clear_load()
{
diff --git a/src/Patchage.hpp b/src/Patchage.hpp
index 5f54c7e..96aa35d 100644
--- a/src/Patchage.hpp
+++ b/src/Patchage.hpp
@@ -21,6 +21,7 @@
#include <string>
#include <boost/shared_ptr.hpp>
#include <libgnomecanvasmm.h>
+#include <libglademm/xml.h>
#include CONFIG_H_PATH
class PatchageCanvas;
@@ -51,20 +52,18 @@ public:
void attach();
void quit() { _main_window->hide(); }
+
+ void refresh();
+ inline void queue_refresh() { _refresh = true; }
void clear_load();
-
- void refresh();
-
- void update_state();
- void store_window_location();
-
void status_message(const std::string& msg);
- inline void queue_refresh() { _refresh = true; }
+ void update_state();
- int max_pane_position()
- { return _main_paned->property_max_position()
- - _messages_expander->get_label_widget()->get_height() - 10; }
+ int max_pane_position() {
+ return _main_paned->property_max_position()
+ - _messages_expander->get_label_widget()->get_height() - 10;
+ }
protected:
void connect_widgets();
@@ -88,10 +87,8 @@ protected:
void on_pane_position_changed();
void on_messages_expander_changed();
-
- bool _pane_closed;
- bool _update_pane_position;
- int _user_pane_position;
+
+ Glib::RefPtr<Gnome::Glade::Xml> xml;
#ifdef HAVE_LASH
LashDriver* _lash_driver;
@@ -129,6 +126,9 @@ protected:
std::string _settings_filename;
bool _refresh;
bool _enable_refresh;
+ bool _pane_closed;
+ bool _update_pane_position;
+ int _user_pane_position;
Gtk::Window* _main_window;
JackSettingsDialog* _jack_settings_dialog;
diff --git a/src/StateManager.cpp b/src/StateManager.cpp
index 22fdb9a..86fe07c 100644
--- a/src/StateManager.cpp
+++ b/src/StateManager.cpp
@@ -27,10 +27,6 @@ using namespace std;
StateManager::StateManager()
{
- _window_location.x = 0;
- _window_location.y = 0;
- _window_size.x = 640;
- _window_size.y = 480;
_zoom = 1.0;
}
@@ -104,23 +100,22 @@ StateManager::load(const string& filename)
}
string s;
-
- is >> s;
- if (s != "window_location") throw std::runtime_error("Corrupt settings file.");
is >> s;
- _window_location.x = atoi(s.c_str());
- is >> s;
- _window_location.y = atoi(s.c_str());
- is >> s;
- if (s != "window_size") throw std::runtime_error("Corrupt settings file.");
- is >> s;
- _window_size.x = atoi(s.c_str());
- is >> s;
- _window_size.y = atoi(s.c_str());
+ if (s == "window_location") {
+ is >> s; is >> s; is >> s;// skip
+ }
+
+ if (s == "window_size") {
+ is >> s; is >> s; is >> s;// skip
+ }
- is >> s;
- if (s != "zoom_level") throw std::runtime_error("Corrupt settings file.");
+ if (s != "zoom_level") {
+ std::string msg = "Corrupt settings file: expected \"zoom_level\", found \"";
+ msg.append(s).append("\"");
+ throw std::runtime_error(msg);
+ }
+
is >> s;
_zoom = atof(s.c_str());
@@ -170,8 +165,6 @@ StateManager::save(const string& filename)
std::ofstream os;
os.open(filename.c_str(), std::ios::out);
- os << "window_location " << _window_location.x << " " << _window_location.y << std::endl;
- os << "window_size " << _window_size.x << " " << _window_size.y << std::endl;
os << "zoom_level " << _zoom << std::endl;
ModuleLocation ml;
@@ -191,34 +184,6 @@ StateManager::save(const string& filename)
}
-Coord
-StateManager::get_window_location()
-{
- return _window_location;
-}
-
-
-void
-StateManager::set_window_location(Coord loc)
-{
- _window_location = loc;
-}
-
-
-Coord
-StateManager::get_window_size()
-{
- return _window_size;
-}
-
-
-void
-StateManager::set_window_size(Coord size)
-{
- _window_size = size;
-}
-
-
float
StateManager::get_zoom()
{
diff --git a/src/StateManager.hpp b/src/StateManager.hpp
index af89944..71d6bdd 100644
--- a/src/StateManager.hpp
+++ b/src/StateManager.hpp
@@ -53,12 +53,6 @@ public:
void set_module_split(const string& name, bool split);
bool get_module_split(const string& name, bool default_val) const;
- Coord get_window_location();
- void set_window_location(Coord loc);
-
- Coord get_window_size();
- void set_window_size(Coord loc);
-
float get_zoom();
void set_zoom(float zoom);
@@ -67,8 +61,6 @@ public:
private:
list<ModuleLocation> _module_locations;
map<string,bool> _module_splits;
- Coord _window_location;
- Coord _window_size;
float _zoom;
};