Vorbis Quality Config GUI
[ardour.git] / gtk2_ardour / plugin_pin_dialog.cc
index 37f453da7ee49afe7a9d6b5d4e7e22373e1b70f7..0a9ad9e628579d48918d0be474e66652a1ee30ae 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/messagedialog.h>
+#include <gtkmm/separator.h>
+#include <gtkmm/table.h>
 
 #include "pbd/replace_all.h"
 
@@ -29,6 +32,8 @@
 #include "gtkmm2ext/rgb_macros.h"
 #include "gtkmm2ext/menu_elems.h"
 
+#include "widgets/tooltips.h"
+
 #include "ardour/amp.h"
 #include "ardour/audioengine.h"
 #include "ardour/pannable.h"
@@ -42,7 +47,6 @@
 #include "plugin_pin_dialog.h"
 #include "gui_thread.h"
 #include "timers.h"
-#include "tooltips.h"
 #include "ui_config.h"
 
 #include "pbd/i18n.h"
@@ -52,6 +56,7 @@ 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)
@@ -191,7 +196,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 */
@@ -300,6 +305,16 @@ PluginPinWidget::idle_update ()
        return false;
 }
 
+void
+PluginPinWidget::error_message_dialog (std::string const& msg) const
+{
+       assert (_session);
+       Gtk::MessageDialog d (
+                       _session->actively_recording () ? _("Cannot perform operation while actively recording.") : msg
+                       , false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_OK, true);
+       d.run();
+}
+
 
 void
 PluginPinWidget::plugin_reconfigured ()
