a more reliable/robust/less complex version of previous commit
[ardour.git] / gtk2_ardour / plugin_pin_dialog.cc
index 4962c1aee45edc953f2648d0df1d13b861abf092..24a4fec4f4cc071c6f93ccdc315bec2db064d3db 100644 (file)
@@ -21,7 +21,6 @@
 
 #include <gtkmm/table.h>
 #include <gtkmm/frame.h>
-#include <gtkmm/box.h>
 #include <gtkmm/label.h>
 
 #include "pbd/replace_all.h"
@@ -44,7 +43,7 @@
 #include "tooltips.h"
 #include "ui_config.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace ARDOUR;
 using namespace PBD;
@@ -471,33 +470,8 @@ PluginPinWidget::refill_output_presets ()
 {
        using namespace Menu_Helpers;
        _out_presets.clear_items ();
-       PluginOutputConfiguration ppc (_pi->plugin (0)->possible_output ());
-
-       bool need_dropdown = true;
-
-       if (ppc.size () == 0) {
-               need_dropdown = false;
-       }
-
-       if (!_pi->strict_io () && ppc.size () == 1) {
-               need_dropdown = false;
-       }
-
-       if (_pi->strict_io () && ppc.size () == 1) {
-               // "stereo" is currently preferred default for instruments, see PluginInsert
-               if (ppc.find (2) != ppc.end ()) {
-                       need_dropdown = false;
-               }
-       }
 
-       if (!_pi->needs_midi_input ()) {
-               /* loose definition of instruments, maybe impose additional
-                * || _pi->natural_input_streams ().n_audio () != 0
-                * and special case variable output plugins
-                * && !_pi->plugin (0)->info->reconfigurable_io()
-                */
-               need_dropdown = false;
-       }
+       bool need_dropdown = _pi->has_output_presets ();
 
        if (!need_dropdown) {
                _out_presets.set_sensitive (false);
@@ -512,6 +486,7 @@ PluginPinWidget::refill_output_presets ()
                _out_presets.set_text (_("Automatic"));
        }
 
+       PluginOutputConfiguration ppc (_pi->plugin (0)->possible_output ());
        if (ppc.find (0) != ppc.end ()) {
                // anyting goes
                ppc.clear ();
@@ -1982,18 +1957,79 @@ PluginPinWidget::Control::control_changed ()
        _ignore_ui_adjustment = false;
 }
 
+
+
 PluginPinDialog::PluginPinDialog (boost::shared_ptr<ARDOUR::PluginInsert> pi)
        : ArdourWindow (string_compose (_("Pin Configuration: %1"), pi->name ()))
-       , ppw (pi)
 {
-       add (ppw);
+       ppw.push_back (PluginPinWidgetPtr(new PluginPinWidget (pi)));
+       add (*ppw.back());
 }
 
-PluginPinDialog::~PluginPinDialog () { }
 
+PluginPinDialog::PluginPinDialog (boost::shared_ptr<ARDOUR::Route> r)
+       : ArdourWindow (string_compose (_("Pin Configuration: %1"), r->name ()))
+       , _route (r)
+{
+       vbox = manage (new VBox ());
+       add (*vbox);
+       vbox->show ();
+
+       _route->foreach_processor (sigc::mem_fun (*this, &PluginPinDialog::add_processor));
+
+       _route->processors_changed.connect (
+               _route_connections, invalidator (*this), boost::bind (&PluginPinDialog::route_processors_changed, this, _1), gui_context()
+               );
+
+       _route->DropReferences.connect (
+               _route_connections, invalidator (*this), boost::bind (&PluginPinDialog::route_going_away, this), gui_context()
+               );
+}
 void
 PluginPinDialog::set_session (ARDOUR::Session *s)
 {
        SessionHandlePtr::set_session (s);
-       ppw.set_session (s);
+       for (PluginPinWidgetList::iterator i = ppw.begin(); i != ppw.end(); ++i) {
+               (*i)->set_session (s);
+       }
+}
+
+void
+PluginPinDialog::route_processors_changed (ARDOUR::RouteProcessorChange)
+{
+       ppw.clear ();
+       remove ();
+       vbox = manage (new VBox ());
+       add (*vbox);
+       vbox->show ();
+       _route->foreach_processor (sigc::mem_fun (*this, &PluginPinDialog::add_processor));
+}
+
+void
+PluginPinDialog::route_going_away ()
+{
+       ppw.clear ();
+       _route.reset ();
+       remove ();
+}
+
+void
+PluginPinDialog::add_processor (boost::weak_ptr<Processor> p)
+{
+       boost::shared_ptr<Processor> proc = p.lock ();
+       if (!proc || !proc->display_to_user ()) {
+               return;
+       }
+       boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (proc);
+       if (pi) {
+               ppw.push_back (PluginPinWidgetPtr(new PluginPinWidget (pi)));
+               vbox->pack_start (*ppw.back());
+       } else {
+               HBox* hbox = manage (new HBox ());
+               hbox->pack_start (*manage (new HSeparator ()));
+               hbox->pack_start (*manage (new Label (proc->display_name ())));
+               hbox->pack_start (*manage (new HSeparator ()));
+               vbox->pack_start (*hbox);
+               hbox->show_all ();
+       }
 }