ProcessorBox: allow to receive PluginInfoPtr drops
authorRobin Gareus <robin@gareus.org>
Tue, 22 Dec 2015 03:24:20 +0000 (04:24 +0100)
committerRobin Gareus <robin@gareus.org>
Tue, 22 Dec 2015 03:24:20 +0000 (04:24 +0100)
gtk2_ardour/processor_box.cc
gtk2_ardour/processor_box.h

index 049cfaaa18476df2fbdb93c59118fc929df988a7..f6f3bd86ececeed14675285ede3ed0440bdddc8b 100644 (file)
@@ -1045,6 +1045,7 @@ static std::list<Gtk::TargetEntry> drop_targets()
 {
        std::list<Gtk::TargetEntry> tmp;
        tmp.push_back (Gtk::TargetEntry ("processor"));
+       tmp.push_back (Gtk::TargetEntry ("PluginInfoPtr"));
        return tmp;
 }
 
@@ -1085,6 +1086,7 @@ ProcessorBox::ProcessorBox (ARDOUR::Session* sess, boost::function<PluginSelecto
 
        processor_display.Reordered.connect (sigc::mem_fun (*this, &ProcessorBox::reordered));
        processor_display.DropFromAnotherBox.connect (sigc::mem_fun (*this, &ProcessorBox::object_drop));
+       processor_display.DropFromExternal.connect (sigc::mem_fun (*this, &ProcessorBox::plugin_drop));
 
        processor_scroller.show ();
        processor_display.show ();
@@ -1147,6 +1149,74 @@ ProcessorBox::route_going_away ()
        _route.reset ();
 }
 
+void
+ProcessorBox::plugin_drop(Gtk::SelectionData const &data, ProcessorEntry* position, Glib::RefPtr<Gdk::DragContext> const & context)
+{
+               if (data.get_target() != "PluginInfoPtr") {
+                       return;
+               }
+               if (!_session) {
+                       return;
+               }
+
+               boost::shared_ptr<Processor> 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<ProcessorEntry*> c = processor_display.children ();
+                               list<ProcessorEntry*>::iterator i = c.begin ();
+
+                               assert (i != c.end ());
+                               p = (*i)->processor ();
+                               assert (p);
+                       }
+               }
+
+               const void * d = data.get_data();
+               const Gtkmm2ext::DnDTreeView<ARDOUR::PluginInfoPtr> * tv = reinterpret_cast<const Gtkmm2ext::DnDTreeView<ARDOUR::PluginInfoPtr>*>(d);
+
+               std::list<ARDOUR::PluginInfoPtr> nfos;
+               TreeView* source;
+               tv->get_object_drag_data (nfos, &source);
+
+               Route::ProcessorStreams err;
+               Route::ProcessorList pl;
+
+               for (list<PluginInfoPtr>::const_iterator i = nfos.begin(); i != nfos.end(); ++i) {
+                       PluginPtr p = (*i)->load (*_session);
+                       if (!p) {
+                               continue;
+                       }
+                       boost::shared_ptr<Processor> processor (new PluginInsert (*_session, p));
+                       if (Config->get_new_plugins_active ()) {
+                               processor->activate ();
+                       }
+                       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 ();
+               } else if (pl.size() == 1 && Config->get_open_gui_after_adding_plugin()) {
+                       boost::shared_ptr<Processor> processor = pl.front();
+                       boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
+                       if (_session->engine().connected () && processor_can_be_edited (processor)) {
+                               if (pi && pi->plugin()->has_editor ()) {
+                                       edit_processor (processor);
+                               } else {
+                                       generic_edit_processor (processor);
+                               }
+                       }
+               }
+}
+
 void
 ProcessorBox::object_drop(DnDVBox<ProcessorEntry>* source, ProcessorEntry* position, Glib::RefPtr<Gdk::DragContext> const & context)
 {
index 015afca4a9f40d4cee022fab20caf4d8d6982f6a..3367534b07cbb9ba6b93d99dbb15e7fb03b46a6f 100644 (file)
@@ -348,6 +348,7 @@ class ProcessorBox : public Gtk::HBox, public PluginInterestedObject, public ARD
        Gtkmm2ext::DnDVBox<ProcessorEntry> processor_display;
        Gtk::ScrolledWindow    processor_scroller;
 
+       void plugin_drop (Gtk::SelectionData const &, ProcessorEntry* position, Glib::RefPtr<Gdk::DragContext> const & context);
        void object_drop (Gtkmm2ext::DnDVBox<ProcessorEntry> *, ProcessorEntry *, Glib::RefPtr<Gdk::DragContext> const &);
 
        Width _width;