diff options
Diffstat (limited to 'src/gui/LoadSubpatchWindow.cpp')
-rw-r--r-- | src/gui/LoadSubpatchWindow.cpp | 101 |
1 files changed, 57 insertions, 44 deletions
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 <dirent.h> #include <cassert> #include <boost/optional.hpp> +#include <glibmm/miscutils.h> #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<Gnome::Glade::Xml>& 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<PatchModel> 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<PatchModel> 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<Raul::Symbol> 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<Glib::ustring> 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 |