diff options
author | David Robillard <d@drobilla.net> | 2011-10-22 03:08:06 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-10-22 03:08:06 +0000 |
commit | ac1d6d135bda8d739fdb8bf564f89c38b664c097 (patch) | |
tree | d750da79dd88b64ab2a88cca1651c2a5a240bd72 /src | |
parent | 143968e38cc2f058dd7c500e984904a39864d652 (diff) | |
download | ingen-ac1d6d135bda8d739fdb8bf564f89c38b664c097.tar.gz ingen-ac1d6d135bda8d739fdb8bf564f89c38b664c097.tar.bz2 ingen-ac1d6d135bda8d739fdb8bf564f89c38b664c097.zip |
De-singleton-ify GUI.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@3584 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
50 files changed, 535 insertions, 424 deletions
diff --git a/src/gui/App.cpp b/src/gui/App.cpp index fc8ca916..c3fedd17 100644 --- a/src/gui/App.cpp +++ b/src/gui/App.cpp @@ -71,13 +71,10 @@ class Port; Gtk::Main* App::_main = 0; -/// Singleton instance -App* App::_instance = 0; - App::App(Ingen::Shared::World* world) - : _configuration(new Configuration()) + : _configuration(new Configuration(*this)) , _about_dialog(NULL) - , _window_factory(new WindowFactory()) + , _window_factory(new WindowFactory(*this)) , _world(world) , _sample_rate(48000) , _enable_signal(true) @@ -89,6 +86,9 @@ App::App(Ingen::Shared::World* world) WidgetFactory::get_widget_derived("messages_win", _messages_window); WidgetFactory::get_widget_derived("patch_tree_win", _patch_tree_window); WidgetFactory::get_widget("about_win", _about_dialog); + _connect_window->init_dialog(*this); + _messages_window->init_window(*this); + _patch_tree_window->init_window(*this); _about_dialog->property_program_name() = "Ingen"; _about_dialog->property_logo_icon_name() = "ingen"; @@ -102,22 +102,21 @@ App::~App() delete _window_factory; } -void -App::init(Ingen::Shared::World* world) +SharedPtr<App> +App::create(Ingen::Shared::World* world) { Gnome::Canvas::init(); _main = new Gtk::Main(&world->argc(), &world->argv()); - if (!_instance) - _instance = new App(world); + App* app = new App(world); // Load configuration settings - _instance->configuration()->load_settings(); - _instance->configuration()->apply_settings(); + app->configuration()->load_settings(); + app->configuration()->apply_settings(); // Set default window icon - _instance->_about_dialog->property_program_name() = "Ingen"; - _instance->_about_dialog->property_logo_icon_name() = "ingen"; + app->_about_dialog->property_program_name() = "Ingen"; + app->_about_dialog->property_logo_icon_name() = "ingen"; gtk_window_set_default_icon_name("ingen"); // Set style for embedded node GUIs @@ -137,20 +136,20 @@ App::init(Ingen::Shared::World* world) "widget \"*ingen_embedded_node_gui_container*\" style \"ingen_embedded_node_gui_style\"\n"; Gtk::RC::parse_string(rc_style); + + return SharedPtr<App>(app); } void App::run() { - App& me = App::instance(); - - me._connect_window->start(me.world()); + _connect_window->start(*this, world()); // Run main iterations here until we're attached to the engine. Otherwise // with 'ingen -egl' we'd get a bunch of notifications about load // immediately before even knowing about the root patch or plugins) - while (!me._connect_window->attached()) - if (me._main->iteration()) + while (!_connect_window->attached()) + if (_main->iteration()) break; _main->run(); @@ -168,9 +167,9 @@ App::attach(SharedPtr<SigClientInterface> client) _client = client; _store = SharedPtr<ClientStore>(new ClientStore(_world->uris(), _world->engine(), client)); - _loader = SharedPtr<ThreadedLoader>(new ThreadedLoader(_world->engine())); + _loader = SharedPtr<ThreadedLoader>(new ThreadedLoader(*this, _world->engine())); - _patch_tree_window->init(*_store); + _patch_tree_window->init(*this, *_store); _client->signal_response_error().connect( sigc::mem_fun(this, &App::error_response)); @@ -290,10 +289,10 @@ void App::register_callbacks() { Glib::signal_timeout().connect( - sigc::mem_fun(App::instance(), &App::gtk_main_iteration), 25, G_PRIORITY_DEFAULT); + sigc::mem_fun(*this, &App::gtk_main_iteration), 25, G_PRIORITY_DEFAULT); Glib::signal_timeout().connect( - sigc::mem_fun(App::instance(), &App::animate), 50, G_PRIORITY_DEFAULT); + sigc::mem_fun(*this, &App::animate), 50, G_PRIORITY_DEFAULT); } bool @@ -330,7 +329,7 @@ bool App::quit(Gtk::Window& dialog_parent) { bool quit = true; - if (App::instance().world()->local_engine()) { + if (_world->local_engine()) { Gtk::MessageDialog d(dialog_parent, "The engine is running in this process. Quitting will terminate Ingen." "\n\n" "Are you sure you want to quit?", @@ -346,6 +345,16 @@ App::quit(Gtk::Window& dialog_parent) return quit; } +struct IconDestroyNotification { + IconDestroyNotification(App& a, pair<string, int> k) + : app(a) + , key(k) + {} + + App& app; + pair<string, int> key; +}; + Glib::RefPtr<Gdk::Pixbuf> App::icon_from_path(const string& path, int size) { @@ -368,8 +377,9 @@ App::icon_from_path(const string& path, int size) try { buf = Gdk::Pixbuf::create_from_file(path, size, size); _icons.insert(make_pair(make_pair(path, size), buf.operator->())); - buf->add_destroy_notify_callback(new pair<string, int>(path, size), - &App::icon_destroyed); + buf->add_destroy_notify_callback( + new IconDestroyNotification(*this, make_pair(path, size)), + &App::icon_destroyed); } catch (Glib::Error e) { warn << "Error loading icon: " << e.what() << endl; } @@ -379,12 +389,12 @@ App::icon_from_path(const string& path, int size) void* App::icon_destroyed(void* data) { - pair<string, int>* p = static_cast<pair<string, int>*>(data); - Icons::iterator iter = instance()._icons.find(*p); - if (iter != instance()._icons.end()) - instance()._icons.erase(iter); + IconDestroyNotification* note = (IconDestroyNotification*)data; + Icons::iterator iter = note->app._icons.find(note->key); + if (iter != note->app._icons.end()) + note->app._icons.erase(iter); - delete p; // allocated in App::icon_from_path + delete note; // allocated in App::icon_from_path return NULL; } diff --git a/src/gui/App.hpp b/src/gui/App.hpp index 9cda522b..c7fa9f52 100644 --- a/src/gui/App.hpp +++ b/src/gui/App.hpp @@ -111,8 +111,8 @@ public: static inline App& instance() { assert(_instance); return *_instance; } - static void init(Ingen::Shared::World* world); - static void run(); + static SharedPtr<App> create(Ingen::Shared::World* world); + void run(); inline Ingen::Shared::World* world() const { return _world; } inline Ingen::Shared::URIs& uris() const { return *_world->uris(); } diff --git a/src/gui/BreadCrumbs.cpp b/src/gui/BreadCrumbs.cpp index 65c9630e..955edfb2 100644 --- a/src/gui/BreadCrumbs.cpp +++ b/src/gui/BreadCrumbs.cpp @@ -26,13 +26,13 @@ namespace GUI { using namespace std; using namespace Raul; -BreadCrumbs::BreadCrumbs() +BreadCrumbs::BreadCrumbs(App& app) : Gtk::HBox() , _active_path("/") , _full_path("/") , _enable_signal(true) { - App::instance().client()->signal_object_deleted().connect( + app.client()->signal_object_deleted().connect( sigc::mem_fun(this, &BreadCrumbs::object_destroyed)); } diff --git a/src/gui/BreadCrumbs.hpp b/src/gui/BreadCrumbs.hpp index 69c82a7c..e6fc3915 100644 --- a/src/gui/BreadCrumbs.hpp +++ b/src/gui/BreadCrumbs.hpp @@ -40,7 +40,7 @@ namespace GUI { class BreadCrumbs : public Gtk::HBox { public: - BreadCrumbs(); + BreadCrumbs(App& app); SharedPtr<PatchView> view(const Raul::Path& path); diff --git a/src/gui/Configuration.cpp b/src/gui/Configuration.cpp index 8358dc34..51eec5bc 100644 --- a/src/gui/Configuration.cpp +++ b/src/gui/Configuration.cpp @@ -37,9 +37,10 @@ namespace GUI { using namespace Ingen::Client; -Configuration::Configuration() +Configuration::Configuration(App& app) // Colours from the Tango palette with modified V and alpha - : _name_style(HUMAN) + : _app(app) + , _name_style(HUMAN) , _audio_port_color( 0x4A8A0EC0) // Green , _control_port_color(0x244678C0) // Blue , _event_port_color( 0x960909C0) // Red @@ -83,12 +84,12 @@ uint32_t Configuration::get_port_color(const PortModel* p) { assert(p != NULL); - const Shared::URIs& uris = App::instance().uris(); + const Shared::URIs& uris = _app.uris(); if (p->is_a(uris.lv2_AudioPort)) { return _audio_port_color; } else if (p->supports(uris.atom_String)) { return _string_port_color; - } else if (App::instance().can_control(p)) { + } else if (_app.can_control(p)) { return _control_port_color; } else if (p->is_a(uris.ev_EventPort) || p->is_a(uris.atom_MessagePort)) { return _event_port_color; diff --git a/src/gui/Configuration.hpp b/src/gui/Configuration.hpp index 6fe922d3..94bff71c 100644 --- a/src/gui/Configuration.hpp +++ b/src/gui/Configuration.hpp @@ -19,7 +19,9 @@ #define INGEN_GUI_CONFIGURATION_HPP #include <stdint.h> + #include <string> + #include "raul/SharedPtr.hpp" namespace Ingen { namespace Client { class PortModel; } } @@ -29,6 +31,7 @@ using std::string; namespace Ingen { namespace GUI { +class App; class Port; /** Singleton state manager for the entire app. @@ -41,7 +44,7 @@ class Port; class Configuration { public: - Configuration(); + Configuration(App& app); ~Configuration(); void load_settings(string filename = ""); @@ -60,6 +63,8 @@ public: void set_name_style(NameStyle s) { _name_style = s; } private: + App& _app; + /** Most recent patch folder shown in open dialog */ string _patch_folder; diff --git a/src/gui/ConnectWindow.cpp b/src/gui/ConnectWindow.cpp index 9ccdb192..0b1aa47d 100644 --- a/src/gui/ConnectWindow.cpp +++ b/src/gui/ConnectWindow.cpp @@ -61,8 +61,10 @@ ConnectWindow::ConnectWindow(BaseObjectType* cobject, } void -ConnectWindow::start(Ingen::Shared::World* world) +ConnectWindow::start(App& app, Ingen::Shared::World* world) { + _app = &app; + if (world->local_engine()) { _mode = INTERNAL; if (_widgets_loaded) { @@ -78,7 +80,7 @@ ConnectWindow::start(Ingen::Shared::World* world) void ConnectWindow::set_connected_to(SharedPtr<ServerInterface> engine) { - App::instance().world()->set_engine(engine); + _app->world()->set_engine(engine); if (!_widgets_loaded) return; @@ -100,7 +102,7 @@ ConnectWindow::set_connected_to(SharedPtr<ServerInterface> engine) _connect_button->set_sensitive(true); _disconnect_button->set_sensitive(false); - if (App::instance().world()->local_engine()) + if (_app->world()->local_engine()) _internal_radio->set_sensitive(true); else _internal_radio->set_sensitive(false); @@ -144,12 +146,12 @@ ConnectWindow::connect(bool existing) if (_attached) _attached = false; - assert(!App::instance().client()); + assert(!_app->client()); _connect_stage = 0; set_connecting_widget_states(); - Ingen::Shared::World* world = App::instance().world(); + Ingen::Shared::World* world = _app->world(); #if defined(HAVE_LIBLO) || defined(HAVE_SOUP) if (_mode == CONNECT_REMOTE) { @@ -172,8 +174,8 @@ ConnectWindow::connect(bool existing) world->set_engine(world->interface(uri, tsci)); - App::instance().attach(tsci); - App::instance().register_callbacks(); + _app->attach(tsci); + _app->register_callbacks(); Glib::signal_timeout().connect( sigc::mem_fun(this, &ConnectWindow::gtk_callback), 40); @@ -191,8 +193,8 @@ ConnectWindow::connect(bool existing) SharedPtr<ThreadedSigClientInterface> tsci(new ThreadedSigClientInterface(1024)); world->set_engine(world->interface(engine_uri, tsci)); - App::instance().attach(tsci); - App::instance().register_callbacks(); + _app->attach(tsci); + _app->register_callbacks(); Glib::signal_timeout().connect( sigc::mem_fun(this, &ConnectWindow::gtk_callback), 40); @@ -216,8 +218,8 @@ ConnectWindow::connect(bool existing) world->local_engine()->activate(); - App::instance().attach(client); - App::instance().register_callbacks(); + _app->attach(client); + _app->register_callbacks(); Glib::signal_timeout().connect( sigc::mem_fun(this, &ConnectWindow::gtk_callback), 10); @@ -230,7 +232,7 @@ ConnectWindow::disconnect() _connect_stage = -1; _attached = false; - App::instance().detach(); + _app->detach(); set_connected_to(SharedPtr<Ingen::ServerInterface>()); if (!_widgets_loaded) @@ -247,7 +249,7 @@ ConnectWindow::disconnect() void ConnectWindow::activate() { - App::instance().engine()->set_property("ingen:driver", + _app->engine()->set_property("ingen:driver", "ingen:enabled", true); } @@ -255,7 +257,7 @@ ConnectWindow::activate() void ConnectWindow::deactivate() { - App::instance().engine()->set_property("ingen:driver", + _app->engine()->set_property("ingen:driver", "ingen:enabled", false); } @@ -266,7 +268,7 @@ ConnectWindow::on_show() if (!_widgets_loaded) { load_widgets(); if (_attached) - set_connected_to(App::instance().engine()); + set_connected_to(_app->engine()); } Gtk::Dialog::on_show(); @@ -309,14 +311,14 @@ void ConnectWindow::on_hide() { Gtk::Dialog::on_hide(); - if (App::instance().window_factory()->num_open_patch_windows() == 0) + if (_app->window_factory()->num_open_patch_windows() == 0) quit(); } void ConnectWindow::quit_clicked() { - if (App::instance().quit(*this)) + if (_app->quit(*this)) _quit_flag = true; } @@ -370,12 +372,12 @@ ConnectWindow::gtk_callback() if (_connect_stage == 0) { _attached = false; - App::instance().client()->signal_response_ok().connect( + _app->client()->signal_response_ok().connect( sigc::mem_fun(this, &ConnectWindow::on_response)); _ping_id = abs(rand()) / 2 * 2; // avoid -1 - App::instance().engine()->respond_to(App::instance().client().get(), _ping_id); - App::instance().engine()->ping(); + _app->engine()->respond_to(_app->client().get(), _ping_id); + _app->engine()->ping(); if (_widgets_loaded) { _progress_label->set_text("Connecting to engine..."); @@ -391,31 +393,31 @@ ConnectWindow::gtk_callback() const float ms_since_last = (now.tv_sec - last.tv_sec) * 1000.0f + (now.tv_usec - last.tv_usec) * 0.001f; if (ms_since_last > 1000) { - App::instance().engine()->respond_to(App::instance().client().get(), _ping_id); - App::instance().engine()->ping(); + _app->engine()->respond_to(_app->client().get(), _ping_id); + _app->engine()->ping(); last = now; } } } else if (_connect_stage == 2) { - App::instance().engine()->get(Path("/")); + _app->engine()->get(Path("/")); if (_widgets_loaded) _progress_label->set_text(string("Requesting root patch...")); ++_connect_stage; } else if (_connect_stage == 3) { - if (App::instance().store()->size() > 0) { + if (_app->store()->size() > 0) { SharedPtr<const PatchModel> root = PtrCast<const PatchModel>( - App::instance().store()->object("/")); + _app->store()->object("/")); if (root) { - set_connected_to(App::instance().engine()); - App::instance().window_factory()->present_patch(root); - App::instance().engine()->get("ingen:plugins"); + set_connected_to(_app->engine()); + _app->window_factory()->present_patch(root); + _app->engine()->get("ingen:plugins"); if (_widgets_loaded) _progress_label->set_text(string("Loading plugins...")); ++_connect_stage; } } } else if (_connect_stage == 4) { - App::instance().engine()->get("ingen:plugins"); + _app->engine()->get("ingen:plugins"); hide(); if (_widgets_loaded) _progress_label->set_text("Connected to engine"); diff --git a/src/gui/ConnectWindow.hpp b/src/gui/ConnectWindow.hpp index 65ff11a2..9f82db32 100644 --- a/src/gui/ConnectWindow.hpp +++ b/src/gui/ConnectWindow.hpp @@ -44,7 +44,7 @@ public: const Glib::RefPtr<Gtk::Builder>& xml); void set_connected_to(SharedPtr<ServerInterface> engine); - void start(Ingen::Shared::World* world); + void start(App& app, Ingen::Shared::World* world); void on_response(int32_t id) { _attached = true; } bool attached() const { return _finished_connecting; } diff --git a/src/gui/ControlPanel.cpp b/src/gui/ControlPanel.cpp index 1aca1adf..6b3c180d 100644 --- a/src/gui/ControlPanel.cpp +++ b/src/gui/ControlPanel.cpp @@ -48,11 +48,13 @@ ControlPanel::~ControlPanel() } void -ControlPanel::init(SharedPtr<const NodeModel> node, uint32_t poly) +ControlPanel::init(App& app, SharedPtr<const NodeModel> node, uint32_t poly) { assert(node != NULL); assert(poly > 0); + _app = &app; + for (NodeModel::Ports::const_iterator i = node->ports().begin(); i != node->ports().end(); ++i) { add_port(*i); @@ -90,12 +92,12 @@ ControlPanel::add_port(SharedPtr<const PortModel> pm) ToggleControl* tc; WidgetFactory::get_widget_derived("toggle_control", tc); control = tc; - } else if (pm->is_a(App::instance().uris().lv2_ControlPort) - || pm->supports(App::instance().uris().atom_Float32)) { + } else if (pm->is_a(_app->uris().lv2_ControlPort) + || pm->supports(_app->uris().atom_Float32)) { SliderControl* sc; WidgetFactory::get_widget_derived("control_strip", sc); control = sc; - } else if (pm->supports(App::instance().uris().atom_String)) { + } else if (pm->supports(_app->uris().atom_String)) { StringControl* sc; WidgetFactory::get_widget_derived("string_control", sc); control = sc; @@ -103,7 +105,7 @@ ControlPanel::add_port(SharedPtr<const PortModel> pm) } if (control) { - control->init(this, pm); + control->init(*_app, this, pm); if (_controls.size() > 0) _control_box->pack_start(*Gtk::manage(new Gtk::HSeparator()), false, false, 4); @@ -142,9 +144,9 @@ ControlPanel::value_changed_atom(SharedPtr<const PortModel> port, const Raul::Atom& val) { if (_callback_enabled) { - App::instance().engine()->set_property(port->path(), - App::instance().uris().ingen_value, - val); + _app->engine()->set_property(port->path(), + _app->uris().ingen_value, + val); } } diff --git a/src/gui/ControlPanel.hpp b/src/gui/ControlPanel.hpp index a657b8d2..3e5aa8b6 100644 --- a/src/gui/ControlPanel.hpp +++ b/src/gui/ControlPanel.hpp @@ -38,6 +38,8 @@ using namespace Ingen::Client; namespace GUI { +class App; + /** A group of controls for a node (or patch). * * Used by both NodeControlWindow and the main window (for patch controls). @@ -50,7 +52,7 @@ public: const Glib::RefPtr<Gtk::Builder>& xml); virtual ~ControlPanel(); - void init(SharedPtr<const NodeModel> node, uint32_t poly); + void init(App& app, SharedPtr<const NodeModel> node, uint32_t poly); Control* find_port(const Raul::Path& path) const; @@ -72,12 +74,11 @@ public: } private: - bool _callback_enabled; - - std::pair<int,int> _ideal_size; - + App* _app; + std::pair<int,int> _ideal_size; std::vector<Control*> _controls; Gtk::VBox* _control_box; + bool _callback_enabled; }; } // namespace GUI diff --git a/src/gui/Controls.cpp b/src/gui/Controls.cpp index c239e7d8..c42f4b69 100644 --- a/src/gui/Controls.cpp +++ b/src/gui/Controls.cpp @@ -41,9 +41,10 @@ namespace GUI { Control::Control(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& xml) : Gtk::VBox(cobject) + , _app(NULL) , _control_panel(NULL) - , _enable_signal(false) , _name_label(NULL) + , _enable_signal(false) { Glib::RefPtr<Gtk::Builder> menu_xml = WidgetFactory::create("port_control_menu"); menu_xml->get_widget("port_control_menu", _menu); @@ -61,8 +62,9 @@ Control::~Control() } void -Control::init(ControlPanel* panel, SharedPtr<const PortModel> pm) +Control::init(App& app, ControlPanel* panel, SharedPtr<const PortModel> pm) { + _app = &app; _control_panel = panel; _port_model = pm, @@ -124,12 +126,12 @@ SliderControl::SliderControl(BaseObjectType* cobject, } void -SliderControl::init(ControlPanel* panel, SharedPtr<const PortModel> pm) +SliderControl::init(App& app, ControlPanel* panel, SharedPtr<const PortModel> pm) { _enable_signal = false; _enabled = true; - Control::init(panel, pm); + Control::init(app, panel, pm); assert(_name_label); assert(_slider); @@ -152,7 +154,7 @@ SliderControl::init(ControlPanel* panel, SharedPtr<const PortModel> pm) boost::shared_ptr<NodeModel> parent = PtrCast<NodeModel>(_port_model->parent()); if (parent) - parent->port_value_range(_port_model, min, max, App::instance().sample_rate()); + parent->port_value_range(_port_model, min, max, app.sample_rate()); if (pm->is_integer() || pm->is_toggle()) { _slider->set_increments(1, 10); @@ -214,7 +216,7 @@ SliderControl::port_property_changed(const URI& key, const Atom& value) { _enable_signal = false; - const Shared::URIs& uris = App::instance().uris(); + const Shared::URIs& uris = _app->uris(); if (key == uris.lv2_minimum && value.type() == Atom::FLOAT) set_range(value.get_float(), _slider->get_adjustment()->get_upper()); else if (key == uris.lv2_maximum && value.type() == Atom::FLOAT) @@ -298,11 +300,11 @@ ToggleControl::ToggleControl(BaseObjectType* cobject, } void -ToggleControl::init(ControlPanel* panel, SharedPtr<const PortModel> pm) +ToggleControl::init(App& app, ControlPanel* panel, SharedPtr<const PortModel> pm) { _enable_signal = false; - Control::init(panel, pm); + Control::init(app, panel, pm); assert(_name_label); assert(_checkbutton); @@ -357,11 +359,11 @@ StringControl::StringControl(BaseObjectType* cobject, } void -StringControl::init(ControlPanel* panel, SharedPtr<const PortModel> pm) +StringControl::init(App& app, ControlPanel* panel, SharedPtr<const PortModel> pm) { _enable_signal = false; - Control::init(panel, pm); + Control::init(app, panel, pm); assert(_name_label); assert(_entry); diff --git a/src/gui/Controls.hpp b/src/gui/Controls.hpp index 7ea5e6c3..9f33a53a 100644 --- a/src/gui/Controls.hpp +++ b/src/gui/Controls.hpp @@ -44,7 +44,9 @@ public: const Glib::RefPtr<Gtk::Builder>& xml); virtual ~Control(); - virtual void init(ControlPanel* panel, SharedPtr<const Client::PortModel> pm); + virtual void init(App& app, + ControlPanel* panel, + SharedPtr<const Client::PortModel> pm); void enable(); void disable(); @@ -58,14 +60,14 @@ protected: void set_label(const std::string& name); void menu_properties(); + App* _app; ControlPanel* _control_panel; SharedPtr<const Client::PortModel> _port_model; sigc::connection _control_connection; + Gtk::Menu* _menu; + Gtk::MenuItem* _menu_properties; + Gtk::Label* _name_label; bool _enable_signal; - - Gtk::Menu* _menu; - Gtk::MenuItem* _menu_properties; - Gtk::Label* _name_label; }; /** A slider for a continuous control. @@ -78,7 +80,9 @@ public: SliderControl(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& xml); - void init(ControlPanel* panel, SharedPtr<const Client::PortModel> pm); + void init(App& app, + ControlPanel* panel, + SharedPtr<const Client::PortModel> pm); void set_min(float val); void set_max(float val); @@ -112,7 +116,9 @@ public: ToggleControl(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& xml); - void init(ControlPanel* panel, SharedPtr<const Client::PortModel> pm); + void init(App& app, + ControlPanel* panel, + SharedPtr<const Client::PortModel> pm); private: void set_value(const Raul::Atom& value); @@ -131,7 +137,9 @@ public: StringControl(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& xml); - void init(ControlPanel* panel, SharedPtr<const Client::PortModel> pm); + void init(App& app, + ControlPanel* panel, + SharedPtr<const Client::PortModel> pm); private: void set_value(const Raul::Atom& value); diff --git a/src/gui/LoadPatchWindow.cpp b/src/gui/LoadPatchWindow.cpp index 1a96cc63..8c121b5e 100644 --- a/src/gui/LoadPatchWindow.cpp +++ b/src/gui/LoadPatchWindow.cpp @@ -42,6 +42,7 @@ namespace GUI { LoadPatchWindow::LoadPatchWindow(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& xml) : Gtk::FileChooserDialog(cobject) + , _app(NULL) , _merge_ports(false) { xml->get_widget("load_patch_symbol_label", _symbol_label); @@ -124,8 +125,8 @@ LoadPatchWindow::set_patch(SharedPtr<const PatchModel> patch) void LoadPatchWindow::on_show() { - if (App::instance().configuration()->patch_folder().length() > 0) - set_current_folder(App::instance().configuration()->patch_folder()); + if (_app->configuration()->patch_folder().length() > 0) + set_current_folder(_app->configuration()->patch_folder()); Gtk::FileChooserDialog::on_show(); } @@ -149,7 +150,7 @@ LoadPatchWindow::ok_clicked() return; } - const URIs& uris = App::instance().uris(); + const URIs& uris = _app->uris(); if (_poly_voices_radio->get_active()) _initial_data.insert(make_pair( @@ -168,7 +169,7 @@ LoadPatchWindow::ok_clicked() symbol = _patch->symbol(); } - App::instance().loader()->load_patch(true, get_uri(), + _app->loader()->load_patch(true, get_uri(), parent, symbol, _initial_data); } else { @@ -186,7 +187,7 @@ LoadPatchWindow::ok_clicked() symbol = avoid_symbol_clash(symbol); - App::instance().loader()->load_patch(false, *i, + _app->loader()->load_patch(false, *i, _patch->path(), symbol, _initial_data); } } @@ -213,7 +214,7 @@ LoadPatchWindow::symbol_from_filename(const Glib::ustring& filename) Raul::Symbol LoadPatchWindow::avoid_symbol_clash(const Raul::Symbol& symbol) { - unsigned offset = App::instance().store()->child_name_offset( + unsigned offset = _app->store()->child_name_offset( _patch->path(), symbol); if (offset != 0) { diff --git a/src/gui/LoadPatchWindow.hpp b/src/gui/LoadPatchWindow.hpp index cc8b906b..653148e9 100644 --- a/src/gui/LoadPatchWindow.hpp +++ b/src/gui/LoadPatchWindow.hpp @@ -45,6 +45,8 @@ public: LoadPatchWindow(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& xml); + void init(App& app) { _app = &app; } + void set_patch(SharedPtr<const PatchModel> patch); void present(SharedPtr<const PatchModel> patch, @@ -65,6 +67,8 @@ private: Raul::Symbol symbol_from_filename(const Glib::ustring& filename); Raul::Symbol avoid_symbol_clash(const Raul::Symbol& symbol); + App* _app; + GraphObject::Properties _initial_data; SharedPtr<const PatchModel> _patch; diff --git a/src/gui/LoadPluginWindow.cpp b/src/gui/LoadPluginWindow.cpp index c94fac30..c89b4c46 100644 --- a/src/gui/LoadPluginWindow.cpp +++ b/src/gui/LoadPluginWindow.cpp @@ -132,7 +132,7 @@ LoadPluginWindow::name_changed() string name = _node_name_entry->get_text(); if (!Path::is_valid_name(name)) { _add_button->property_sensitive() = false; - } else if (App::instance().store()->find_child(_patch, name)) { + } else if (_app->store()->find_child(_patch, name)) { _add_button->property_sensitive() = false; } else if (name.length() == 0) { _add_button->property_sensitive() = false; @@ -181,13 +181,13 @@ void LoadPluginWindow::on_show() { if (!_has_shown) { - App::instance().store()->signal_new_plugin().connect( + _app->store()->signal_new_plugin().connect( sigc::mem_fun(this, &LoadPluginWindow::add_plugin)); _has_shown = true; } if (_refresh_list) { - set_plugins(App::instance().store()->plugins()); + set_plugins(_app->store()->plugins()); _refresh_list = false; } @@ -224,7 +224,7 @@ void LoadPluginWindow::set_row(Gtk::TreeModel::Row& row, SharedPtr<const PluginModel> plugin) { - const URIs& uris = App::instance().uris(); + const URIs& uris = _app->uris(); const Atom& name = plugin->get_property(uris.doap_name); if (name.is_valid() && name.type() == Atom::STRING) row[_plugins_columns._col_name] = name.get_string(); @@ -290,7 +290,7 @@ LoadPluginWindow::plugin_selection_changed() Gtk::TreeModel::Row row = *iter; boost::shared_ptr<const PluginModel> p = row.get_value( _plugins_columns._col_plugin); - _name_offset = App::instance().store()->child_name_offset( + _name_offset = _app->store()->child_name_offset( _patch->path(), p->default_node_symbol()); _node_name_entry->set_text(generate_module_name(p, _name_offset)); _node_name_entry->set_sensitive(true); @@ -325,7 +325,7 @@ LoadPluginWindow::generate_module_name(SharedPtr<const PluginModel> plugin, void LoadPluginWindow::load_plugin(const Gtk::TreeModel::iterator& iter) { - const URIs& uris = App::instance().uris(); + const URIs& uris = _app->uris(); Gtk::TreeModel::Row row = *iter; SharedPtr<const PluginModel> plugin = row.get_value(_plugins_columns._col_plugin); bool polyphonic = _polyphonic_checkbutton->get_active(); @@ -346,7 +346,7 @@ LoadPluginWindow::load_plugin(const Gtk::TreeModel::iterator& iter) props.insert(make_pair(uris.rdf_type, uris.ingen_Node)); props.insert(make_pair(uris.rdf_instanceOf, plugin->uri())); props.insert(make_pair(uris.ingen_polyphonic, polyphonic)); - App::instance().engine()->put(path, props); + _app->engine()->put(path, props); if (_selection->get_selected_rows().size() == 1) { _name_offset = (_name_offset == 0) ? 2 : _name_offset + 1; @@ -386,10 +386,10 @@ LoadPluginWindow::filter_changed() Gtk::TreeModel::Row model_row; Gtk::TreeModel::iterator model_iter; size_t num_visible = 0; - const URIs& uris = App::instance().uris(); + const URIs& uris = _app->uris(); - for (ClientStore::Plugins::const_iterator i = App::instance().store()->plugins()->begin(); - i != App::instance().store()->plugins()->end(); ++i) { + for (ClientStore::Plugins::const_iterator i = _app->store()->plugins()->begin(); + i != _app->store()->plugins()->end(); ++i) { const SharedPtr<PluginModel> plugin = (*i).second; const Atom& name = plugin->get_property(uris.doap_name); @@ -439,7 +439,7 @@ LoadPluginWindow::plugin_property_changed(const URI& plugin, const URI& predicate, const Atom& value) { - const URIs& uris = App::instance().uris(); + const URIs& uris = _app->uris(); if (predicate == uris.doap_name) { Rows::const_iterator i = _rows.find(plugin); if (i != _rows.end() && value.type() == Atom::STRING) diff --git a/src/gui/LoadRemotePatchWindow.cpp b/src/gui/LoadRemotePatchWindow.cpp index 1bfafc50..55ceccc0 100644 --- a/src/gui/LoadRemotePatchWindow.cpp +++ b/src/gui/LoadRemotePatchWindow.cpp @@ -67,17 +67,17 @@ LoadRemotePatchWindow::present(SharedPtr<const PatchModel> patch, cerr << "FIXME: load remote patch" << endl; #if 0 - Sord::Model model(*App::instance().world()->rdf_world(), + Sord::Model model(*_app->world()->rdf_world(), "http://rdf.drobilla.net/ingen_patches/index.ttl", "http://rdf.drobilla.net/ingen_patches/"); - Sord::Query query(*App::instance().world()->rdf_world(), Glib::ustring( + Sord::Query query(*_app->world()->rdf_world(), Glib::ustring( "SELECT DISTINCT ?name ?uri WHERE {" " ?uri a ingen:Patch ;" " doap:name ?name ." "}")); - SharedPtr<Sord::QueryResults> results(query.run(*App::instance().world()->rdf_world(), model)); + SharedPtr<Sord::QueryResults> results(query.run(*_app->world()->rdf_world(), model)); for (; !results->finished(); results->next()) { Gtk::TreeModel::iterator iter = _liststore->append(); (*iter)[_columns._col_name] = results->get("name").to_string(); @@ -135,7 +135,7 @@ LoadRemotePatchWindow::open_clicked() if (!_patch->path().is_root()) parent = _patch->path().parent(); - App::instance().loader()->load_patch(true, uri, + _app->loader()->load_patch(true, uri, parent, symbol, _initial_data); hide(); diff --git a/src/gui/NewSubpatchWindow.cpp b/src/gui/NewSubpatchWindow.cpp index a21c65f8..504bc506 100644 --- a/src/gui/NewSubpatchWindow.cpp +++ b/src/gui/NewSubpatchWindow.cpp @@ -77,8 +77,8 @@ NewSubpatchWindow::name_changed() if (!Path::is_valid_name(name)) { _message_label->set_text("Name contains invalid characters."); _ok_button->property_sensitive() = false; - } else if (App::instance().store()->find(_patch->path().base() + name) - != App::instance().store()->end()) { + } else if (_app->store()->find(_patch->path().base() + name) + != _app->store()->end()) { _message_label->set_text("An object already exists with that name."); _ok_button->property_sensitive() = false; } else if (name.length() == 0) { @@ -93,21 +93,20 @@ NewSubpatchWindow::name_changed() void NewSubpatchWindow::ok_clicked() { - App& app = App::instance(); const Path path = _patch->path().base() + Path::nameify(_name_entry->get_text()); const uint32_t poly = _poly_spinbutton->get_value_as_int(); // Create patch Resource::Properties props; - props.insert(make_pair(app.uris().rdf_type, app.uris().ingen_Patch)); - props.insert(make_pair(app.uris().ingen_polyphony, Atom(int32_t(poly)))); - props.insert(make_pair(app.uris().ingen_enabled, Atom(bool(true)))); - app.engine()->put(path, props, Resource::INTERNAL); + props.insert(make_pair(_app->uris().rdf_type, _app->uris().ingen_Patch)); + props.insert(make_pair(_app->uris().ingen_polyphony, Atom(int32_t(poly)))); + props.insert(make_pair(_app->uris().ingen_enabled, Atom(bool(true)))); + _app->engine()->put(path, props, Resource::INTERNAL); // Set external (node perspective) properties props = _initial_data; - props.insert(make_pair(app.uris().rdf_type, app.uris().ingen_Patch)); - app.engine()->put(path, _initial_data, Resource::EXTERNAL); + props.insert(make_pair(_app->uris().rdf_type, _app->uris().ingen_Patch)); + _app->engine()->put(path, _initial_data, Resource::EXTERNAL); hide(); } diff --git a/src/gui/NodeControlWindow.cpp b/src/gui/NodeControlWindow.cpp index 97f81e69..2af13b98 100644 --- a/src/gui/NodeControlWindow.cpp +++ b/src/gui/NodeControlWindow.cpp @@ -33,7 +33,8 @@ namespace GUI { /** Create a node control window and load a new ControlPanel for it. */ -NodeControlWindow::NodeControlWindow(SharedPtr<const NodeModel> node, +NodeControlWindow::NodeControlWindow(App& app, + SharedPtr<const NodeModel> node, uint32_t poly) : _node(node) , _position_stored(false) @@ -53,7 +54,7 @@ NodeControlWindow::NodeControlWindow(SharedPtr<const NodeModel> node, show_all_children(); _control_panel->reparent(*this); - _control_panel->init(_node, poly); + _control_panel->init(app, _node, poly); _control_panel->show(); resize(); @@ -63,7 +64,8 @@ NodeControlWindow::NodeControlWindow(SharedPtr<const NodeModel> node, /** Create a node control window and with an existing ControlPanel. */ -NodeControlWindow::NodeControlWindow(SharedPtr<const NodeModel> node, +NodeControlWindow::NodeControlWindow(App& app, + SharedPtr<const NodeModel> node, ControlPanel* panel) : _node(node) , _control_panel(panel) diff --git a/src/gui/NodeControlWindow.hpp b/src/gui/NodeControlWindow.hpp index 30fb0a40..e8c728ce 100644 --- a/src/gui/NodeControlWindow.hpp +++ b/src/gui/NodeControlWindow.hpp @@ -43,8 +43,9 @@ class ControlPanel; class NodeControlWindow : public Window { public: - NodeControlWindow(SharedPtr<const NodeModel> node, uint32_t poly); - NodeControlWindow(SharedPtr<const NodeModel> node, ControlPanel* panel); + NodeControlWindow(App& app, SharedPtr<const NodeModel> node, uint32_t poly); + NodeControlWindow(App& app, SharedPtr<const NodeModel> node, ControlPanel* panel); + virtual ~NodeControlWindow(); SharedPtr<const NodeModel> node() const { return _node; } diff --git a/src/gui/NodeMenu.cpp b/src/gui/NodeMenu.cpp index af13e0cf..8efe89ac 100644 --- a/src/gui/NodeMenu.cpp +++ b/src/gui/NodeMenu.cpp @@ -44,14 +44,14 @@ NodeMenu::NodeMenu(BaseObjectType* cobject, } void -NodeMenu::init(SharedPtr<const NodeModel> node) +NodeMenu::init(App& app, SharedPtr<const NodeModel> node) { - ObjectMenu::init(node); + ObjectMenu::init(app, node); _learn_menuitem->signal_activate().connect(sigc::mem_fun(this, &NodeMenu::on_menu_learn)); _controls_menuitem->signal_activate().connect( - sigc::bind(sigc::mem_fun(App::instance().window_factory(), + sigc::bind(sigc::mem_fun(_app->window_factory(), &WindowFactory::present_controls), node)); _popup_gui_menuitem->signal_activate().connect( @@ -136,26 +136,26 @@ NodeMenu::on_menu_embed_gui() void NodeMenu::on_menu_randomize() { - App::instance().engine()->bundle_begin(); + _app->engine()->bundle_begin(); const NodeModel* const nm = (NodeModel*)_object.get(); for (NodeModel::Ports::const_iterator i = nm->ports().begin(); i != nm->ports().end(); ++i) { - if ((*i)->is_input() && App::instance().can_control(i->get())) { + if ((*i)->is_input() && _app->can_control(i->get())) { float min = 0.0f, max = 1.0f; - nm->port_value_range(*i, min, max, App::instance().sample_rate()); + nm->port_value_range(*i, min, max, _app->sample_rate()); const float val = ((rand() / (float)RAND_MAX) * (max - min) + min); - App::instance().engine()->set_property((*i)->path(), - App::instance().uris().ingen_value, val); + _app->engine()->set_property((*i)->path(), + _app->uris().ingen_value, val); } } - App::instance().engine()->bundle_end(); + _app->engine()->bundle_end(); } void NodeMenu::on_menu_disconnect() { - App::instance().engine()->disconnect_all(_object->parent()->path(), _object->path()); + _app->engine()->disconnect_all(_object->parent()->path(), _object->path()); } void @@ -179,7 +179,7 @@ NodeMenu::on_preset_activated(const std::string& uri) subject, port_pred, NULL); - App::instance().engine()->bundle_begin(); + _app->engine()->bundle_begin(); LILV_FOREACH(nodes, i, ports) { const LilvNode* uri = lilv_nodes_get(ports, i); LilvNodes* values = lilv_world_find_nodes( @@ -189,13 +189,13 @@ NodeMenu::on_preset_activated(const std::string& uri) if (values && symbols) { const LilvNode* val = lilv_nodes_get_first(values); const LilvNode* sym = lilv_nodes_get_first(symbols); - App::instance().engine()->set_property( + _app->engine()->set_property( node->path().base() + lilv_node_as_string(sym), - App::instance().uris().ingen_value, + _app->uris().ingen_value, lilv_node_as_float(val)); } } - App::instance().engine()->bundle_end(); + _app->engine()->bundle_end(); lilv_nodes_free(ports); lilv_node_free(value_pred); lilv_node_free(symbol_pred); diff --git a/src/gui/NodeMenu.hpp b/src/gui/NodeMenu.hpp index 382bd164..fe238e80 100644 --- a/src/gui/NodeMenu.hpp +++ b/src/gui/NodeMenu.hpp @@ -39,7 +39,7 @@ public: NodeMenu(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& xml); - void init(SharedPtr<const NodeModel> node); + void init(App& app, SharedPtr<const NodeModel> node); bool has_control_inputs(); diff --git a/src/gui/NodeModule.cpp b/src/gui/NodeModule.cpp index 7ba26c9b..5a8e30ad 100644 --- a/src/gui/NodeModule.cpp +++ b/src/gui/NodeModule.cpp @@ -72,7 +72,7 @@ NodeModule::~NodeModule() { embed_gui(false); - NodeControlWindow* win = App::instance().window_factory()->control_window(_node); + NodeControlWindow* win = app().window_factory()->control_window(_node); delete win; // Will be removed from window factory via signal } @@ -80,7 +80,7 @@ bool NodeModule::show_menu(GdkEventButton* ev) { WidgetFactory::get_widget_derived("object_menu", _menu); - _menu->init(_node); + _menu->init(app(), _node); _menu->signal_embed_gui.connect( sigc::mem_fun(this, &NodeModule::embed_gui)); _menu->signal_popup_gui.connect( @@ -118,10 +118,16 @@ NodeModule::create(PatchCanvas& canvas, return ret; } +App& +NodeModule::app() const +{ + return ((PatchCanvas*)canvas())->app(); +} + void NodeModule::show_human_names(bool b) { - const URIs& uris = App::instance().uris(); + const URIs& uris = app().uris(); if (b && node()->plugin()) { const Raul::Atom& name_property = node()->get_property(uris.lv2_name); @@ -183,7 +189,7 @@ NodeModule::plugin_changed() void NodeModule::embed_gui(bool embed) { - const URIs& uris = App::instance().uris(); + const URIs& uris = app().uris(); if (embed) { if (_gui_window) { @@ -193,7 +199,7 @@ NodeModule::embed_gui(bool embed) if (!_plugin_ui) { const PluginModel* const pm = dynamic_cast<const PluginModel*>(_node->plugin()); - _plugin_ui = pm->ui(App::instance().world(), _node); + _plugin_ui = pm->ui(app().world(), _node); } if (_plugin_ui) { @@ -213,8 +219,8 @@ NodeModule::embed_gui(bool embed) for (NodeModel::Ports::const_iterator p = _node->ports().begin(); p != _node->ports().end(); ++p) - if ((*p)->is_output() && App::instance().can_control(p->get())) - App::instance().engine()->set_property((*p)->path(), uris.ingen_broadcast, true); + if ((*p)->is_output() && app().can_control(p->get())) + app().engine()->set_property((*p)->path(), uris.ingen_broadcast, true); } } else { // un-embed @@ -224,8 +230,8 @@ NodeModule::embed_gui(bool embed) for (NodeModel::Ports::const_iterator p = _node->ports().begin(); p != _node->ports().end(); ++p) - if ((*p)->is_output() && App::instance().can_control(p->get())) - App::instance().engine()->set_property((*p)->path(), + if ((*p)->is_output() && app().can_control(p->get())) + app().engine()->set_property((*p)->path(), uris.ingen_broadcast, false); } @@ -241,7 +247,7 @@ NodeModule::embed_gui(bool embed) void NodeModule::rename() { - if (App::instance().configuration()->name_style() == Configuration::PATH) { + if (app().configuration()->name_style() == Configuration::PATH) { set_name(_node->path().symbol()); } } @@ -249,8 +255,8 @@ NodeModule::rename() void NodeModule::new_port_view(SharedPtr<const PortModel> port) { - Port::create(*this, port, - App::instance().configuration()->name_style() == Configuration::HUMAN); + Port::create(app(), *this, port, + app().configuration()->name_style() == Configuration::HUMAN); port->signal_value_changed().connect( sigc::bind<0>(sigc::mem_fun(this, &NodeModule::value_changed), @@ -291,7 +297,7 @@ NodeModule::popup_gui() const PluginModel* const plugin = dynamic_cast<const PluginModel*>(_node->plugin()); assert(plugin); - _plugin_ui = plugin->ui(App::instance().world(), _node); + _plugin_ui = plugin->ui(app().world(), _node); if (_plugin_ui) { GtkWidget* c_widget = (GtkWidget*)_plugin_ui->get_widget(); @@ -332,7 +338,7 @@ NodeModule::set_control_values() uint32_t index = 0; for (NodeModel::Ports::const_iterator p = _node->ports().begin(); p != _node->ports().end(); ++p) { - if (App::instance().can_control(p->get())) + if (app().can_control(p->get())) value_changed(index, (*p)->value()); ++index; } @@ -341,7 +347,7 @@ NodeModule::set_control_values() void NodeModule::show_control_window() { - App::instance().window_factory()->present_controls(_node); + app().window_factory()->present_controls(_node); } void @@ -357,7 +363,7 @@ NodeModule::store_location() const Atom x(static_cast<float>(property_x())); const Atom y(static_cast<float>(property_y())); - const URIs& uris = App::instance().uris(); + const URIs& uris = app().uris(); const Atom& existing_x = _node->get_property(uris.ingenui_canvas_x); const Atom& existing_y = _node->get_property(uris.ingenui_canvas_y); @@ -369,14 +375,14 @@ NodeModule::store_location() Resource::Properties add; add.insert(make_pair(uris.ingenui_canvas_x, x)); add.insert(make_pair(uris.ingenui_canvas_y, y)); - App::instance().engine()->delta(_node->path(), remove, add); + app().engine()->delta(_node->path(), remove, add); } } void NodeModule::property_changed(const URI& key, const Atom& value) { - const Shared::URIs& uris = App::instance().uris(); + const Shared::URIs& uris = app().uris(); switch (value.type()) { case Atom::FLOAT: if (key == uris.ingenui_canvas_x) { @@ -399,7 +405,7 @@ NodeModule::property_changed(const URI& key, const Atom& value) break; case Atom::STRING: if (key == uris.lv2_name - && App::instance().configuration()->name_style() == Configuration::HUMAN) { + && app().configuration()->name_style() == Configuration::HUMAN) { set_name(value.get_string()); } default: break; @@ -409,12 +415,11 @@ NodeModule::property_changed(const URI& key, const Atom& value) void NodeModule::set_selected(bool b) { - const App& app = App::instance(); - const URIs& uris = app.uris(); + const URIs& uris = app().uris(); if (b != selected()) { Module::set_selected(b); if (b) { - PatchWindow* win = app.window_factory()->parent_patch_window(node()); + PatchWindow* win = app().window_factory()->parent_patch_window(node()); if (win) { std::string doc; bool html = false; @@ -428,8 +433,8 @@ NodeModule::set_selected(bool b) } } } - if (App::instance().signal()) - App::instance().engine()->set_property(_node->path(), uris.ingen_selected, b); + if (app().signal()) + app().engine()->set_property(_node->path(), uris.ingen_selected, b); } } diff --git a/src/gui/NodeModule.hpp b/src/gui/NodeModule.hpp index b833bf82..5109be96 100644 --- a/src/gui/NodeModule.hpp +++ b/src/gui/NodeModule.hpp @@ -56,6 +56,8 @@ public: virtual ~NodeModule(); + App& app() const; + Port* port(boost::shared_ptr<const PortModel> model); void delete_port_view(SharedPtr<const PortModel> port); diff --git a/src/gui/ObjectMenu.cpp b/src/gui/ObjectMenu.cpp index 693dec73..10dffa6d 100644 --- a/src/gui/ObjectMenu.cpp +++ b/src/gui/ObjectMenu.cpp @@ -36,6 +36,7 @@ namespace GUI { ObjectMenu::ObjectMenu(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& xml) : Gtk::Menu(cobject) + , _app(NULL) , _polyphonic_menuitem(NULL) , _disconnect_menuitem(NULL) , _rename_menuitem(NULL) @@ -53,12 +54,11 @@ ObjectMenu::ObjectMenu(BaseObjectType* cobject, } void -ObjectMenu::init(SharedPtr<const ObjectModel> object) +ObjectMenu::init(App& app, SharedPtr<const ObjectModel> object) { + _app = &app; _object = object; - App& app = App::instance(); - _polyphonic_menuitem->signal_toggled().connect( sigc::mem_fun(this, &ObjectMenu::on_menu_polyphonic)); @@ -74,7 +74,7 @@ ObjectMenu::init(SharedPtr<const ObjectModel> object) sigc::mem_fun(this, &ObjectMenu::on_menu_disconnect)); _rename_menuitem->signal_activate().connect(sigc::bind( - sigc::mem_fun(app.window_factory(), &WindowFactory::present_rename), + sigc::mem_fun(_app->window_factory(), &WindowFactory::present_rename), object)); _destroy_menuitem->signal_activate().connect( @@ -94,9 +94,9 @@ ObjectMenu::init(SharedPtr<const ObjectModel> object) void ObjectMenu::on_menu_learn() { - App::instance().engine()->set_property(_object->path(), - App::instance().uris().ingen_controlBinding, - App::instance().uris().wildcard); + _app->engine()->set_property(_object->path(), + _app->uris().ingen_controlBinding, + _app->uris().wildcard); } void @@ -104,24 +104,24 @@ ObjectMenu::on_menu_unlearn() { Resource::Properties remove; remove.insert(std::make_pair( - App::instance().uris().ingen_controlBinding, - App::instance().uris().wildcard)); - App::instance().engine()->delta(_object->path(), remove, Resource::Properties()); + _app->uris().ingen_controlBinding, + _app->uris().wildcard)); + _app->engine()->delta(_object->path(), remove, Resource::Properties()); } void ObjectMenu::on_menu_polyphonic() { if (_enable_signal) - App::instance().engine()->set_property(_object->path(), - App::instance().uris().ingen_polyphonic, + _app->engine()->set_property(_object->path(), + _app->uris().ingen_polyphonic, bool(_polyphonic_menuitem->get_active())); } void ObjectMenu::property_changed(const URI& predicate, const Atom& value) { - const URIs& uris = App::instance().uris(); + const URIs& uris = _app->uris(); _enable_signal = false; if (predicate == uris.ingen_polyphonic && value.type() == Atom::BOOL) _polyphonic_menuitem->set_active(value.get_bool()); @@ -131,13 +131,13 @@ ObjectMenu::property_changed(const URI& predicate, const Atom& value) void ObjectMenu::on_menu_destroy() { - App::instance().engine()->del(_object->path()); + _app->engine()->del(_object->path()); } void ObjectMenu::on_menu_properties() { - App::instance().window_factory()->present_properties(_object); + _app->window_factory()->present_properties(_object); } } // namespace GUI diff --git a/src/gui/ObjectMenu.hpp b/src/gui/ObjectMenu.hpp index 91743c3a..829db28b 100644 --- a/src/gui/ObjectMenu.hpp +++ b/src/gui/ObjectMenu.hpp @@ -45,7 +45,7 @@ public: ObjectMenu(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& xml); - void init(SharedPtr<const ObjectModel> object); + void init(App& app, SharedPtr<const ObjectModel> object); protected: void on_menu_learn(); @@ -57,6 +57,7 @@ protected: void property_changed(const Raul::URI& predicate, const Raul::Atom& value); + App* _app; SharedPtr<const ObjectModel> _object; Gtk::MenuItem* _learn_menuitem; Gtk::MenuItem* _unlearn_menuitem; diff --git a/src/gui/PatchCanvas.cpp b/src/gui/PatchCanvas.cpp index 191713eb..299336cf 100644 --- a/src/gui/PatchCanvas.cpp +++ b/src/gui/PatchCanvas.cpp @@ -48,7 +48,7 @@ #define LOG(s) s << "[PatchCanvas] " -#define FOREACH_ITEM(iter, coll) \ +#define FOREACH_ITEM(iter, coll) \ for (Items::iterator (iter) = coll.begin(); \ (iter) != coll.end(); ++(iter)) @@ -61,8 +61,12 @@ using namespace Raul; namespace Ingen { namespace GUI { -PatchCanvas::PatchCanvas(SharedPtr<const PatchModel> patch, int width, int height) +PatchCanvas::PatchCanvas(App& app, + SharedPtr<const PatchModel> patch, + int width, + int height) : Canvas(width, height) + , _app(app) , _patch(patch) , _auto_position_count(0) , _last_click_x(0) @@ -92,22 +96,22 @@ PatchCanvas::PatchCanvas(SharedPtr<const PatchModel> patch, int width, int heigh // Add port menu items _menu_add_audio_input->signal_activate().connect( sigc::bind(sigc::mem_fun(this, &PatchCanvas::menu_add_port), - "audio_in", "Audio In", "http://lv2plug.in/ns/lv2core#AudioPort", false)); + "audio_in", "Audio In", "http://lv2plug.in/ns/lv2core#AudioPort", false)); _menu_add_audio_output->signal_activate().connect( sigc::bind(sigc::mem_fun(this, &PatchCanvas::menu_add_port), - "audio_out", "Audio Out", "http://lv2plug.in/ns/lv2core#AudioPort", true)); + "audio_out", "Audio Out", "http://lv2plug.in/ns/lv2core#AudioPort", true)); _menu_add_control_input->signal_activate().connect( sigc::bind(sigc::mem_fun(this, &PatchCanvas::menu_add_port), - "control_in", "Control In", "http://lv2plug.in/ns/lv2core#ControlPort", false)); + "control_in", "Control In", "http://lv2plug.in/ns/lv2core#ControlPort", false)); _menu_add_control_output->signal_activate().connect( sigc::bind(sigc::mem_fun(this, &PatchCanvas::menu_add_port), - "control_out", "Control Out", "http://lv2plug.in/ns/lv2core#ControlPort", true)); + "control_out", "Control Out", "http://lv2plug.in/ns/lv2core#ControlPort", true)); _menu_add_event_input->signal_activate().connect( sigc::bind(sigc::mem_fun(this, &PatchCanvas::menu_add_port), - "event_in", "Event In", "http://lv2plug.in/ns/ext/event#EventPort", false)); + "event_in", "Event In", "http://lv2plug.in/ns/ext/event#EventPort", false)); _menu_add_event_output->signal_activate().connect( sigc::bind(sigc::mem_fun(this, &PatchCanvas::menu_add_port), - "event_out", "Event Out", "http://lv2plug.in/ns/ext/event#EventPort", true)); + "event_out", "Event Out", "http://lv2plug.in/ns/ext/event#EventPort", true)); // Connect to model signals to track state _patch->signal_new_node().connect( @@ -123,7 +127,7 @@ PatchCanvas::PatchCanvas(SharedPtr<const PatchModel> patch, int width, int heigh _patch->signal_removed_connection().connect( sigc::mem_fun(this, &PatchCanvas::disconnection)); - App::instance().store()->signal_new_plugin().connect( + _app.store()->signal_new_plugin().connect( sigc::mem_fun(this, &PatchCanvas::add_plugin)); // Connect widget signals to do things @@ -185,7 +189,7 @@ PatchCanvas::build_menus() } // Add known plugins to menu heirarchy - SharedPtr<const ClientStore::Plugins> plugins = App::instance().store()->plugins(); + SharedPtr<const ClientStore::Plugins> plugins = _app.store()->plugins(); for (ClientStore::Plugins::const_iterator i = plugins->begin(); i != plugins->end(); ++i) add_plugin(i->second); } @@ -206,7 +210,7 @@ PatchCanvas::build_plugin_class_menu( const char* class_uri_str = lilv_node_as_string(class_uri); const std::pair<LV2Children::const_iterator, LV2Children::const_iterator> kids - = children.equal_range(class_uri_str); + = children.equal_range(class_uri_str); if (kids.first == children.end()) return 0; @@ -280,8 +284,8 @@ void PatchCanvas::build() { // Create modules for nodes - for (Store::const_iterator i = App::instance().store()->children_begin(_patch); - i != App::instance().store()->children_end(_patch); ++i) { + for (Store::const_iterator i = _app.store()->children_begin(_patch); + i != _app.store()->children_end(_patch); ++i) { SharedPtr<NodeModel> node = PtrCast<NodeModel>(i->second); if (node && node->parent() == _patch) add_node(node); @@ -289,13 +293,13 @@ PatchCanvas::build() // Create pseudo modules for ports (ports on this canvas, not on our module) for (NodeModel::Ports::const_iterator i = _patch->ports().begin(); - i != _patch->ports().end(); ++i) { + i != _patch->ports().end(); ++i) { add_port(*i); } // Create connections for (PatchModel::Connections::const_iterator i = _patch->connections().begin(); - i != _patch->connections().end(); ++i) { + i != _patch->connections().end(); ++i) { connection(PtrCast<ConnectionModel>(i->second)); } } @@ -332,7 +336,7 @@ PatchCanvas::add_plugin(SharedPtr<PluginModel> p) typedef ClassMenus::iterator iterator; if (_internal_menu && p->type() == Plugin::Internal) { _internal_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(p->human_name(), - sigc::bind(sigc::mem_fun(this, &PatchCanvas::load_plugin), p))); + sigc::bind(sigc::mem_fun(this, &PatchCanvas::load_plugin), p))); } else if (_plugin_menu && p->type() == Plugin::LV2 && p->lilv_plugin()) { if (lilv_plugin_is_replaced(p->lilv_plugin())) { //info << (boost::format("[Menu] LV2 plugin <%s> hidden") % p->uri()) << endl; @@ -343,14 +347,14 @@ PatchCanvas::add_plugin(SharedPtr<PluginModel> p) const LilvNode* class_uri = lilv_plugin_class_get_uri(pc); const char* class_uri_str = lilv_node_as_string(class_uri); - Glib::RefPtr<Gdk::Pixbuf> icon = App::instance().icon_from_path( - PluginModel::get_lv2_icon_path(p->lilv_plugin()), 16); + Glib::RefPtr<Gdk::Pixbuf> icon = _app.icon_from_path( + PluginModel::get_lv2_icon_path(p->lilv_plugin()), 16); pair<iterator,iterator> range = _class_menus.equal_range(class_uri_str); if (range.first == _class_menus.end() || range.first == range.second - || range.first->second.menu == _plugin_menu) { + || range.first->second.menu == _plugin_menu) { _classless_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(p->human_name(), - sigc::bind(sigc::mem_fun(this, &PatchCanvas::load_plugin), p))); + sigc::bind(sigc::mem_fun(this, &PatchCanvas::load_plugin), p))); if (!_classless_menu->is_visible()) _classless_menu->show(); } else { @@ -387,7 +391,7 @@ PatchCanvas::add_node(SharedPtr<const NodeModel> nm) module = NodeModule::create(*this, nm, _human_names); const PluginModel* plugm = dynamic_cast<const PluginModel*>(nm->plugin()); if (plugm && !plugm->icon_path().empty()) - module->set_icon(App::instance().icon_from_path(plugm->icon_path(), 100)); + module->set_icon(_app.icon_from_path(plugm->icon_path(), 100)); } module->show(); @@ -446,7 +450,7 @@ PatchCanvas::get_port_view(SharedPtr<PortModel> port) module = dynamic_cast<NodeModule*>(_views[port->parent()]); if (module) { for (Module::Ports::const_iterator p = module->ports().begin(); - p != module->ports().end(); ++p) { + p != module->ports().end(); ++p) { GUI::Port* pv = dynamic_cast<GUI::Port*>(*p); if (pv && pv->model() == port) return pv; @@ -471,7 +475,7 @@ PatchCanvas::connection(SharedPtr<const ConnectionModel> cm) src->color() + 0x22222200)); } else { LOG(error) << "Unable to find ports to connect " - << cm->src_port_path() << " -> " << cm->dst_port_path() << endl; + << cm->src_port_path() << " -> " << cm->dst_port_path() << endl; } } @@ -485,7 +489,7 @@ PatchCanvas::disconnection(SharedPtr<const ConnectionModel> cm) remove_connection(src, dst); else LOG(error) << "Unable to find ports to disconnect " - << cm->src_port_path() << " -> " << cm->dst_port_path() << endl; + << cm->src_port_path() << " -> " << cm->dst_port_path() << endl; } void @@ -501,7 +505,7 @@ PatchCanvas::connect(FlowCanvas::Connectable* src_port, if (!src || !dst) return; - App::instance().engine()->connect(src->model()->path(), dst->model()->path()); + _app.engine()->connect(src->model()->path(), dst->model()->path()); } void @@ -514,8 +518,8 @@ PatchCanvas::disconnect(FlowCanvas::Connectable* src_port, const Ingen::GUI::Port* const dst = dynamic_cast<Ingen::GUI::Port*>(dst_port); - App::instance().engine()->disconnect(src->model()->path(), - dst->model()->path()); + _app.engine()->disconnect(src->model()->path(), + dst->model()->path()); } void @@ -588,8 +592,7 @@ PatchCanvas::canvas_event(GdkEvent* event) void PatchCanvas::clear_selection() { - const App& app = App::instance(); - PatchWindow* win = app.window_factory()->patch_window(_patch); + PatchWindow* win = _app.window_factory()->patch_window(_patch); if (win) { win->hide_documentation(); } @@ -603,11 +606,11 @@ PatchCanvas::destroy_selection() FOREACH_ITEM(m, selected_items()) { NodeModule* module = dynamic_cast<NodeModule*>(*m); if (module) { - App::instance().engine()->del(module->node()->path()); + _app.engine()->del(module->node()->path()); } else { PatchPortModule* port_module = dynamic_cast<PatchPortModule*>(*m); if (port_module) - App::instance().engine()->del(port_module->port()->path()); + _app.engine()->del(port_module->port()->path()); } } } @@ -626,7 +629,7 @@ void PatchCanvas::copy_selection() { static const char* base_uri = ""; - Serialiser serialiser(*App::instance().world(), App::instance().store()); + Serialiser serialiser(*_app.world(), _app.store()); serialiser.start_to_string(_patch->path(), base_uri); FOREACH_ITEM(m, selected_items()) { @@ -644,7 +647,7 @@ PatchCanvas::copy_selection() c != selected_connections().end(); ++c) { Connection* const connection = dynamic_cast<Connection*>(*c); if (connection) { - const Sord::URI subject(*App::instance().world()->rdf_world(), + const Sord::URI subject(*_app.world()->rdf_world(), base_uri); serialiser.serialise_connection(subject, connection->model()); } @@ -661,7 +664,7 @@ void PatchCanvas::paste() { Glib::ustring str = Gtk::Clipboard::get()->wait_for_text(); - SharedPtr<Parser> parser = App::instance().loader()->parser(); + SharedPtr<Parser> parser = _app.loader()->parser(); if (!parser) { LOG(error) << "Unable to load parser, paste unavailable" << endl; return; @@ -670,11 +673,11 @@ PatchCanvas::paste() clear_selection(); ++_paste_count; - const URIs& uris = App::instance().uris(); + const URIs& uris = _app.uris(); - Builder builder(App::instance().world()->uris(), *App::instance().engine()); - ClientStore clipboard(App::instance().world()->uris()); - clipboard.set_plugins(App::instance().store()->plugins()); + Builder builder(_app.world()->uris(), *_app.engine()); + ClientStore clipboard(_app.world()->uris()); + clipboard.set_plugins(_app.store()->plugins()); // mkdir -p string to_create = _patch->path().chop_scheme().substr(1); @@ -687,7 +690,7 @@ PatchCanvas::paste() clipboard.put(Path(), props); size_t first_slash; while (to_create != "/" && !to_create.empty() - && (first_slash = to_create.find("/")) != string::npos) { + && (first_slash = to_create.find("/")) != string::npos) { created += to_create.substr(0, first_slash); assert(Path::is_valid(created)); clipboard.put(created, props); @@ -704,8 +707,8 @@ PatchCanvas::paste() parent = _patch->path(); } - ClashAvoider avoider(*App::instance().store().get(), clipboard, &clipboard); - parser->parse_string(App::instance().world(), &avoider, str, "", + ClashAvoider avoider(*_app.store().get(), clipboard, &clipboard); + parser->parse_string(_app.world(), &avoider, str, "", parent, symbol); for (Store::iterator i = clipboard.begin(); i != clipboard.end(); ++i) { @@ -733,8 +736,8 @@ PatchCanvas::paste() void PatchCanvas::generate_port_name( - const string& sym_base, string& symbol, - const string& name_base, string& name) + const string& sym_base, string& symbol, + const string& name_base, string& name) { symbol = sym_base; name = name_base; @@ -756,13 +759,13 @@ PatchCanvas::generate_port_name( void PatchCanvas::menu_add_port(const string& sym_base, const string& name_base, - const Raul::URI& type, bool is_output) + const Raul::URI& type, bool is_output) { string sym, name; generate_port_name(sym_base, sym, name_base, name); const Path& path = _patch->path().base() + sym; - const URIs& uris = App::instance().uris(); + const URIs& uris = _app.uris(); Resource::Properties props = get_initial_data(); props.insert(make_pair(uris.rdf_type, @@ -773,7 +776,7 @@ PatchCanvas::menu_add_port(const string& sym_base, const string& name_base, Atom(int32_t(_patch->num_ports())))); props.insert(make_pair(uris.lv2_name, Atom(name.c_str()))); - App::instance().engine()->put(path, props); + _app.engine()->put(path, props); } void @@ -784,21 +787,21 @@ PatchCanvas::load_plugin(WeakPtr<PluginModel> weak_plugin) return; Raul::Symbol symbol = plugin->default_node_symbol(); - unsigned offset = App::instance().store()->child_name_offset(_patch->path(), symbol); + unsigned offset = _app.store()->child_name_offset(_patch->path(), symbol); if (offset != 0) { std::stringstream ss; ss << symbol << "_" << offset; symbol = ss.str(); } - const URIs& uris = App::instance().uris(); + const URIs& uris = _app.uris(); const Path path = _patch->path().child(symbol); // FIXME: polyphony? GraphObject::Properties props = get_initial_data(); props.insert(make_pair(uris.rdf_type, uris.ingen_Node)); props.insert(make_pair(uris.rdf_instanceOf, plugin->uri())); - App::instance().engine()->put(path, props); + _app.engine()->put(path, props); } /** Try to guess a suitable location for a new module. @@ -817,7 +820,7 @@ GraphObject::Properties PatchCanvas::get_initial_data(Resource::Graph ctx) { GraphObject::Properties result; - const URIs& uris = App::instance().uris(); + const URIs& uris = _app.uris(); result.insert(make_pair(uris.ingenui_canvas_x, Resource::Property((float)_last_click_x, ctx))); result.insert(make_pair(uris.ingenui_canvas_y, @@ -828,21 +831,21 @@ PatchCanvas::get_initial_data(Resource::Graph ctx) void PatchCanvas::menu_load_plugin() { - App::instance().window_factory()->present_load_plugin( + _app.window_factory()->present_load_plugin( _patch, get_initial_data()); } void PatchCanvas::menu_load_patch() { - App::instance().window_factory()->present_load_subpatch( + _app.window_factory()->present_load_subpatch( _patch, get_initial_data(Resource::EXTERNAL)); } void PatchCanvas::menu_new_patch() { - App::instance().window_factory()->present_new_subpatch( + _app.window_factory()->present_new_subpatch( _patch, get_initial_data(Resource::EXTERNAL)); } diff --git a/src/gui/PatchCanvas.hpp b/src/gui/PatchCanvas.hpp index 654b2dca..a21a37b8 100644 --- a/src/gui/PatchCanvas.hpp +++ b/src/gui/PatchCanvas.hpp @@ -60,10 +60,15 @@ class NodeModule; class PatchCanvas : public FlowCanvas::Canvas { public: - PatchCanvas(SharedPtr<const PatchModel> patch, int width, int height); + PatchCanvas(App& app, + SharedPtr<const PatchModel> patch, + int width, + int height); virtual ~PatchCanvas() {} + App& app() { return _app; } + void build(); void show_human_names(bool show); void show_port_names(bool show); @@ -132,6 +137,7 @@ private: void disconnect(FlowCanvas::Connectable* src, FlowCanvas::Connectable* dst); + App& _app; SharedPtr<const PatchModel> _patch; typedef std::map<SharedPtr<const ObjectModel>, diff --git a/src/gui/PatchPortModule.cpp b/src/gui/PatchPortModule.cpp index a65d39ac..3a00c344 100644 --- a/src/gui/PatchPortModule.cpp +++ b/src/gui/PatchPortModule.cpp @@ -59,17 +59,23 @@ PatchPortModule::create(PatchCanvas& canvas, bool human) { PatchPortModule* ret = new PatchPortModule(canvas, model); - Port* port = Port::create(*ret, model, human, true); + Port* port = Port::create(canvas.app(), *ret, model, human, true); ret->set_port(port); for (GraphObject::Properties::const_iterator m = model->properties().begin(); - m != model->properties().end(); ++m) + m != model->properties().end(); ++m) ret->property_changed(m->first, m->second); return ret; } +App& +PatchPortModule::app() const +{ + return ((PatchCanvas*)canvas())->app(); +} + bool PatchPortModule::show_menu(GdkEventButton* ev) { @@ -83,7 +89,7 @@ PatchPortModule::store_location() const Atom x(static_cast<float>(property_x())); const Atom y(static_cast<float>(property_y())); - const URIs& uris = App::instance().uris(); + const URIs& uris = app().uris(); const Atom& existing_x = _model->get_property(uris.ingenui_canvas_x); const Atom& existing_y = _model->get_property(uris.ingenui_canvas_y); @@ -97,14 +103,14 @@ PatchPortModule::store_location() Resource::Property(x, Resource::INTERNAL))); add.insert(make_pair(uris.ingenui_canvas_y, Resource::Property(y, Resource::INTERNAL))); - App::instance().engine()->delta(_model->path(), remove, add); + app().engine()->delta(_model->path(), remove, add); } } void PatchPortModule::show_human_names(bool b) { - const URIs& uris = App::instance().uris(); + const URIs& uris = app().uris(); const Atom& name = _model->get_property(uris.lv2_name); if (b && name.type() == Atom::STRING) set_name(name.get_string()); @@ -122,7 +128,7 @@ PatchPortModule::set_name(const std::string& n) void PatchPortModule::property_changed(const URI& key, const Atom& value) { - const URIs& uris = App::instance().uris(); + const URIs& uris = app().uris(); switch (value.type()) { case Atom::FLOAT: if (key == uris.ingenui_canvas_x) { @@ -133,10 +139,10 @@ PatchPortModule::property_changed(const URI& key, const Atom& value) break; case Atom::STRING: if (key == uris.lv2_name - && App::instance().configuration()->name_style() == Configuration::HUMAN) { + && app().configuration()->name_style() == Configuration::HUMAN) { set_name(value.get_string()); } else if (key == uris.lv2_symbol - && App::instance().configuration()->name_style() == Configuration::PATH) { + && app().configuration()->name_style() == Configuration::PATH) { set_name(value.get_string()); } break; @@ -161,9 +167,9 @@ PatchPortModule::set_selected(bool b) { if (b != selected()) { Module::set_selected(b); - if (App::instance().signal()) - App::instance().engine()->set_property(_model->path(), - App::instance().uris().ingen_selected, b); + if (app().signal()) + app().engine()->set_property(_model->path(), + app().uris().ingen_selected, b); } } diff --git a/src/gui/PatchPortModule.hpp b/src/gui/PatchPortModule.hpp index 655e6bfc..c351c1bc 100644 --- a/src/gui/PatchPortModule.hpp +++ b/src/gui/PatchPortModule.hpp @@ -54,6 +54,8 @@ public: SharedPtr<const PortModel> model, bool human); + App& app() const; + virtual void store_location(); void show_human_names(bool b); diff --git a/src/gui/PatchTreeWindow.cpp b/src/gui/PatchTreeWindow.cpp index 0c75dd6a..c728fd2b 100644 --- a/src/gui/PatchTreeWindow.cpp +++ b/src/gui/PatchTreeWindow.cpp @@ -37,6 +37,7 @@ namespace GUI { PatchTreeWindow::PatchTreeWindow(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& xml) : Window(cobject) + , _app(NULL) , _enable_signal(true) { xml->get_widget_derived("patches_treeview", _patches_treeview); @@ -68,8 +69,9 @@ PatchTreeWindow::PatchTreeWindow(BaseObjectType* cobject, } void -PatchTreeWindow::init(ClientStore& store) +PatchTreeWindow::init(App& app, ClientStore& store) { + _app = &app; store.signal_new_object().connect( sigc::mem_fun(this, &PatchTreeWindow::new_object)); } @@ -89,7 +91,7 @@ PatchTreeWindow::add_patch(SharedPtr<PatchModel> pm) Gtk::TreeModel::iterator iter = _patch_treestore->append(); Gtk::TreeModel::Row row = *iter; if (pm->path().is_root()) { - row[_patch_tree_columns.name_col] = App::instance().engine()->uri().str(); + row[_patch_tree_columns.name_col] = _app->engine()->uri().str(); } else { row[_patch_tree_columns.name_col] = pm->symbol().c_str(); } @@ -170,7 +172,7 @@ PatchTreeWindow::event_patch_activated(const Gtk::TreeModel::Path& path, Gtk::Tr Gtk::TreeModel::Row row = *active; SharedPtr<PatchModel> pm = row[_patch_tree_columns.patch_model_col]; - App::instance().window_factory()->present_patch(pm); + _app->window_factory()->present_patch(pm); } void @@ -184,15 +186,15 @@ PatchTreeWindow::event_patch_enabled_toggled(const Glib::ustring& path_str) assert(pm); if (_enable_signal) - App::instance().engine()->set_property(pm->path(), - App::instance().uris().ingen_enabled, (bool)!pm->enabled()); + _app->engine()->set_property(pm->path(), + _app->uris().ingen_enabled, (bool)!pm->enabled()); } void PatchTreeWindow::patch_property_changed(const URI& key, const Atom& value, SharedPtr<PatchModel> patch) { - const URIs& uris = App::instance().uris(); + const URIs& uris = _app->uris(); _enable_signal = false; if (key == uris.ingen_enabled && value.type() == Atom::BOOL) { Gtk::TreeModel::iterator i = find_patch(_patch_treestore->children(), patch); diff --git a/src/gui/PatchTreeWindow.hpp b/src/gui/PatchTreeWindow.hpp index 861913c2..1bc94030 100644 --- a/src/gui/PatchTreeWindow.hpp +++ b/src/gui/PatchTreeWindow.hpp @@ -43,7 +43,7 @@ public: PatchTreeWindow(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& xml); - void init(Client::ClientStore& store); + void init(App& app, Client::ClientStore& store); void new_object(SharedPtr<Client::ObjectModel> object); @@ -76,10 +76,11 @@ protected: Gtk::TreeModelColumn<SharedPtr<Client::PatchModel> > patch_model_col; }; - bool _enable_signal; + App* _app; PatchTreeModelColumns _patch_tree_columns; Glib::RefPtr<Gtk::TreeStore> _patch_treestore; Glib::RefPtr<Gtk::TreeSelection> _patch_tree_selection; + bool _enable_signal; }; /** Derived TreeView class to support context menus for patches */ diff --git a/src/gui/PatchView.cpp b/src/gui/PatchView.cpp index 5ba23b85..e3741e52 100644 --- a/src/gui/PatchView.cpp +++ b/src/gui/PatchView.cpp @@ -39,6 +39,7 @@ namespace GUI { PatchView::PatchView(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& xml) : Gtk::Box(cobject) + , _app(NULL) , _breadcrumb_container(NULL) , _enable_signal(true) { @@ -58,7 +59,12 @@ PatchView::PatchView(BaseObjectType* cobject, _toolbar->set_toolbar_style(Gtk::TOOLBAR_ICONS); _canvas_scrolledwindow->property_hadjustment().get_value()->set_step_increment(10); _canvas_scrolledwindow->property_vadjustment().get_value()->set_step_increment(10); +} +void +PatchView::init(App& app) +{ + _app = &app; } void @@ -69,7 +75,7 @@ PatchView::set_patch(SharedPtr<const PatchModel> patch) assert(_breadcrumb_container); // ensure created _patch = patch; - _canvas = SharedPtr<PatchCanvas>(new PatchCanvas(patch, 1600*2, 1200*2)); + _canvas = SharedPtr<PatchCanvas>(new PatchCanvas(*_app, patch, 1600*2, 1200*2)); _canvas->build(); _canvas_scrolledwindow->add(*_canvas); @@ -115,12 +121,12 @@ PatchView::set_patch(SharedPtr<const PatchModel> patch) } SharedPtr<PatchView> -PatchView::create(SharedPtr<const PatchModel> patch) +PatchView::create(App& app, SharedPtr<const PatchModel> patch) { PatchView* result = NULL; Glib::RefPtr<Gtk::Builder> xml = WidgetFactory::create("warehouse_win"); xml->get_widget_derived("patch_view_box", result); - assert(result); + result->init(app); result->set_patch(patch); return SharedPtr<PatchView>(result); } @@ -178,30 +184,30 @@ PatchView::process_toggled() if (!_enable_signal) return; - App::instance().engine()->set_property(_patch->path(), - App::instance().uris().ingen_enabled, + _app->engine()->set_property(_patch->path(), + _app->uris().ingen_enabled, (bool)_process_but->get_active()); } void PatchView::poly_changed() { - App::instance().engine()->set_property(_patch->path(), - App::instance().uris().ingen_polyphony, + _app->engine()->set_property(_patch->path(), + _app->uris().ingen_polyphony, _poly_spin->get_value_as_int()); } void PatchView::refresh_clicked() { - App::instance().engine()->get(_patch->path()); + _app->engine()->get(_patch->path()); } void PatchView::property_changed(const Raul::URI& predicate, const Raul::Atom& value) { _enable_signal = false; - if (predicate == App::instance().uris().ingen_enabled) { + if (predicate == _app->uris().ingen_enabled) { if (value.type() == Atom::BOOL) _process_but->set_active(value.get_bool()); else diff --git a/src/gui/PatchView.hpp b/src/gui/PatchView.hpp index 0d3e0fab..52d33331 100644 --- a/src/gui/PatchView.hpp +++ b/src/gui/PatchView.hpp @@ -57,13 +57,15 @@ public: PatchView(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& xml); + void init(App& app); + SharedPtr<PatchCanvas> canvas() const { return _canvas; } SharedPtr<const PatchModel> patch() const { return _patch; } Gtk::ToolItem* breadcrumb_container() const { return _breadcrumb_container; } void set_editable(bool editable); - static SharedPtr<PatchView> create(SharedPtr<const PatchModel> patch); + static SharedPtr<PatchView> create(App& app, SharedPtr<const PatchModel> patch); sigc::signal<void, const ObjectModel*> signal_object_entered; sigc::signal<void, const ObjectModel*> signal_object_left; @@ -85,20 +87,21 @@ private: void zoom_full(); + App* _app; + SharedPtr<const PatchModel> _patch; SharedPtr<PatchCanvas> _canvas; - Gtk::ScrolledWindow* _canvas_scrolledwindow; - - Gtk::Toolbar* _toolbar; - Gtk::ToggleToolButton* _process_but; - Gtk::SpinButton* _poly_spin; - Gtk::ToolButton* _refresh_but; - Gtk::ToolButton* _save_but; - Gtk::ToolButton* _zoom_normal_but; - Gtk::ToolButton* _zoom_full_but; - Gtk::ToggleToolButton* _edit_mode_but; - Gtk::ToolItem* _breadcrumb_container; + Gtk::ScrolledWindow* _canvas_scrolledwindow; + Gtk::Toolbar* _toolbar; + Gtk::ToggleToolButton* _process_but; + Gtk::SpinButton* _poly_spin; + Gtk::ToolButton* _refresh_but; + Gtk::ToolButton* _save_but; + Gtk::ToolButton* _zoom_normal_but; + Gtk::ToolButton* _zoom_full_but; + Gtk::ToggleToolButton* _edit_mode_but; + Gtk::ToolItem* _breadcrumb_container; bool _enable_signal; }; diff --git a/src/gui/PatchWindow.cpp b/src/gui/PatchWindow.cpp index 05f5fcc9..c95f4fea 100644 --- a/src/gui/PatchWindow.cpp +++ b/src/gui/PatchWindow.cpp @@ -109,11 +109,6 @@ PatchWindow::PatchWindow(BaseObjectType* cobject, xml->get_widget("patch_documentation_scrolledwindow", _doc_scrolledwindow); _menu_view_control_window->property_sensitive() = false; - string engine_name = App::instance().engine()->uri().str(); - if (engine_name == "http://drobilla.net/ns/ingen#internal") - engine_name = "internal engine"; - _status_bar->push(string("Connected to ") + engine_name, STATUS_CONTEXT_ENGINE); - _menu_import->signal_activate().connect( sigc::mem_fun(this, &PatchWindow::event_import)); _menu_import_location->signal_activate().connect( @@ -164,17 +159,6 @@ PatchWindow::PatchWindow(BaseObjectType* cobject, sigc::mem_fun(this, &PatchWindow::event_show_controls)); _menu_view_patch_properties->signal_activate().connect( sigc::mem_fun(this, &PatchWindow::event_show_properties)); - _menu_view_messages_window->signal_activate().connect( - sigc::mem_fun<void>(App::instance().messages_dialog(), &MessagesWindow::present)); - _menu_view_patch_tree_window->signal_activate().connect( - sigc::mem_fun<void>(App::instance().patch_tree(), &PatchTreeWindow::present)); - - _menu_help_about->signal_activate().connect(sigc::hide_return( - sigc::mem_fun(App::instance(), &App::show_about))); - - _breadcrumbs = new BreadCrumbs(); - _breadcrumbs->signal_patch_selected.connect( - sigc::mem_fun(this, &PatchWindow::set_patch_from_path)); #ifndef HAVE_CURL _menu_upload->hide(); @@ -190,6 +174,30 @@ PatchWindow::~PatchWindow() delete _breadcrumbs; } +void +PatchWindow::init_window(App& app) +{ + Window::init_window(app); + + string engine_name = _app->engine()->uri().str(); + if (engine_name == "http://drobilla.net/ns/ingen#internal") { + engine_name = "internal engine"; + } + _status_bar->push(string("Connected to ") + engine_name, STATUS_CONTEXT_ENGINE); + + _menu_view_messages_window->signal_activate().connect( + sigc::mem_fun<void>(_app->messages_dialog(), &MessagesWindow::present)); + _menu_view_patch_tree_window->signal_activate().connect( + sigc::mem_fun<void>(_app->patch_tree(), &PatchTreeWindow::present)); + + _menu_help_about->signal_activate().connect(sigc::hide_return( + sigc::mem_fun(_app, &App::show_about))); + + _breadcrumbs = new BreadCrumbs(*_app); + _breadcrumbs->signal_patch_selected.connect( + sigc::mem_fun(this, &PatchWindow::set_patch_from_path)); +} + /** Set the patch controller from a Path (for use by eg. BreadCrumbs) */ void @@ -197,12 +205,12 @@ PatchWindow::set_patch_from_path(const Path& path, SharedPtr<PatchView> view) { if (view) { assert(view->patch()->path() == path); - App::instance().window_factory()->present_patch(view->patch(), this, view); + _app->window_factory()->present_patch(view->patch(), this, view); } else { SharedPtr<const PatchModel> model = PtrCast<const PatchModel>( - App::instance().store()->object(path)); + _app->store()->object(path)); if (model) - App::instance().window_factory()->present_patch(model, this); + _app->window_factory()->present_patch(model, this); } } @@ -234,7 +242,7 @@ PatchWindow::set_patch(SharedPtr<const PatchModel> patch, _view = _breadcrumbs->view(patch->path()); if (!_view) - _view = PatchView::create(patch); + _view = PatchView::create(*_app, patch); assert(_view); @@ -259,7 +267,7 @@ PatchWindow::set_patch(SharedPtr<const PatchModel> patch, for (NodeModel::Ports::const_iterator p = patch->ports().begin(); p != patch->ports().end(); ++p) { - if (App::instance().can_control(p->get())) { + if (_app->can_control(p->get())) { _menu_view_control_window->property_sensitive() = true; break; } @@ -288,7 +296,7 @@ PatchWindow::set_patch(SharedPtr<const PatchModel> patch, void PatchWindow::patch_port_added(SharedPtr<const PortModel> port) { - if (port->is_input() && App::instance().can_control(port.get())) { + if (port->is_input() && _app->can_control(port.get())) { _menu_view_control_window->property_sensitive() = true; } } @@ -296,12 +304,12 @@ PatchWindow::patch_port_added(SharedPtr<const PortModel> port) void PatchWindow::patch_port_removed(SharedPtr<const PortModel> port) { - if (!(port->is_input() && App::instance().can_control(port.get()))) + if (!(port->is_input() && _app->can_control(port.get()))) return; for (NodeModel::Ports::const_iterator i = _patch->ports().begin(); i != _patch->ports().end(); ++i) { - if ((*i)->is_input() && App::instance().can_control(i->get())) { + if ((*i)->is_input() && _app->can_control(i->get())) { _menu_view_control_window->property_sensitive() = true; return; } @@ -406,7 +414,7 @@ void PatchWindow::event_show_engine() { if (_patch) - App::instance().connect_window()->show(); + _app->connect_window()->show(); } void @@ -419,35 +427,35 @@ PatchWindow::event_clipboard_changed(GdkEventOwnerChange* ev) void PatchWindow::event_show_controls() { - App::instance().window_factory()->present_controls(_patch); + _app->window_factory()->present_controls(_patch); } void PatchWindow::event_show_properties() { - App::instance().window_factory()->present_properties(_patch); + _app->window_factory()->present_properties(_patch); } void PatchWindow::event_import() { - App::instance().window_factory()->present_load_patch(_patch); + _app->window_factory()->present_load_patch(_patch); } void PatchWindow::event_import_location() { - App::instance().window_factory()->present_load_remote_patch(_patch); + _app->window_factory()->present_load_remote_patch(_patch); } void PatchWindow::event_save() { - const Raul::Atom& document = _patch->get_property(App::instance().uris().ingen_document); + const Raul::Atom& document = _patch->get_property(_app->uris().ingen_document); if (!document.is_valid() || document.type() != Raul::Atom::URI) { event_save_as(); } else { - App::instance().loader()->save_patch(_patch, document.get_uri()); + _app->loader()->save_patch(_patch, document.get_uri()); _status_bar->push( (boost::format("Saved %1% to %2%") % _patch->path().chop_scheme() % document.get_uri()).str(), @@ -458,7 +466,7 @@ PatchWindow::event_save() void PatchWindow::event_save_as() { - const Shared::URIs& uris = App::instance().uris(); + const Shared::URIs& uris = _app->uris(); while (true) { Gtk::FileChooserDialog dialog(*this, "Save Patch", Gtk::FILE_CHOOSER_ACTION_SAVE); @@ -475,8 +483,8 @@ PatchWindow::event_save_as() const Raul::Atom& document = _patch->get_property(uris.ingen_document); if (document.type() == Raul::Atom::URI) dialog.set_uri(document.get_uri()); - else if (App::instance().configuration()->patch_folder().length() > 0) - dialog.set_current_folder(App::instance().configuration()->patch_folder()); + else if (_app->configuration()->patch_folder().length() > 0) + dialog.set_current_folder(_app->configuration()->patch_folder()); if (dialog.run() != Gtk::RESPONSE_OK) break; @@ -539,7 +547,7 @@ more files and/or directories, recursively. Existing files will be overwritten. if (confirm) { const Glib::ustring uri = Glib::filename_to_uri(filename); - App::instance().loader()->save_patch(_patch, uri); + _app->loader()->save_patch(_patch, uri); const_cast<PatchModel*>(_patch.get())->set_property( uris.ingen_document, Atom(Atom::URI, uri.c_str()), Resource::EXTERNAL); _status_bar->push( @@ -548,7 +556,7 @@ more files and/or directories, recursively. Existing files will be overwritten. STATUS_CONTEXT_PATCH); } - App::instance().configuration()->set_patch_folder(dialog.get_current_folder()); + _app->configuration()->set_patch_folder(dialog.get_current_folder()); break; } } @@ -556,7 +564,7 @@ more files and/or directories, recursively. Existing files will be overwritten. void PatchWindow::event_upload() { - App::instance().window_factory()->present_upload_patch(_patch); + _app->window_factory()->present_upload_patch(_patch); } void @@ -659,13 +667,13 @@ PatchWindow::on_event(GdkEvent* event) void PatchWindow::event_close() { - App::instance().window_factory()->remove_patch_window(this); + _app->window_factory()->remove_patch_window(this); } void PatchWindow::event_quit() { - App::instance().quit(*this); + _app->quit(*this); } void @@ -721,9 +729,9 @@ PatchWindow::event_human_names_toggled() { _view->canvas()->show_human_names(_menu_human_names->get_active()); if (_menu_human_names->get_active()) - App::instance().configuration()->set_name_style(Configuration::HUMAN); + _app->configuration()->set_name_style(Configuration::HUMAN); else - App::instance().configuration()->set_name_style(Configuration::PATH); + _app->configuration()->set_name_style(Configuration::PATH); } void diff --git a/src/gui/PatchWindow.hpp b/src/gui/PatchWindow.hpp index fb58e337..63f70cd7 100644 --- a/src/gui/PatchWindow.hpp +++ b/src/gui/PatchWindow.hpp @@ -57,6 +57,7 @@ public: const Glib::RefPtr<Gtk::Builder>& xml); ~PatchWindow(); + void init_window(App& app); void set_patch_from_path(const Raul::Path& path, SharedPtr<PatchView> view); void set_patch(SharedPtr<const PatchModel> pc, SharedPtr<PatchView> view); diff --git a/src/gui/Port.cpp b/src/gui/Port.cpp index 25a1972b..abe22507 100644 --- a/src/gui/Port.cpp +++ b/src/gui/Port.cpp @@ -41,14 +41,15 @@ namespace GUI { ArtVpathDash* Port::_dash; Port* -Port::create(FlowCanvas::Module& module, +Port::create(App& app, + FlowCanvas::Module& module, SharedPtr<const PortModel> pm, bool human_name, bool flip) { Glib::ustring label(human_name ? "" : pm->path().symbol()); if (human_name) { - const Raul::Atom& name = pm->get_property(App::instance().uris().lv2_name); + const Raul::Atom& name = pm->get_property(app.uris().lv2_name); if (name.type() == Raul::Atom::STRING) { label = name.get_string(); } else { @@ -57,18 +58,20 @@ Port::create(FlowCanvas::Module& module, label = parent->plugin_model()->port_human_name(pm->index()); } } - return new Port(module, pm, label, flip); + return new Port(app, module, pm, label, flip); } /** @a flip Make an input port appear as an output port, and vice versa. */ -Port::Port(FlowCanvas::Module& module, +Port::Port(App& app, + FlowCanvas::Module& module, SharedPtr<const PortModel> pm, const string& name, bool flip) : FlowCanvas::Port(module, name, flip ? (!pm->is_input()) : pm->is_input(), - App::instance().configuration()->get_port_color(pm.get())) + app.configuration()->get_port_color(pm.get())) + , _app(app) , _port_model(pm) , _pressed(false) , _flipped(flip) @@ -81,7 +84,7 @@ Port::Port(FlowCanvas::Module& module, pm->signal_moved().connect(sigc::mem_fun(this, &Port::moved)); - if (App::instance().can_control(pm.get())) { + if (app.can_control(pm.get())) { set_toggled(pm->is_toggle()); show_control(); pm->signal_property().connect( @@ -99,19 +102,19 @@ Port::Port(FlowCanvas::Module& module, Port::~Port() { - App::instance().activity_port_destroyed(this); + _app.activity_port_destroyed(this); } void Port::update_metadata() { SharedPtr<const PortModel> pm = _port_model.lock(); - if (App::instance().can_control(pm.get()) && pm->is_numeric()) { + if (_app.can_control(pm.get()) && pm->is_numeric()) { boost::shared_ptr<const NodeModel> parent = PtrCast<const NodeModel>(pm->parent()); if (parent) { float min = 0.0f; float max = 1.0f; - parent->port_value_range(pm, min, max, App::instance().sample_rate()); + parent->port_value_range(pm, min, max, _app.sample_rate()); set_control_min(min); set_control_max(max); } @@ -123,7 +126,7 @@ Port::show_menu(GdkEventButton* ev) { PortMenu* menu = NULL; WidgetFactory::get_widget_derived("object_menu", menu); - menu->init(model(), _flipped); + menu->init(_app, model(), _flipped); menu->popup(ev->button, ev->time); return true; } @@ -131,7 +134,7 @@ Port::show_menu(GdkEventButton* ev) void Port::moved() { - if (App::instance().configuration()->name_style() == Configuration::PATH) + if (_app.configuration()->name_style() == Configuration::PATH) set_name(model()->symbol().c_str()); } @@ -214,10 +217,10 @@ peak_color(float peak) void Port::activity(const Raul::Atom& value) { - if (model()->is_a(App::instance().uris().lv2_AudioPort)) { + if (model()->is_a(_app.uris().lv2_AudioPort)) { set_fill_color(peak_color(value.get_float())); } else { - App::instance().port_activity(this); + _app.port_activity(this); } } @@ -225,14 +228,13 @@ void Port::set_control(float value, bool signal) { if (signal) { - App& app = App::instance(); - Ingen::Shared::World* const world = app.world(); - app.engine()->set_property(model()->path(), + Ingen::Shared::World* const world = _app.world(); + _app.engine()->set_property(model()->path(), world->uris()->ingen_value, Atom(value)); - PatchWindow* pw = app.window_factory()->patch_window( + PatchWindow* pw = _app.window_factory()->patch_window( PtrCast<const PatchModel>(model()->parent())); if (!pw) - pw = app.window_factory()->patch_window( + pw = _app.window_factory()->patch_window( PtrCast<const PatchModel>(model()->parent()->parent())); if (pw) pw->show_port_status(model().get(), value); @@ -244,19 +246,19 @@ Port::set_control(float value, bool signal) void Port::property_changed(const URI& key, const Atom& value) { - const URIs& uris = App::instance().uris(); + const URIs& uris = _app.uris(); if (value.type() == Atom::FLOAT) { float val = value.get_float(); if (key == uris.ingen_value && !_pressed) { set_control(val, false); } else if (key == uris.lv2_minimum) { if (model()->port_property(uris.lv2_sampleRate)) { - val *= App::instance().sample_rate(); + val *= _app.sample_rate(); } set_control_min(val); } else if (key == uris.lv2_maximum) { if (model()->port_property(uris.lv2_sampleRate)) { - val *= App::instance().sample_rate(); + val *= _app.sample_rate(); } set_control_max(val); } @@ -269,7 +271,7 @@ Port::property_changed(const URI& key, const Atom& value) set_border_width(dash ? 2.0 : 0.0); } else if (key == uris.lv2_name) { if (value.type() == Atom::STRING - && App::instance().configuration()->name_style() == Configuration::HUMAN) { + && _app.configuration()->name_style() == Configuration::HUMAN) { set_name(value.get_string()); } } @@ -278,7 +280,7 @@ Port::property_changed(const URI& key, const Atom& value) ArtVpathDash* Port::dash() { - const URIs& uris = App::instance().uris(); + const URIs& uris = _app.uris(); SharedPtr<const PortModel> pm = _port_model.lock(); if (!pm) return NULL; @@ -304,9 +306,8 @@ Port::set_selected(bool b) FlowCanvas::Port::set_selected(b); SharedPtr<const PortModel> pm = _port_model.lock(); if (pm && b) { - const App& app = App::instance(); SharedPtr<const NodeModel> node = PtrCast<NodeModel>(pm->parent()); - PatchWindow* win = app.window_factory()->parent_patch_window(node); + PatchWindow* win = _app.window_factory()->parent_patch_window(node); if (win && node->plugin_model()) { const std::string& doc = node->plugin_model()->port_documentation( pm->index()); diff --git a/src/gui/Port.hpp b/src/gui/Port.hpp index 788baa0e..f1c4b80a 100644 --- a/src/gui/Port.hpp +++ b/src/gui/Port.hpp @@ -33,6 +33,8 @@ using Ingen::Client::PortModel; namespace GUI { +class App; + /** A Port on an Module. * * \ingroup GUI @@ -41,6 +43,7 @@ class Port : public FlowCanvas::Port { public: static Port* create( + App& app, FlowCanvas::Module& module, SharedPtr<const PortModel> pm, bool human_name, @@ -62,10 +65,11 @@ public: ArtVpathDash* dash(); private: - Port(FlowCanvas::Module& module, + Port(App& app, + FlowCanvas::Module& module, SharedPtr<const PortModel> pm, const std::string& name, - bool flip=false); + bool flip = false); void property_changed(const Raul::URI& key, const Raul::Atom& value); @@ -74,9 +78,10 @@ private: static ArtVpathDash* _dash; + App& _app; WeakPtr<const PortModel> _port_model; - bool _pressed; - bool _flipped; + bool _pressed : 1; + bool _flipped : 1; }; } // namespace GUI diff --git a/src/gui/PortMenu.cpp b/src/gui/PortMenu.cpp index 2c727d31..a2dc57de 100644 --- a/src/gui/PortMenu.cpp +++ b/src/gui/PortMenu.cpp @@ -41,11 +41,11 @@ PortMenu::PortMenu(BaseObjectType* cobject, } void -PortMenu::init(SharedPtr<const PortModel> port, bool patch_port) +PortMenu::init(App& app, SharedPtr<const PortModel> port, bool patch_port) { - const URIs& uris = App::instance().uris(); + const URIs& uris = app.uris(); - ObjectMenu::init(port); + ObjectMenu::init(app, port); _patch_port = patch_port; _set_min_menuitem->signal_activate().connect(sigc::mem_fun(this, @@ -66,7 +66,7 @@ PortMenu::init(SharedPtr<const PortModel> port, bool patch_port) if (port->is_a(uris.ev_EventPort)) _polyphonic_menuitem->hide(); - const bool is_control = App::instance().can_control(port.get()) + const bool is_control = app.can_control(port.get()) && port->is_numeric(); _reset_range_menuitem->set_sensitive(is_control); @@ -85,10 +85,10 @@ void PortMenu::on_menu_disconnect() { if (_patch_port) { - App::instance().engine()->disconnect_all( + _app->engine()->disconnect_all( _object->parent()->path(), _object->path()); } else { - App::instance().engine()->disconnect_all( + _app->engine()->disconnect_all( _object->parent()->path().parent(), _object->path()); } } @@ -96,27 +96,27 @@ PortMenu::on_menu_disconnect() void PortMenu::on_menu_set_min() { - const URIs& uris = App::instance().uris(); + const URIs& uris = _app->uris(); SharedPtr<const PortModel> model = PtrCast<const PortModel>(_object); const Raul::Atom& value = model->get_property(uris.ingen_value); if (value.is_valid()) - App::instance().engine()->set_property(_object->path(), uris.lv2_minimum, value); + _app->engine()->set_property(_object->path(), uris.lv2_minimum, value); } void PortMenu::on_menu_set_max() { - const URIs& uris = App::instance().uris(); + const URIs& uris = _app->uris(); SharedPtr<const PortModel> model = PtrCast<const PortModel>(_object); const Raul::Atom& value = model->get_property(uris.ingen_value); if (value.is_valid()) - App::instance().engine()->set_property(_object->path(), uris.lv2_maximum, value); + _app->engine()->set_property(_object->path(), uris.lv2_maximum, value); } void PortMenu::on_menu_reset_range() { - const URIs& uris = App::instance().uris(); + const URIs& uris = _app->uris(); SharedPtr<const PortModel> model = PtrCast<const PortModel>(_object); SharedPtr<const NodeModel> parent = PtrCast<const NodeModel>(_object->parent()); @@ -124,10 +124,10 @@ PortMenu::on_menu_reset_range() parent->default_port_value_range(model, min, max); if (!std::isnan(min)) - App::instance().engine()->set_property(_object->path(), uris.lv2_minimum, min); + _app->engine()->set_property(_object->path(), uris.lv2_minimum, min); if (!std::isnan(max)) - App::instance().engine()->set_property(_object->path(), uris.lv2_maximum, max); + _app->engine()->set_property(_object->path(), uris.lv2_maximum, max); } } // namespace GUI diff --git a/src/gui/PortMenu.hpp b/src/gui/PortMenu.hpp index 5efb8e2a..b38e7a2b 100644 --- a/src/gui/PortMenu.hpp +++ b/src/gui/PortMenu.hpp @@ -39,7 +39,9 @@ public: PortMenu(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& xml); - void init(SharedPtr<const PortModel> port, bool patch_port=false); + void init(App& app, + SharedPtr<const PortModel> port, + bool patch_port=false); private: void on_menu_disconnect(); diff --git a/src/gui/PortPropertiesWindow.cpp b/src/gui/PortPropertiesWindow.cpp index ca962300..cca61ecd 100644 --- a/src/gui/PortPropertiesWindow.cpp +++ b/src/gui/PortPropertiesWindow.cpp @@ -71,7 +71,7 @@ PortPropertiesWindow::present(SharedPtr<const PortModel> pm) boost::shared_ptr<NodeModel> parent = PtrCast<NodeModel>(_port_model->parent()); if (parent) parent->port_value_range(_port_model, min, max, - App::instance().sample_rate()); + _app->sample_rate()); _initial_min = min; _initial_max = max; @@ -96,7 +96,7 @@ PortPropertiesWindow::present(SharedPtr<const PortModel> pm) void PortPropertiesWindow::property_changed(const URI& key, const Atom& value) { - const Shared::URIs& uris = App::instance().uris(); + const Shared::URIs& uris = _app->uris(); if (value.type() == Atom::FLOAT) { if (key == uris.lv2_minimum) @@ -151,11 +151,11 @@ PortPropertiesWindow::cancel() void PortPropertiesWindow::ok() { - const Shared::URIs& uris = App::instance().uris(); + const Shared::URIs& uris = _app->uris(); Resource::Properties props; props.insert(make_pair(uris.lv2_minimum, float(_min_spinner->get_value()))); props.insert(make_pair(uris.lv2_maximum, float(_max_spinner->get_value()))); - App::instance().engine()->put(_port_model->path(), props); + _app->engine()->put(_port_model->path(), props); hide(); } diff --git a/src/gui/PropertiesWindow.cpp b/src/gui/PropertiesWindow.cpp index 1f6a2ca7..6e4841d0 100644 --- a/src/gui/PropertiesWindow.cpp +++ b/src/gui/PropertiesWindow.cpp @@ -93,7 +93,7 @@ PropertiesWindow::set_object(SharedPtr<const ObjectModel> model) set_title(model->path().chop_scheme() + " Properties - Ingen"); - Shared::World* world = App::instance().world(); + Shared::World* world = _app->world(); ostringstream ss; unsigned n_rows = 0; @@ -296,7 +296,7 @@ PropertiesWindow::apply_clicked() } } - App::instance().engine()->put(_model->path(), properties); + _app->engine()->put(_model->path(), properties); LOG(debug) << "}" << endl; } diff --git a/src/gui/RenameWindow.cpp b/src/gui/RenameWindow.cpp index e62eb101..7e5d8ed2 100644 --- a/src/gui/RenameWindow.cpp +++ b/src/gui/RenameWindow.cpp @@ -87,7 +87,7 @@ RenameWindow::values_changed() } else if (!Path::is_valid_name(symbol)) { _message_label->set_text("Symbol contains invalid characters"); _ok_button->property_sensitive() = false; - } else if (App::instance().store()->object(_object->parent()->path().child(symbol))) { + } else if (_app->store()->object(_object->parent()->path().child(symbol))) { _message_label->set_text("An object already exists with that path"); _ok_button->property_sensitive() = false; } else if (label.empty()) { @@ -115,7 +115,7 @@ RenameWindow::cancel_clicked() void RenameWindow::ok_clicked() { - const Shared::URIs& uris = App::instance().uris(); + const Shared::URIs& uris = _app->uris(); const string& symbol_str = _symbol_entry->get_text(); const string& label = _label_entry->get_text(); @@ -126,12 +126,12 @@ RenameWindow::ok_clicked() const Symbol& symbol(symbol_str); if (symbol != _object->symbol()) { path = _object->path().parent().child(symbol); - App::instance().engine()->move(_object->path(), path); + _app->engine()->move(_object->path(), path); } } if (!label.empty() && (!name_atom.is_valid() || label != name_atom.get_string())) { - App::instance().engine()->set_property(path, uris.lv2_name, Atom(label)); + _app->engine()->set_property(path, uris.lv2_name, Atom(label)); } hide(); diff --git a/src/gui/SubpatchModule.cpp b/src/gui/SubpatchModule.cpp index 777ea11f..72bcd8af 100644 --- a/src/gui/SubpatchModule.cpp +++ b/src/gui/SubpatchModule.cpp @@ -55,9 +55,9 @@ SubpatchModule::on_double_click(GdkEventButton* event) PatchWindow* const preferred = ( (parent && (event->state & GDK_SHIFT_MASK)) ? NULL - : App::instance().window_factory()->patch_window(parent) ); + : app().window_factory()->patch_window(parent) ); - App::instance().window_factory()->present_patch(_patch, preferred); + app().window_factory()->present_patch(_patch, preferred); } void @@ -66,7 +66,7 @@ SubpatchModule::store_location() const Atom x(static_cast<float>(property_x())); const Atom y(static_cast<float>(property_y())); - const URIs& uris = App::instance().uris(); + const URIs& uris = app().uris(); const Atom& existing_x = _node->get_property(uris.ingenui_canvas_x); const Atom& existing_y = _node->get_property(uris.ingenui_canvas_y); @@ -80,7 +80,7 @@ SubpatchModule::store_location() Resource::Property(x, Resource::EXTERNAL))); add.insert(make_pair(uris.ingenui_canvas_y, Resource::Property(y, Resource::EXTERNAL))); - App::instance().engine()->delta(_node->path(), remove, add); + app().engine()->delta(_node->path(), remove, add); } } @@ -95,16 +95,16 @@ SubpatchModule::browse_to_patch() SharedPtr<PatchModel> parent = PtrCast<PatchModel>(_patch->parent()); PatchWindow* const preferred = ( (parent) - ? App::instance().window_factory()->patch_window(parent) + ? app().window_factory()->patch_window(parent) : NULL ); - App::instance().window_factory()->present_patch(_patch, preferred); + app().window_factory()->present_patch(_patch, preferred); } void SubpatchModule::menu_remove() { - App::instance().engine()->del(_patch->path()); + app().engine()->del(_patch->path()); } } // namespace GUI diff --git a/src/gui/ThreadedLoader.cpp b/src/gui/ThreadedLoader.cpp index e3cea135..babc6ee9 100644 --- a/src/gui/ThreadedLoader.cpp +++ b/src/gui/ThreadedLoader.cpp @@ -29,8 +29,9 @@ using namespace Raul; namespace Ingen { namespace GUI { -ThreadedLoader::ThreadedLoader(SharedPtr<ServerInterface> engine) - : _engine(engine) +ThreadedLoader::ThreadedLoader(App& app, SharedPtr<ServerInterface> engine) + : _app(app) + , _engine(engine) { set_name("Loader"); @@ -43,7 +44,7 @@ ThreadedLoader::ThreadedLoader(SharedPtr<ServerInterface> engine) SharedPtr<Parser> ThreadedLoader::parser() { - Ingen::Shared::World* world = App::instance().world(); + Ingen::Shared::World* world = _app.world(); if (!world->parser()) world->load_module("serialisation"); @@ -73,7 +74,7 @@ ThreadedLoader::load_patch(bool merge, { _mutex.lock(); - Ingen::Shared::World* world = App::instance().world(); + Ingen::Shared::World* world = _app.world(); Glib::ustring engine_base = ""; if (engine_parent) { @@ -87,8 +88,8 @@ ThreadedLoader::load_patch(bool merge, sigc::hide_return( sigc::bind(sigc::mem_fun(world->parser().get(), &Ingen::Serialisation::Parser::parse_file), - App::instance().world(), - App::instance().world()->engine().get(), + _app.world(), + _app.world()->engine().get(), document_uri, engine_parent, engine_symbol, @@ -118,11 +119,11 @@ void ThreadedLoader::save_patch_event(SharedPtr<const PatchModel> model, const string& filename) { - if (App::instance().serialiser()) { + if (_app.serialiser()) { if (filename.find(".ingen") != string::npos) - App::instance().serialiser()->write_bundle(model, filename); + _app.serialiser()->write_bundle(model, filename); else - App::instance().serialiser()->to_file(model, filename); + _app.serialiser()->to_file(model, filename); } } diff --git a/src/gui/ThreadedLoader.hpp b/src/gui/ThreadedLoader.hpp index deb8781b..2668a691 100644 --- a/src/gui/ThreadedLoader.hpp +++ b/src/gui/ThreadedLoader.hpp @@ -54,7 +54,8 @@ namespace GUI { class ThreadedLoader : public Raul::Slave { public: - ThreadedLoader(SharedPtr<ServerInterface> engine); + ThreadedLoader(App& app, + SharedPtr<ServerInterface> engine); void load_patch(bool merge, const Glib::ustring& document_uri, @@ -74,10 +75,10 @@ private: void _whipped(); + App& _app; SharedPtr<ServerInterface> _engine; - - Glib::Mutex _mutex; - list<Closure> _events; + Glib::Mutex _mutex; + list<Closure> _events; }; } // namespace GUI diff --git a/src/gui/UploadPatchWindow.cpp b/src/gui/UploadPatchWindow.cpp index d8d204a7..5e47bef9 100644 --- a/src/gui/UploadPatchWindow.cpp +++ b/src/gui/UploadPatchWindow.cpp @@ -69,7 +69,7 @@ UploadPatchWindow::present(SharedPtr<PatchModel> patch) void UploadPatchWindow::on_show() { - const Shared::URIs& uris = App::instance().uris(); + const Shared::URIs& uris = _app->uris(); Gtk::Dialog::on_show(); Raul::Atom atom = _patch->get_property(uris.lv2_symbol); @@ -222,7 +222,7 @@ UploadPatchWindow::upload_clicked() { assert(!_thread); - const Shared::URIs& uris = App::instance().uris(); + const Shared::URIs& uris = _app->uris(); Glib::ustring symbol = _symbol_entry->get_text(); Glib::ustring short_name = _short_name_entry->get_text(); @@ -237,7 +237,7 @@ UploadPatchWindow::upload_clicked() _upload_progress->set_fraction(0.0); _upload_progress->set_text(""); - Serialiser s(*App::instance().world(), App::instance().store()); + Serialiser s(*_app->world(), _app->store()); const string uri = string("http://rdf.drobilla.net/ingen_patches/") .append(symbol).append(INGEN_PATCH_FILE_EXT); diff --git a/src/gui/Window.hpp b/src/gui/Window.hpp index cbe72fbb..372c248e 100644 --- a/src/gui/Window.hpp +++ b/src/gui/Window.hpp @@ -20,16 +20,11 @@ #include <gtkmm.h> -namespace Raul { class Path; } - namespace Ingen { -namespace Client { class ClientStore; } - namespace GUI { -class PatchWindow; -class PatchTreeView; +class App; /** Ingen GUI Window * \ingroup GUI @@ -37,8 +32,10 @@ class PatchTreeView; class Window : public Gtk::Window { public: - Window() : Gtk::Window() {} - Window(BaseObjectType* cobject) : Gtk::Window(cobject) {} + Window() : Gtk::Window(), _app(NULL) {} + Window(BaseObjectType* cobject) : Gtk::Window(cobject), _app(NULL) {} + + virtual void init_window(App& app) { _app = &app; } bool on_key_press_event(GdkEventKey* event) { if (Ingen::GUI::Window::key_press_handler(this, event)) @@ -48,6 +45,8 @@ public: } static bool key_press_handler(Gtk::Window* win, GdkEventKey* event); + + App* _app; }; /** Ingen GUI Dialog @@ -56,8 +55,10 @@ public: class Dialog : public Gtk::Dialog { public: - Dialog() : Gtk::Dialog() {} - Dialog(BaseObjectType* cobject) : Gtk::Dialog(cobject) {} + Dialog() : Gtk::Dialog(), _app(NULL) {} + Dialog(BaseObjectType* cobject) : Gtk::Dialog(cobject), _app(NULL) {} + + virtual void init_dialog(App& app) { _app = &app; } bool on_key_press_event(GdkEventKey* event) { if (Ingen::GUI::Window::key_press_handler(this, event)) @@ -65,6 +66,8 @@ public: else return Gtk::Dialog::on_key_press_event(event); } + + App* _app; }; } // namespace GUI diff --git a/src/gui/WindowFactory.cpp b/src/gui/WindowFactory.cpp index 1bdda4c3..6ea87f84 100644 --- a/src/gui/WindowFactory.cpp +++ b/src/gui/WindowFactory.cpp @@ -39,8 +39,9 @@ using namespace std; namespace Ingen { namespace GUI { -WindowFactory::WindowFactory() - : _load_plugin_win(NULL) +WindowFactory::WindowFactory(App& app) + : _app(app) + , _load_plugin_win(NULL) , _load_patch_win(NULL) , _load_remote_patch_win(NULL) , _upload_patch_win(NULL) @@ -56,7 +57,15 @@ WindowFactory::WindowFactory() #ifdef HAVE_CURL WidgetFactory::get_widget_derived("upload_patch_win", _upload_patch_win); + _upload_patch_win->init_dialog(app); #endif + + _load_plugin_win->init_window(app); + _load_patch_win->init(app); + //_load_remote_patch_win->init(app); + _new_subpatch_win->init_window(app); + _properties_win->init_window(app); + _rename_win->init_window(app); } WindowFactory::~WindowFactory() @@ -169,7 +178,7 @@ WindowFactory::new_patch_window(SharedPtr<const PatchModel> patch, PatchWindow* win = NULL; WidgetFactory::get_widget_derived("patch_win", win); - assert(win); + win->init_window(_app); win->set_patch(patch, view); _patch_windows[patch->path()] = win; @@ -184,7 +193,7 @@ bool WindowFactory::remove_patch_window(PatchWindow* win, GdkEventAny* ignored) { if (_patch_windows.size() <= 1) - return !App::instance().quit(*win); + return !_app.quit(*win); PatchWindowMap::iterator w = _patch_windows.find(win->patch()->path()); @@ -216,7 +225,7 @@ WindowFactory::new_control_window(SharedPtr<const NodeModel> node) if (node->polyphonic() && node->parent()) poly = ((PatchModel*)node->parent().get())->internal_poly(); - NodeControlWindow* win = new NodeControlWindow(node, poly); + NodeControlWindow* win = new NodeControlWindow(_app, node, poly); _control_windows[node->path()] = win; diff --git a/src/gui/WindowFactory.hpp b/src/gui/WindowFactory.hpp index 46445ffb..952c3db7 100644 --- a/src/gui/WindowFactory.hpp +++ b/src/gui/WindowFactory.hpp @@ -19,9 +19,11 @@ #define INGEN_GUI_WINDOWFACTORY_HPP #include <map> + #include <gtkmm.h> -#include "raul/SharedPtr.hpp" + #include "ingen/GraphObject.hpp" +#include "raul/SharedPtr.hpp" using namespace Ingen::Shared; @@ -36,6 +38,7 @@ using Ingen::Client::ObjectModel; namespace GUI { +class App; class LoadPatchWindow; class LoadPluginWindow; class LoadRemotePatchWindow; @@ -55,7 +58,7 @@ class UploadPatchWindow; */ class WindowFactory { public: - WindowFactory(); + WindowFactory(App& app); ~WindowFactory(); size_t num_open_patch_windows(); @@ -96,9 +99,9 @@ private: bool remove_control_window(NodeControlWindow* win, GdkEventAny* ignored); - PatchWindowMap _patch_windows; - ControlWindowMap _control_windows; - + App& _app; + PatchWindowMap _patch_windows; + ControlWindowMap _control_windows; LoadPluginWindow* _load_plugin_win; LoadPatchWindow* _load_patch_win; LoadRemotePatchWindow* _load_remote_patch_win; diff --git a/src/gui/ingen_gui.cpp b/src/gui/ingen_gui.cpp index 2ab86894..4d3ab8f8 100644 --- a/src/gui/ingen_gui.cpp +++ b/src/gui/ingen_gui.cpp @@ -20,11 +20,13 @@ struct IngenGUIModule : public Ingen::Shared::Module { void load(Ingen::Shared::World* world) { - Ingen::GUI::App::init(world); + app = Ingen::GUI::App::create(world); } void run(Ingen::Shared::World* world) { - Ingen::GUI::App::run(); + app->run(); } + + SharedPtr<Ingen::GUI::App> app; }; extern "C" { |