@@ -566,7 +581,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);
@@ -602,7 +617,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);
@@ -1551,14 +1566,15 @@ PluginPinWidget::handle_disconnect (const CtrlElem &e, bool no_signal)
 void
 PluginPinWidget::toggle_sidechain ()
 {
-       if (_session && _session->actively_recording ()) { return; }
-       _route ()->add_remove_sidechain (_pi, !_pi->has_sidechain ());
+       if (!_route ()->add_remove_sidechain (_pi, !_pi->has_sidechain ())) {
+               error_message_dialog (_("Failed to toggle sidechain."));
+       }
 }
 
 void
 PluginPinWidget::connect_sidechain ()
 {
-       if (!_session) { return; }
+       assert (_session);
 
        if (_sidechain_selector == 0) {
                _sidechain_selector = new IOSelectorWindow (_session, _pi->sidechain_input ());
@@ -1574,10 +1590,14 @@ PluginPinWidget::connect_sidechain ()
 void
 PluginPinWidget::reset_configuration ()
 {
+       bool rv;
        if (_set_config.get_active ()) {
-               _route ()->reset_plugin_insert (_pi);
+               rv = _route ()->reset_plugin_insert (_pi);
        } else {
-               _route ()->customize_plugin_insert (_pi, _n_plugins, _out, _sinks);
+               rv = _route ()->customize_plugin_insert (_pi, _n_plugins, _out, _sinks);
+       }
+       if (!rv) {
+               error_message_dialog (_("Failed to reset plugin configuration."));
        }
 }
 
@@ -1590,47 +1610,56 @@ PluginPinWidget::reset_mapping ()
 void
 PluginPinWidget::select_output_preset (uint32_t n_audio)
 {
-       if (_session && _session->actively_recording ()) { return; }
        ChanCount out (DataType::AUDIO, n_audio);
-       _route ()->plugin_preset_output (_pi, out);
+       if (!_route ()->plugin_preset_output (_pi, out)) {
+               error_message_dialog (_("Failed to change channel preset."));
+       }
 }
 
 void
 PluginPinWidget::add_remove_plugin_clicked (bool add)
 {
-       if (_session && _session->actively_recording ()) { return; }
        ChanCount out = _out;
        ChanCount sinks = _sinks;
        assert (add || _n_plugins > 0);
-       _route ()->customize_plugin_insert (_pi, _n_plugins + (add ? 1 : -1), out, sinks);
+       if (!_route ()->customize_plugin_insert (_pi, _n_plugins + (add ? 1 : -1), out, sinks)) {
+               error_message_dialog (_("Failed to change instance count"));
+       }
 }
 
 void
 PluginPinWidget::add_remove_port_clicked (bool add, ARDOUR::DataType dt)
 {
-       if (_session && _session->actively_recording ()) { return; }
        ChanCount out = _out;
        ChanCount sinks = _sinks;
        assert (add || out.get (dt) > 0);
        out.set (dt, out.get (dt) + (add ? 1 : -1));
-       _route ()->customize_plugin_insert (_pi, _n_plugins, out, sinks);
+       if (!_route ()->customize_plugin_insert (_pi, _n_plugins, out, sinks)) {
+               error_message_dialog (_("Failed to alter plugin output configuration."));
+       }
 }
 
 void
 PluginPinWidget::add_remove_inpin_clicked (bool add, ARDOUR::DataType dt)
 {
-       if (_session && _session->actively_recording ()) { return; }
        ChanCount out = _out;
        ChanCount sinks = _sinks;
        assert (add || sinks.get (dt) > 0);
        sinks.set (dt, sinks.get (dt) + (add ? 1 : -1));
-       _route ()->customize_plugin_insert (_pi, _n_plugins, out, sinks);
+       if (!_route ()->customize_plugin_insert (_pi, _n_plugins, out, sinks)) {
+               error_message_dialog (_("Failed to alter plugin input configuration."));
+       }
 }
 
 void
 PluginPinWidget::add_sidechain_port (DataType dt)
 {
-       if (_session && _session->actively_recording ()) { return; }
+       assert (_session);
+       if (_session->actively_recording ()) {
+               error_message_dialog (/* unused */ "");
+               return;
+       }
+
        boost::shared_ptr<IO> io = _pi->sidechain_input ();
        if (!io) {
                return;
@@ -1644,7 +1673,11 @@ PluginPinWidget::add_sidechain_port (DataType dt)
 void
 PluginPinWidget::remove_port (boost::weak_ptr<ARDOUR::Port> wp)
 {
-       if (_session && _session->actively_recording ()) { return; }
+       assert (_session);
+       if (_session->actively_recording ()) {
+               error_message_dialog (/* unused */ "");
+               return;
+       }
        boost::shared_ptr<ARDOUR::Port> p = wp.lock ();
        boost::shared_ptr<IO> io = _pi->sidechain_input ();
        if (!io || !p) {
@@ -1656,7 +1689,12 @@ PluginPinWidget::remove_port (boost::weak_ptr<ARDOUR::Port> wp)
 void
 PluginPinWidget::disconnect_port (boost::weak_ptr<ARDOUR::Port> wp)
 {
-       if (_session && _session->actively_recording ()) { return; }
+       assert (_session);
+       if (_session->actively_recording ()) {
+               error_message_dialog (/* unused */ "");
+               return;
+       }
+
        boost::shared_ptr<ARDOUR::Port> p = wp.lock ();
        boost::shared_ptr<IO> io = _pi->sidechain_input ();
        if (!io || !p) {
@@ -1668,7 +1706,12 @@ PluginPinWidget::disconnect_port (boost::weak_ptr<ARDOUR::Port> wp)
 void
 PluginPinWidget::connect_port (boost::weak_ptr<ARDOUR::Port> wp0, boost::weak_ptr<ARDOUR::Port> wp1)
 {
-       if (_session && _session->actively_recording ()) { return; }
+       assert (_session);
+       if (_session->actively_recording ()) {
+               error_message_dialog (/* unused */ "");
+               return;
+       }
+
        boost::shared_ptr<ARDOUR::Port> p0 = wp0.lock ();
        boost::shared_ptr<ARDOUR::Port> p1 = wp1.lock ();
        boost::shared_ptr<IO> io = _pi->sidechain_input ();
@@ -1684,11 +1727,16 @@ PluginPinWidget::connect_port (boost::weak_ptr<ARDOUR::Port> wp0, boost::weak_pt
 void
 PluginPinWidget::add_send_from (boost::weak_ptr<ARDOUR::Port> wp, boost::weak_ptr<ARDOUR::Route> wr)
 {
-       if (_session && _session->actively_recording ()) { return; }
+       assert (_session);
+       if (_session->actively_recording ()) {
+               error_message_dialog (/* unused */ "");
+               return;
+       }
+
        boost::shared_ptr<Port> p = wp.lock ();
        boost::shared_ptr<Route> r = wr.lock ();
        boost::shared_ptr<IO> io = _pi->sidechain_input ();
-       if (!p || !r || !io || !_session) {
+       if (!p || !r || !io) {
                return;
        }
 
@@ -1729,25 +1777,27 @@ PluginPinWidget::add_send_from (boost::weak_ptr<ARDOUR::Port> wp, boost::weak_pt
 bool
 PluginPinWidget::sc_input_release (GdkEventButton *ev)
 {
-       if (_session && _session->actively_recording ()) { return false; }
+       assert (_session);
+       if (_session->actively_recording ()) {
+               error_message_dialog (/* unused */ "");
+               return false;
+       }
+
        if (ev->button == 3) {
                connect_sidechain ();
        }
        return false;
 }
 
-struct RouteCompareByName {
-       bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
-               return a->name ().compare (b->name ()) < 0;
-       }
-};
-
 bool
 PluginPinWidget::sc_input_press (GdkEventButton *ev, boost::weak_ptr<ARDOUR::Port> wp)
 {
        using namespace Menu_Helpers;
-       if (!_session || _session->actively_recording ()) { return false; }
-       if (!_session->engine ().connected ()) { return false; }
+       assert (_session);
+       if (_session->actively_recording () || !_session->engine ().connected ()) {
+               error_message_dialog (_("Port Connections are only available with active Audio/MIDI system."));
+               return false;
+       }
 
        if (ev->button == 1) {
                MenuList& citems = input_menu.items ();
@@ -1770,9 +1820,8 @@ PluginPinWidget::sc_input_press (GdkEventButton *ev, boost::weak_ptr<ARDOUR::Por
                }
 #endif
 
-               boost::shared_ptr<ARDOUR::RouteList> routes = _session->get_routes ();
-               RouteList copy = *routes;
-               copy.sort (RouteCompareByName ());
+               RouteList copy = _session->get_routelist ();
+               copy.sort (Stripable::Sorter(true));
                uint32_t added = 0;
                for (ARDOUR::RouteList::const_iterator i = copy.begin (); i != copy.end (); ++i) {
                        added += maybe_add_route_to_input_menu (*i, p->type (), wp);
@@ -2035,6 +2084,7 @@ PluginPinDialog::add_processor (boost::weak_ptr<Processor> p)
 #endif
        if (pi) {
                ppw.push_back (PluginPinWidgetPtr(new PluginPinWidget (pi)));
+               ppw.back()->set_session (_session);
                vbox->pack_start (*ppw.back());
        } else {
                HBox* hbox = manage (new HBox ());