From 449af7b35ac64ed90ef635e7657870f524e12c26 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 14 Feb 2010 20:19:11 +0000 Subject: Fix loading of subpatches. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2450 a436a847-0d15-0410-975c-d299462d15a1 --- src/gui/LoadPatchWindow.cpp | 41 ++-- src/gui/LoadPatchWindow.hpp | 14 +- src/gui/LoadPluginWindow.cpp | 22 ++- src/gui/LoadPluginWindow.hpp | 2 +- src/gui/LoadSubpatchWindow.cpp | 101 +++++----- src/gui/LoadSubpatchWindow.hpp | 13 +- src/gui/WindowFactory.cpp | 2 - src/gui/ingen_gui.glade | 439 ++++++++++++++++++++--------------------- 8 files changed, 332 insertions(+), 302 deletions(-) (limited to 'src/gui') diff --git a/src/gui/LoadPatchWindow.cpp b/src/gui/LoadPatchWindow.cpp index db65968b..bba7c75d 100644 --- a/src/gui/LoadPatchWindow.cpp +++ b/src/gui/LoadPatchWindow.cpp @@ -39,27 +39,30 @@ namespace GUI { LoadPatchWindow::LoadPatchWindow(BaseObjectType* cobject, const Glib::RefPtr& xml) : Gtk::FileChooserDialog(cobject) - , _replace(true) + , _merge_ports(true) { - xml->get_widget("load_patch_poly_from_current_radio", _poly_from_current_radio); + xml->get_widget("load_patch_poly_voices_radio", _poly_voices_radio); xml->get_widget("load_patch_poly_from_file_radio", _poly_from_file_radio); - xml->get_widget("load_patch_poly_from_user_radio", _poly_from_user_radio); xml->get_widget("load_patch_poly_spinbutton", _poly_spinbutton); + xml->get_widget("load_patch_merge_ports_radio", _merge_ports_radio); + xml->get_widget("load_patch_insert_ports_radio", _insert_ports_radio); xml->get_widget("load_patch_ok_button", _ok_button); xml->get_widget("load_patch_cancel_button", _cancel_button); - _poly_from_current_radio->signal_toggled().connect( - sigc::mem_fun(this, &LoadPatchWindow::poly_from_file_selected)); _poly_from_file_radio->signal_toggled().connect( sigc::mem_fun(this, &LoadPatchWindow::poly_from_file_selected)); - _poly_from_user_radio->signal_toggled().connect( - sigc::mem_fun(this, &LoadPatchWindow::poly_from_user_selected)); + _poly_voices_radio->signal_toggled().connect( + sigc::mem_fun(this, &LoadPatchWindow::poly_voices_selected)); + _merge_ports_radio->signal_toggled().connect( + sigc::mem_fun(this, &LoadPatchWindow::merge_ports_selected)); + _insert_ports_radio->signal_toggled().connect( + sigc::mem_fun(this, &LoadPatchWindow::insert_ports_selected)); _ok_button->signal_clicked().connect( sigc::mem_fun(this, &LoadPatchWindow::ok_clicked)); _cancel_button->signal_clicked().connect( sigc::mem_fun(this, &LoadPatchWindow::cancel_clicked)); - _poly_from_current_radio->set_active(true); + _poly_voices_radio->set_active(true); Gtk::FileFilter filt; filt.add_pattern("*.om"); @@ -89,7 +92,7 @@ LoadPatchWindow::present(SharedPtr patch, GraphObject::Properties da } -/** Sets the patch controller for this window and initializes everything. +/** Sets the patch model for this window and initializes everything. * * This function MUST be called before using the window in any way! */ @@ -97,6 +100,7 @@ void LoadPatchWindow::set_patch(SharedPtr patch) { _patch = patch; + _poly_spinbutton->set_value(patch->poly()); } @@ -120,11 +124,24 @@ LoadPatchWindow::poly_from_file_selected() void -LoadPatchWindow::poly_from_user_selected() +LoadPatchWindow::poly_voices_selected() { _poly_spinbutton->property_sensitive() = true; } +void +LoadPatchWindow::merge_ports_selected() +{ + _merge_ports = true; +} + + +void +LoadPatchWindow::insert_ports_selected() +{ + _merge_ports = false; +} + void LoadPatchWindow::ok_clicked() @@ -136,7 +153,7 @@ LoadPatchWindow::ok_clicked() optional parent; optional symbol; - if (_poly_from_user_radio->get_active()) + if (_poly_voices_radio->get_active()) _initial_data.insert(make_pair( App::instance().uris().ingen_polyphony, _poly_spinbutton->get_value_as_int())); @@ -146,6 +163,8 @@ LoadPatchWindow::ok_clicked() symbol = _patch->symbol(); } + cout << "MERGE PORTS: " << _merge_ports << endl; + _patch.reset(); hide(); diff --git a/src/gui/LoadPatchWindow.hpp b/src/gui/LoadPatchWindow.hpp index a3356de6..faae39dd 100644 --- a/src/gui/LoadPatchWindow.hpp +++ b/src/gui/LoadPatchWindow.hpp @@ -52,29 +52,29 @@ public: void set_patch(SharedPtr patch); - void set_replace() { _replace = true; } - void set_merge() { _replace = false; } - void present(SharedPtr patch, GraphObject::Properties data); protected: void on_show(); private: + void poly_voices_selected(); void poly_from_file_selected(); - void poly_from_user_selected(); + void merge_ports_selected(); + void insert_ports_selected(); void ok_clicked(); void cancel_clicked(); GraphObject::Properties _initial_data; SharedPtr _patch; - bool _replace; + bool _merge_ports; - Gtk::RadioButton* _poly_from_current_radio; + Gtk::RadioButton* _poly_voices_radio; Gtk::RadioButton* _poly_from_file_radio; - Gtk::RadioButton* _poly_from_user_radio; Gtk::SpinButton* _poly_spinbutton; + Gtk::RadioButton* _merge_ports_radio; + Gtk::RadioButton* _insert_ports_radio; Gtk::Button* _ok_button; Gtk::Button* _cancel_button; }; diff --git a/src/gui/LoadPluginWindow.cpp b/src/gui/LoadPluginWindow.cpp index 39ed0f3d..ab94b919 100644 --- a/src/gui/LoadPluginWindow.cpp +++ b/src/gui/LoadPluginWindow.cpp @@ -38,7 +38,7 @@ namespace GUI { LoadPluginWindow::LoadPluginWindow(BaseObjectType* cobject, const Glib::RefPtr& xml) : Window(cobject) - , _plugin_name_offset(0) + , _name_offset(0) , _has_shown(false) , _refresh_list(true) { @@ -290,23 +290,27 @@ LoadPluginWindow::plugin_selection_changed() { size_t n_selected = _selection->get_selected_rows().size(); if (n_selected == 0) { - _plugin_name_offset = 0; + _name_offset = 0; _node_name_entry->set_text(""); + _node_name_entry->set_sensitive(false); } else if (n_selected == 1) { Gtk::TreeModel::iterator iter = _plugins_liststore->get_iter( *_selection->get_selected_rows().begin()); if (iter) { Gtk::TreeModel::Row row = *iter; boost::shared_ptr p = row.get_value(_plugins_columns._col_plugin); - _plugin_name_offset = App::instance().store()->child_name_offset( + _name_offset = App::instance().store()->child_name_offset( _patch->path(), p->default_node_symbol()); - _node_name_entry->set_text(generate_module_name(p, _plugin_name_offset)); + _node_name_entry->set_text(generate_module_name(p, _name_offset)); + _node_name_entry->set_sensitive(true); } else { - _plugin_name_offset = 0; + _name_offset = 0; _node_name_entry->set_text(""); + _node_name_entry->set_sensitive(false); } } else { - _node_name_entry->set_text(NAME_ENTRY_MULTI_STRING); + _node_name_entry->set_text(""); + _node_name_entry->set_sensitive(false); } } @@ -338,7 +342,7 @@ LoadPluginWindow::load_plugin(const Gtk::TreeModel::iterator& iter) string name = _node_name_entry->get_text(); if (name.empty() || name == NAME_ENTRY_MULTI_STRING) - name = generate_module_name(plugin, _plugin_name_offset); + name = generate_module_name(plugin, _name_offset); if (name.empty() || !Symbol::is_valid(name)) { Gtk::MessageDialog dialog(*this, @@ -355,7 +359,7 @@ LoadPluginWindow::load_plugin(const Gtk::TreeModel::iterator& iter) App::instance().engine()->put(path, props); if (_selection->get_selected_rows().size() == 1) - _node_name_entry->set_text(generate_module_name(plugin, _plugin_name_offset + 1)); + _node_name_entry->set_text(generate_module_name(plugin, _name_offset + 1)); // Cascade next node Atom& x = _initial_data.find(uris.ingenui_canvas_x)->second; @@ -372,7 +376,7 @@ LoadPluginWindow::add_clicked() _selection->selected_foreach_iter( sigc::mem_fun(*this, &LoadPluginWindow::load_plugin)); - ++_plugin_name_offset; + ++_name_offset; } diff --git a/src/gui/LoadPluginWindow.hpp b/src/gui/LoadPluginWindow.hpp index 71ac3f89..c75c1eb6 100644 --- a/src/gui/LoadPluginWindow.hpp +++ b/src/gui/LoadPluginWindow.hpp @@ -130,7 +130,7 @@ private: Glib::RefPtr _selection; - int _plugin_name_offset; // see comments for generate_plugin_name + int _name_offset; // see comments for generate_plugin_name bool _has_shown; bool _refresh_list; diff --git a/src/gui/LoadSubpatchWindow.cpp b/src/gui/LoadSubpatchWindow.cpp index d299e327..65daa638 100644 --- a/src/gui/LoadSubpatchWindow.cpp +++ b/src/gui/LoadSubpatchWindow.cpp @@ -19,10 +19,12 @@ #include #include #include +#include #include "interface/EngineInterface.hpp" #include "shared/LV2URIMap.hpp" #include "client/NodeModel.hpp" #include "client/PatchModel.hpp" +#include "client/ClientStore.hpp" #include "shared/runtime_paths.hpp" #include "App.hpp" #include "LoadSubpatchWindow.hpp" @@ -41,21 +43,14 @@ namespace GUI { LoadSubpatchWindow::LoadSubpatchWindow(BaseObjectType* cobject, const Glib::RefPtr& xml) : Gtk::FileChooserDialog(cobject) { - xml->get_widget("load_subpatch_name_from_file_radio", _name_from_file_radio); - xml->get_widget("load_subpatch_name_from_user_radio", _name_from_user_radio); - xml->get_widget("load_subpatch_name_entry", _name_entry); + xml->get_widget("load_subpatch_symbol_entry", _symbol_entry); + xml->get_widget("load_subpatch_poly_voices_radio", _poly_voices_radio); xml->get_widget("load_subpatch_poly_from_file_radio", _poly_from_file_radio); - xml->get_widget("load_subpatch_poly_from_parent_radio", _poly_from_parent_radio); - xml->get_widget("load_subpatch_poly_from_user_radio", _poly_from_user_radio); xml->get_widget("load_subpatch_poly_spinbutton", _poly_spinbutton); xml->get_widget("load_subpatch_ok_button", _ok_button); xml->get_widget("load_subpatch_cancel_button", _cancel_button); - _name_from_file_radio->signal_toggled().connect(sigc::mem_fun(this, &LoadSubpatchWindow::disable_name_entry)); - _name_from_user_radio->signal_toggled().connect(sigc::mem_fun(this, &LoadSubpatchWindow::enable_name_entry)); - _poly_from_file_radio->signal_toggled().connect(sigc::mem_fun(this, &LoadSubpatchWindow::disable_poly_spinner)); - _poly_from_parent_radio->signal_toggled().connect(sigc::mem_fun(this, &LoadSubpatchWindow::disable_poly_spinner)); - _poly_from_user_radio->signal_toggled().connect(sigc::mem_fun(this, &LoadSubpatchWindow::enable_poly_spinner)); + _poly_voices_radio->signal_toggled().connect(sigc::mem_fun(this, &LoadSubpatchWindow::enable_poly_spinner)); _ok_button->signal_clicked().connect(sigc::mem_fun(this, &LoadSubpatchWindow::ok_clicked)); _cancel_button->signal_clicked().connect(sigc::mem_fun(this, &LoadSubpatchWindow::cancel_clicked)); @@ -75,6 +70,9 @@ LoadSubpatchWindow::LoadSubpatchWindow(BaseObjectType* cobject, const Glib::RefP add_shortcut_folder(examples_dir); closedir(d); } + + signal_selection_changed().connect( + sigc::mem_fun(this, &LoadSubpatchWindow::selection_changed)); } @@ -87,7 +85,7 @@ LoadSubpatchWindow::present(SharedPtr patch, GraphObject::Properties } -/** Sets the patch controller for this window and initializes everything. +/** Sets the patch model for this window and initializes everything. * * This function MUST be called before using the window in any way! */ @@ -95,12 +93,8 @@ void LoadSubpatchWindow::set_patch(SharedPtr patch) { _patch = patch; - - char temp_buf[4]; - snprintf(temp_buf, 4, "%u", patch->poly()); - Glib::ustring txt = "Same as parent ("; - txt.append(temp_buf).append(")"); - _poly_from_parent_radio->set_label(txt); + _symbol_entry->set_text(patch->path().symbol()); + _poly_spinbutton->set_value(patch->poly()); } @@ -116,21 +110,6 @@ LoadSubpatchWindow::on_show() ///// Event Handlers ////// - -void -LoadSubpatchWindow::disable_name_entry() -{ - _name_entry->property_sensitive() = false; -} - - -void -LoadSubpatchWindow::enable_name_entry() -{ - _name_entry->property_sensitive() = true; -} - - void LoadSubpatchWindow::disable_poly_spinner() { @@ -150,21 +129,10 @@ LoadSubpatchWindow::ok_clicked() { assert(_patch); - // If unset load_patch will load values - optional symbol; - string name_str = ""; - - if (_name_from_user_radio->get_active()) { - name_str = _name_entry->get_text(); - symbol = Symbol::symbolify(name_str); - } - const LV2URIMap& uris = App::instance().uris(); - if (_poly_from_user_radio->get_active()) { + if (_poly_voices_radio->get_active()) { _initial_data.insert(make_pair(uris.ingen_polyphony, (int)_poly_spinbutton->get_value_as_int())); - } else if (_poly_from_parent_radio->get_active()) { - _initial_data.insert(make_pair(uris.ingen_polyphony, (int)_patch->poly())); } std::list uri_list = get_uris(); @@ -175,6 +143,12 @@ LoadSubpatchWindow::ok_clicked() Atom& y = _initial_data.find(uris.ingenui_canvas_y)->second; y = Atom(y.get_float() + 20.0f); + Raul::Symbol symbol(symbol_from_filename(*i)); + if (uri_list.size() == 1 && _symbol_entry->get_text() != "") + symbol = Symbol::symbolify(_symbol_entry->get_text()); + + symbol = avoid_symbol_clash(symbol); + App::instance().loader()->load_patch(false, *i, Path("/"), _patch->path(), symbol, _initial_data); } @@ -190,5 +164,44 @@ LoadSubpatchWindow::cancel_clicked() } +Raul::Symbol +LoadSubpatchWindow::symbol_from_filename(const Glib::ustring& filename) +{ + std::string symbol_str = Glib::path_get_basename(get_filename()); + symbol_str = symbol_str.substr(0, symbol_str.find('.')); + return Raul::Symbol::symbolify(symbol_str); +} + + +Raul::Symbol +LoadSubpatchWindow::avoid_symbol_clash(const Raul::Symbol& symbol) +{ + unsigned offset = App::instance().store()->child_name_offset( + _patch->path(), symbol); + + if (offset != 0) { + std::stringstream ss; + ss << symbol << "_" << offset + 1; + return ss.str(); + } else { + return symbol; + } +} + + +void +LoadSubpatchWindow::selection_changed() +{ + if (get_filenames().size() != 1) { + _symbol_entry->set_text(""); + _symbol_entry->set_sensitive(false); + } else { + _symbol_entry->set_text(avoid_symbol_clash( + symbol_from_filename(get_filename()).c_str()).c_str()); + _symbol_entry->set_sensitive(true); + } +} + + } // namespace GUI } // namespace Ingen diff --git a/src/gui/LoadSubpatchWindow.hpp b/src/gui/LoadSubpatchWindow.hpp index 6f71642b..c216f26a 100644 --- a/src/gui/LoadSubpatchWindow.hpp +++ b/src/gui/LoadSubpatchWindow.hpp @@ -51,24 +51,23 @@ protected: void on_show(); private: - void disable_name_entry(); - void enable_name_entry(); void disable_poly_spinner(); void enable_poly_spinner(); void ok_clicked(); void cancel_clicked(); + void selection_changed(); + + Raul::Symbol symbol_from_filename(const Glib::ustring& filename); + Raul::Symbol avoid_symbol_clash(const Raul::Symbol& symbol); GraphObject::Properties _initial_data; SharedPtr _patch; - Gtk::RadioButton* _name_from_file_radio; - Gtk::RadioButton* _name_from_user_radio; - Gtk::Entry* _name_entry; + Gtk::Entry* _symbol_entry; + Gtk::RadioButton* _poly_voices_radio; Gtk::RadioButton* _poly_from_file_radio; - Gtk::RadioButton* _poly_from_parent_radio; - Gtk::RadioButton* _poly_from_user_radio; Gtk::SpinButton* _poly_spinbutton; Gtk::Button* _ok_button; Gtk::Button* _cancel_button; diff --git a/src/gui/WindowFactory.cpp b/src/gui/WindowFactory.cpp index 1842a04a..d5493339 100644 --- a/src/gui/WindowFactory.cpp +++ b/src/gui/WindowFactory.cpp @@ -269,8 +269,6 @@ WindowFactory::present_load_patch(SharedPtr patch, GraphObject::Prop if (w != _patch_windows.end()) _load_patch_win->set_transient_for(*w->second); - _load_patch_win->set_merge(); // Import is the only choice - _load_patch_win->present(patch, data); } diff --git a/src/gui/ingen_gui.glade b/src/gui/ingen_gui.glade index 9178a7fe..8c35c2e8 100644 --- a/src/gui/ingen_gui.glade +++ b/src/gui/ingen_gui.glade @@ -831,191 +831,140 @@ True 24 - + True - 2 - 4 - 12 - 4 - - - True - 0 - <b>Name: </b> - True - - - GTK_FILL - - - - - - True - 0 - <b>Polyphony: </b> - True - - - 1 - 2 - GTK_FILL - - - - - - Load from file - True - True - False - Use the name stored in the patch file - True - True - True - - - 1 - 2 - GTK_FILL - - - + 0 + 0 + 0 - - Load from file - True - True - False - Use the polyphony value stored in the patch file - True - True - True - - - 1 - 2 - 1 - 2 - GTK_FILL - - - - - + True + 2 + 3 + 12 + 12 - - Specify: + True - True - False - Specify a custom polyphony value for new patch + 0 + _Symbol: + True True - True - load_subpatch_poly_from_file_radio + load_subpatch_symbol_entry - False - False - 0 + GTK_FILL + - + True - False - True - Specify a custom polyphony value for new patch - 1 0 1000 1 10 0 - 1 + 0 + Polyphony: + True - False - 1 + 1 + 2 + GTK_FILL + - - - 3 - 4 - 1 - 2 - GTK_FILL - GTK_FILL - - - - - Same as parent (?) - True - True - False - Set polyphony to the same value as the parent (containing) patch - True - True - load_subpatch_poly_from_file_radio - - - 2 - 3 - 1 - 2 - GTK_FILL - - - - - - True - 0 - - - 2 - 3 - GTK_FILL - - - - - - True - - Specify: + + Load from _file True True False - Specify the name for the new patch + True + Use the polyphony value stored in the patch file True True - load_subpatch_name_from_file_radio + load_subpatch_poly_voices_radio - False - False - 0 + 2 + 3 + 1 + 2 + GTK_FILL + - + + True + + + _Voices: + True + True + False + True + Specify a custom polyphony value for new patch + True + True + True + load_subpatch_poly_from_file_radio + + + False + False + 0 + + + + + True + False + True + Specify a custom polyphony value for new patch + + 1 0 1000 1 10 0 + 1 + + + False + 1 + + + + + 1 + 2 + 1 + 2 + GTK_FILL + GTK_FILL + + + + + True + 0 + + + 2 + 3 + GTK_FILL + + + + + True - False True Specify the name for the new patch + True - False - 1 + 1 + 3 - - 3 - 4 - GTK_FILL - @@ -1078,103 +1027,151 @@ 24 - + True - 4 - 12 - 4 - - - True - 0 - <b>Polyphony: </b> - True - - - GTK_FILL - - - + 0 + 0 - - Keep current - True - True - False - Use the same polyphony as the current patch - True - True - True - - - 1 - 2 - GTK_FILL - - - - - - Load from file - True - True - False - Use the polyphony value stored in the patch file - True - True - load_patch_poly_from_current_radio - - - 2 - 3 - GTK_FILL - - - - - + True + 2 + 3 + 12 + 12 + + + True + 0 + Polyphony: + True + + + GTK_FILL + + + - - Specify: + + Load from _File True True False + True + Use the polyphony value stored in the patch file True True - load_patch_poly_from_current_radio + load_patch_poly_voices_radio - False - False - 0 + 2 + 3 + GTK_FILL + - + + True + 0 + Ports: + True + + + 1 + 2 + GTK_FILL + + + + + _Insert new ports True - False True - Specify a custom polyphony value for new patch - 1 0 100 1 10 0 - 1 + False + True + Create new ports for all of the loaded patch's ports + True + True + load_patch_merge_ports_radio - False - 1 + 2 + 3 + 1 + 2 + GTK_FILL + + + + + _Merge with existing ports + True + True + False + True + Merge current ports and loaded patch's ports wherever possible + True + True + True + + + 1 + 2 + 1 + 2 + GTK_FILL + + + + + True + 6 + + + _Voices: + True + True + False + True + Set polyphonic to a specific number of voices + True + True + True + + + False + False + 0 + + + + + True + True + Specify a custom polyphony value for new patch + + 1 0 100 1 10 0 + 1 + + + False + 1 + + + + + 1 + 2 + GTK_FILL + GTK_FILL - - 3 - 4 - GTK_FILL - GTK_FILL - False + False 2 -- cgit v1.2.1