mechanism to allow Track (or other Route-derived type) to add its own processors...
[ardour.git] / gtk2_ardour / plugin_pin_dialog.cc
index 070f6da064649ef553ebc437c4b3a8ee6edfbf90..d9591732bd2b1ad3372029ca35780c0b10d1d6aa 100644 (file)
 
 #include <boost/algorithm/string.hpp>
 
-#include <gtkmm/table.h>
+#include <gtkmm/box.h>
 #include <gtkmm/frame.h>
 #include <gtkmm/label.h>
+#include <gtkmm/separator.h>
+#include <gtkmm/table.h>
 
 #include "pbd/replace_all.h"
 
 #include "gtkmm2ext/utils.h"
 #include "gtkmm2ext/rgb_macros.h"
+#include "gtkmm2ext/menu_elems.h"
+
+#include "widgets/tooltips.h"
 
 #include "ardour/amp.h"
 #include "ardour/audioengine.h"
 #include "ardour/profile.h"
 #include "ardour/send.h"
 #include "ardour/session.h"
+#include "ardour/value_as_string.h"
 
 #include "plugin_pin_dialog.h"
 #include "gui_thread.h"
 #include "timers.h"
-#include "tooltips.h"
 #include "ui_config.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace ARDOUR;
 using namespace PBD;
 using namespace std;
 using namespace Gtk;
 using namespace Gtkmm2ext;
+using namespace ArdourWidgets;
 
 PluginPinWidget::PluginPinWidget (boost::shared_ptr<ARDOUR::PluginInsert> pi)
        : _set_config (_("Manual Config"), ArdourButton::led_default_elements)
@@ -189,7 +195,7 @@ PluginPinWidget::PluginPinWidget (boost::shared_ptr<ARDOUR::PluginInsert> pi)
        tl->pack_start (*manage (new Label ("")), true, true); // invisible separator
        tl->pack_start (*manage (new HSeparator ()), false, false, 4);
        _out_presets.disable_scrolling ();
-       ARDOUR_UI_UTILS::set_tooltip (_out_presets, _("Output Presets"));
+       ArdourWidgets::set_tooltip (_out_presets, _("Output Presets"));
        tl->pack_start (_out_presets, false, false);
 
        /* right side */
@@ -470,33 +476,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);
@@ -511,6 +492,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 ();
@@ -588,7 +570,7 @@ uint32_t
 PluginPinWidget::add_port_to_table (boost::shared_ptr<Port> p, uint32_t r, bool can_remove)
 {
        std::string lbl;
-       std::string tip = p->name ();
+       std::string tip = Gtkmm2ext::markup_escape_text (p->name ());
        std::vector<std::string> cns;
        bool single_source = true;
        p->get_connections (cns);
@@ -624,7 +606,7 @@ PluginPinWidget::add_port_to_table (boost::shared_ptr<Port> p, uint32_t r, bool
        ArdourButton *pb = manage (new ArdourButton (lbl));
        pb->set_text_ellipsize (Pango::ELLIPSIZE_MIDDLE);
        pb->set_layout_ellipsize_width (108 * PANGO_SCALE);
-       ARDOUR_UI_UTILS::set_tooltip (*pb, tip);
+       ArdourWidgets::set_tooltip (*pb, tip);
        _sidechain_tbl->attach (*pb, 0, 1, r, r +1 , EXPAND|FILL, SHRINK);
 
        pb->signal_button_press_event ().connect (sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::sc_input_press), boost::weak_ptr<Port> (p)), false);
@@ -1845,7 +1827,7 @@ PluginPinWidget::maybe_add_route_to_input_menu (boost::shared_ptr<Route> r, Data
        /* we're going to create the new send pre-fader, so check the route amp's data type.  */
        const ChanCount& rc (r->amp ()->input_streams ());
        if (!already_present && rc.get (dt) > 0) {
-               citems.push_back (MenuElem (r->name (), sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_send_from), wp, boost::weak_ptr<Route> (r))));
+               citems.push_back (MenuElemNoMnemonic (r->name (), sigc::bind (sigc::mem_fun (*this, &PluginPinWidget::add_send_from), wp, boost::weak_ptr<Route> (r))));
                ++added;
        }
        return added;
