From e762fe36be82c93847447e8691217ea7e522f785 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 25 Dec 2015 17:13:00 +0100 Subject: [PATCH] refactor Processor-Box plugin drag/drop: allow presets --- gtk2_ardour/processor_box.cc | 134 ++++++++++++++++++++++------------- gtk2_ardour/processor_box.h | 5 ++ 2 files changed, 89 insertions(+), 50 deletions(-) diff --git a/gtk2_ardour/processor_box.cc b/gtk2_ardour/processor_box.cc index 666d770fd2..a997795cde 100644 --- a/gtk2_ardour/processor_box.cc +++ b/gtk2_ardour/processor_box.cc @@ -1046,6 +1046,7 @@ static std::list drop_targets() std::list tmp; tmp.push_back (Gtk::TargetEntry ("processor")); tmp.push_back (Gtk::TargetEntry ("PluginInfoPtr")); + tmp.push_back (Gtk::TargetEntry ("PluginPresetPtr")); return tmp; } @@ -1149,41 +1150,66 @@ ProcessorBox::route_going_away () _route.reset (); } -void -ProcessorBox::plugin_drop(Gtk::SelectionData const &data, ProcessorEntry* position, Glib::RefPtr const & context) +boost::shared_ptr +ProcessorBox::find_drop_position (ProcessorEntry* position) { - if (data.get_target() != "PluginInfoPtr") { - return; - } - if (!_session) { - return; - } + boost::shared_ptr p; + if (position) { + p = position->processor (); + if (!p) { + /* dropped on the blank entry (which will be before the + fader), so use the first non-blank child as our + `dropped on' processor */ + list c = processor_display.children (); + list::iterator i = c.begin (); - boost::shared_ptr p; - if (position) { - p = position->processor (); - if (!p) { - /* dropped on the blank entry (which will be before the - fader), so use the first non-blank child as our - `dropped on' processor */ - list c = processor_display.children (); - list::iterator i = c.begin (); - - assert (i != c.end ()); - p = (*i)->processor (); - assert (p); - } + assert (i != c.end ()); + p = (*i)->processor (); + assert (p); } + } + return p; +} +void +ProcessorBox::_drop_plugin_preset (Gtk::SelectionData const &data, Route::ProcessorList &pl) +{ const void * d = data.get_data(); - const Gtkmm2ext::DnDTreeView * tv = reinterpret_cast*>(d); + const Gtkmm2ext::DnDTreeView* tv = reinterpret_cast*>(d); - std::list nfos; + PluginPresetList nfos; TreeView* source; tv->get_object_drag_data (nfos, &source); - Route::ProcessorStreams err; - Route::ProcessorList pl; + for (list::const_iterator i = nfos.begin(); i != nfos.end(); ++i) { + PluginPresetPtr ppp = (*i); + PluginInfoPtr pip = ppp->_pip; + PluginPtr p = pip->load (*_session); + if (!p) { + continue; + } + + if (ppp->_preset.valid) { + p->load_preset (ppp->_preset); + } + + boost::shared_ptr processor (new PluginInsert (*_session, p)); + if (Config->get_new_plugins_active ()) { + processor->activate (); + } + pl.push_back (processor); + } +} + +void +ProcessorBox::_drop_plugin (Gtk::SelectionData const &data, Route::ProcessorList &pl) +{ + const void * d = data.get_data(); + const Gtkmm2ext::DnDTreeView* tv = reinterpret_cast*>(d); + PluginInfoList nfos; + + TreeView* source; + tv->get_object_drag_data (nfos, &source); for (list::const_iterator i = nfos.begin(); i != nfos.end(); ++i) { PluginPtr p = (*i)->load (*_session); @@ -1196,36 +1222,44 @@ ProcessorBox::plugin_drop(Gtk::SelectionData const &data, ProcessorEntry* positi } pl.push_back (processor); } - - if (_route->add_processors (pl, p, &err)) { - string msg = _( - "Adding the given processor(s) failed probably,\n\ -because the I/O configuration of the plugins could\n\ -not match the configuration of this track."); - MessageDialog am (msg); - am.run (); - } } void -ProcessorBox::object_drop(DnDVBox* source, ProcessorEntry* position, Glib::RefPtr const & context) +ProcessorBox::plugin_drop (Gtk::SelectionData const &data, ProcessorEntry* position, Glib::RefPtr const & context) { - boost::shared_ptr p; - if (position) { - p = position->processor (); - if (!p) { - /* dropped on the blank entry (which will be before the - fader), so use the first non-blank child as our - `dropped on' processor */ - list c = processor_display.children (); - list::iterator i = c.begin (); - - assert (i != c.end ()); - p = (*i)->processor (); - assert (p); - } + if (!_session) { + return; } + boost::shared_ptr p = find_drop_position (position); + Route::ProcessorList pl; + + if (data.get_target() == "PluginInfoPtr") { + _drop_plugin (data, pl); + } + else if (data.get_target() == "PluginPresetPtr") { + _drop_plugin_preset (data, pl); + } + else { + return; + } + + Route::ProcessorStreams err; + if (_route->add_processors (pl, p, &err)) { + string msg = _( + "Processor Drag/Drop failed. Probably because\n\ +the I/O configuration of the plugins could\n\ +not match the configuration of this track."); + MessageDialog am (msg); + am.run (); + } +} + +void +ProcessorBox::object_drop (DnDVBox* source, ProcessorEntry* position, Glib::RefPtr const & context) +{ + boost::shared_ptr p = find_drop_position (position); + list children = source->selection (); list > procs; for (list::const_iterator i = children.begin(); i != children.end(); ++i) { diff --git a/gtk2_ardour/processor_box.h b/gtk2_ardour/processor_box.h index 3367534b07..872f58ce61 100644 --- a/gtk2_ardour/processor_box.h +++ b/gtk2_ardour/processor_box.h @@ -348,6 +348,11 @@ class ProcessorBox : public Gtk::HBox, public PluginInterestedObject, public ARD Gtkmm2ext::DnDVBox processor_display; Gtk::ScrolledWindow processor_scroller; + boost::shared_ptr find_drop_position (ProcessorEntry* position); + + void _drop_plugin_preset (Gtk::SelectionData const &, ARDOUR::Route::ProcessorList &); + void _drop_plugin (Gtk::SelectionData const &, ARDOUR::Route::ProcessorList &); + void plugin_drop (Gtk::SelectionData const &, ProcessorEntry* position, Glib::RefPtr const & context); void object_drop (Gtkmm2ext::DnDVBox *, ProcessorEntry *, Glib::RefPtr const &);