summaryrefslogtreecommitdiffstats
path: root/src/libs
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2008-08-13 21:38:13 +0000
committerDavid Robillard <d@drobilla.net>2008-08-13 21:38:13 +0000
commitcc67a8d797a1b9ba05440f8abb60815aabe838dd (patch)
tree03c757b346ec5f5c00de004b497696b2e6715524 /src/libs
parent3bc15f3e1fef153dd6f1898b981a409876c171ac (diff)
downloadingen-cc67a8d797a1b9ba05440f8abb60815aabe838dd.tar.gz
ingen-cc67a8d797a1b9ba05440f8abb60815aabe838dd.tar.bz2
ingen-cc67a8d797a1b9ba05440f8abb60815aabe838dd.zip
Fix new node default naming from both plugin window and patch context menu.
git-svn-id: http://svn.drobilla.net/lad/ingen@1355 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/libs')
-rw-r--r--src/libs/client/PatchModel.cpp23
-rw-r--r--src/libs/client/PatchModel.hpp2
-rw-r--r--src/libs/client/PluginModel.cpp17
-rw-r--r--src/libs/client/PluginModel.hpp2
-rw-r--r--src/libs/gui/LoadPluginWindow.cpp21
-rw-r--r--src/libs/gui/PatchCanvas.cpp10
6 files changed, 48 insertions, 27 deletions
diff --git a/src/libs/client/PatchModel.cpp b/src/libs/client/PatchModel.cpp
index a0f0aa4b..b47bd4f4 100644
--- a/src/libs/client/PatchModel.cpp
+++ b/src/libs/client/PatchModel.cpp
@@ -188,5 +188,28 @@ PatchModel::polyphonic() const
}
+unsigned
+PatchModel::child_name_offset(const string& base_name) const
+{
+ assert(Path::is_valid_name(base_name));
+ unsigned offset = 0;
+
+ while (true) {
+ std::stringstream ss;
+ ss << base_name;
+ if (offset > 0)
+ ss << "_" << offset;
+ if (!find_child(ss.str()))
+ break;
+ else if (offset == 0)
+ offset = 2;
+ else
+ ++offset;
+ }
+
+ return offset;
+}
+
+
} // namespace Client
} // namespace Ingen
diff --git a/src/libs/client/PatchModel.hpp b/src/libs/client/PatchModel.hpp
index 909b9e9e..c73c60a3 100644
--- a/src/libs/client/PatchModel.hpp
+++ b/src/libs/client/PatchModel.hpp
@@ -61,6 +61,8 @@ public:
_editable = e;
signal_editable.emit(e);
} }
+
+ unsigned child_name_offset(const string& base_name) const;
// Signals
sigc::signal<void, SharedPtr<NodeModel> > signal_new_node;
diff --git a/src/libs/client/PluginModel.cpp b/src/libs/client/PluginModel.cpp
index 99387dcd..8c2705da 100644
--- a/src/libs/client/PluginModel.cpp
+++ b/src/libs/client/PluginModel.cpp
@@ -37,24 +37,9 @@ Redland::World* PluginModel::_rdf_world = NULL;
string
-PluginModel::default_node_name(SharedPtr<PatchModel> parent)
+PluginModel::default_node_name()
{
return Raul::Path::nameify(_symbol);
- /*string default_name = Raul::Path::nameify(_symbol);
- string name;
-
- char num_buf[3];
- for (uint i=0; i < 99; ++i) {
- name = default_name;
- if (i != 0) {
- snprintf(num_buf, 4, "_%d", i+1);
- name += num_buf;
- }
- if (!parent->find_child(name))
- break;
- }
-
- return name;*/
}
diff --git a/src/libs/client/PluginModel.hpp b/src/libs/client/PluginModel.hpp
index e19d1691..4e2bfab1 100644
--- a/src/libs/client/PluginModel.hpp
+++ b/src/libs/client/PluginModel.hpp
@@ -82,7 +82,7 @@ public:
}
}
- string default_node_name(SharedPtr<PatchModel> parent);
+ string default_node_name();
#ifdef HAVE_SLV2
static SLV2World slv2_world() { return _slv2_world; }
diff --git a/src/libs/gui/LoadPluginWindow.cpp b/src/libs/gui/LoadPluginWindow.cpp
index 76f5cdd4..fddb1396 100644
--- a/src/libs/gui/LoadPluginWindow.cpp
+++ b/src/libs/gui/LoadPluginWindow.cpp
@@ -148,7 +148,12 @@ LoadPluginWindow::name_changed()
void
LoadPluginWindow::set_patch(SharedPtr<PatchModel> patch)
{
- _patch = patch;
+ if (_patch) {
+ _patch = patch;
+ plugin_selection_changed();
+ } else {
+ _patch = patch;
+ }
/*if (patch->poly() <= 1)
_polyphonic_checkbutton->property_sensitive() = false;
@@ -272,13 +277,11 @@ LoadPluginWindow::plugin_activated(const Gtk::TreeModel::Path& path, Gtk::TreeVi
void
LoadPluginWindow::plugin_selection_changed()
{
- _plugin_name_offset = 0;
-
- _node_name_entry->set_text(generate_module_name());
-
- //Gtk::TreeModel::iterator iter = _selection->get_selected();
- //Gtk::TreeModel::Row row = *iter;
- //const PluginModel* plugin = row.get_value(_plugins_columns._col_plugin_model);
+ Gtk::TreeModel::iterator iter = _selection->get_selected();
+ Gtk::TreeModel::Row row = *iter;
+ boost::shared_ptr<PluginModel> p = row.get_value(_plugins_columns._col_plugin_model);
+ _plugin_name_offset = _patch->child_name_offset(p->default_node_name());
+ _node_name_entry->set_text(generate_module_name(_plugin_name_offset));
}
@@ -299,7 +302,7 @@ LoadPluginWindow::generate_module_name(int offset)
Gtk::TreeModel::Row row = *iter;
SharedPtr<PluginModel> plugin = row.get_value(_plugins_columns._col_plugin_model);
std::stringstream ss;
- ss << plugin->default_node_name(_patch);
+ ss << plugin->default_node_name();
if (offset != 0)
ss << "_" << offset + 1;
name = ss.str();
diff --git a/src/libs/gui/PatchCanvas.cpp b/src/libs/gui/PatchCanvas.cpp
index 0cd82ecb..48ad1366 100644
--- a/src/libs/gui/PatchCanvas.cpp
+++ b/src/libs/gui/PatchCanvas.cpp
@@ -592,7 +592,15 @@ PatchCanvas::menu_add_port(const string& name, const string& type, bool is_outpu
void
PatchCanvas::load_plugin(SharedPtr<PluginModel> plugin)
{
- const Path& path = _patch->path().base() + plugin->default_node_name(_patch);
+ string name = plugin->default_node_name();
+ unsigned offset = _patch->child_name_offset(name);
+ if (offset != 0) {
+ std::stringstream ss;
+ ss << name << "_" << offset;
+ name = ss.str();
+ }
+
+ const Path path = _patch->path().base() + name;
// FIXME: polyphony?
App::instance().engine()->create_node(path, plugin->uri(), false);
GraphObject::Variables data = get_initial_data();