@@ -1887,23 +1869,11 @@ PluginPinWidget::Control::Control (boost::shared_ptr<AutomationControl> c, strin
        _slider.show ();
 
        const ARDOUR::ParameterDescriptor& desc = c->desc ();
-       double const lo = c->internal_to_interface (desc.lower);
-       double const up = c->internal_to_interface (desc.upper);
-       double const normal = c->internal_to_interface (desc.normal);
-       double smallstep = desc.smallstep;
-       double largestep = desc.largestep;
-
-       if (smallstep == 0.0) {
-               smallstep = up / 1000.;
-       } else {
-               smallstep = c->internal_to_interface (desc.lower + smallstep);
-       }
-
-       if (largestep == 0.0) {
-               largestep = up / 40.;
-       } else {
-               largestep = c->internal_to_interface (desc.lower + largestep);
-       }
+       double const lo        = c->internal_to_interface (desc.lower);
+       double const up        = c->internal_to_interface (desc.upper);
+       double const normal    = c->internal_to_interface (desc.normal);
+       double const smallstep = c->internal_to_interface (desc.lower + desc.smallstep);
+       double const largestep = c->internal_to_interface (desc.lower + desc.largestep);
 
        _adjustment.set_lower (lo);
        _adjustment.set_upper (up);
@@ -1938,10 +1908,8 @@ PluginPinWidget::Control::set_tooltip ()
        if (!c) {
                return;
        }
-       char tmp[256];
-       snprintf (tmp, sizeof (tmp), "%s: %.2f", _name.c_str (), c->internal_to_user (c->get_value ()));
-
-       string sm = Gtkmm2ext::markup_escape_text (tmp);
+       std::string tt = _name + ": " + ARDOUR::value_as_string (c->desc(), c->get_value ());
+       string sm = Gtkmm2ext::markup_escape_text (tt);
        _slider_persistant_tooltip.set_tip (sm);
 }
 
@@ -1994,10 +1962,18 @@ PluginPinDialog::PluginPinDialog (boost::shared_ptr<ARDOUR::PluginInsert> pi)
 PluginPinDialog::PluginPinDialog (boost::shared_ptr<ARDOUR::Route> r)
        : ArdourWindow (string_compose (_("Pin Configuration: %1"), r->name ()))
        , _route (r)
+       , _height_mapped (false)
 {
        vbox = manage (new VBox ());
-       add (*vbox);
+       vbox->signal_size_allocate().connect (sigc::mem_fun (*this, &PluginPinDialog::map_height));
+       scroller = manage (new ScrolledWindow);
+       scroller->set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
+       scroller->set_shadow_type (Gtk::SHADOW_NONE);
+       scroller->show ();
        vbox->show ();
+       scroller->add (*vbox);
+       add (*scroller);
+
 
        _route->foreach_processor (sigc::mem_fun (*this, &PluginPinDialog::add_processor));
 
@@ -2018,15 +1994,26 @@ PluginPinDialog::set_session (ARDOUR::Session *s)
        }
 }
 
+void
+PluginPinDialog::map_height (Gtk::Allocation&)
+{
+       if (!_height_mapped) {
+               scroller->set_size_request (-1, std::min (600, 2 + vbox->get_height()));
+               _height_mapped = true;
+       }
+}
+
 void
 PluginPinDialog::route_processors_changed (ARDOUR::RouteProcessorChange)
 {
        ppw.clear ();
-       remove ();
+       _height_mapped = false;
+       scroller->remove ();
        vbox = manage (new VBox ());
-       add (*vbox);
-       vbox->show ();
+       vbox->signal_size_allocate().connect (sigc::mem_fun (*this, &PluginPinDialog::map_height));
+       scroller->add (*vbox);
        _route->foreach_processor (sigc::mem_fun (*this, &PluginPinDialog::add_processor));
+       vbox->show ();
 }
 
 void
@@ -2045,6 +2032,11 @@ PluginPinDialog::add_processor (boost::weak_ptr<Processor> p)
                return;
        }
        boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (proc);
+#ifdef MIXBUS
+       if (pi && pi->is_channelstrip ()) {
+               pi.reset ();
+       }
+#endif
        if (pi) {
                ppw.push_back (PluginPinWidgetPtr(new PluginPinWidget (pi)));
                vbox->pack_start (*ppw.back());
@@ -2053,7 +2045,7 @@ PluginPinDialog::add_processor (boost::weak_ptr<Processor> p)
                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);
+               vbox->pack_start (*hbox, false, false);
                hbox->show_all ();
        }
 }