a-fluidsynth: implement LV2_BANKPATCH__notify
[ardour.git] / gtk2_ardour / generic_pluginui.cc
index 1bd682a0a8afd74a9c74474fb250835e762bc0ce..ffb4a2cc9216039479c2b33e4b8afd2282d45cd8 100644 (file)
@@ -49,6 +49,7 @@
 #include "widgets/tooltips.h"
 
 #include "plugin_ui.h"
+#include "plugin_display.h"
 #include "gui_thread.h"
 #include "automation_controller.h"
 #include "gain_meter.h"
@@ -137,23 +138,29 @@ GenericPluginUI::GenericPluginUI (boost::shared_ptr<PluginInsert> pi, bool scrol
 
        main_contents.pack_start (*constraint_hbox, false, false);
 
-       if (is_scrollable) {
-               Gtk::ScrolledWindow *scroller = manage (new Gtk::ScrolledWindow());
-               scroller->set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
-               scroller->set_name ("PluginEditor");
-               scroller->add (hpacker);
-               main_contents.pack_start (*scroller, true, true);
-       } else {
-               main_contents.pack_start (hpacker, false, false);
-       }
-
        pi->ActiveChanged.connect (active_connection, invalidator (*this), boost::bind (&GenericPluginUI::processor_active_changed, this, boost::weak_ptr<Processor>(pi)), gui_context());
 
        bypass_button.set_active (!pi->enabled());
 
+       /* ScrolledWindow will wrap hpacker in a Viewport */
+       scroller.add (hpacker);
+       Viewport* view = static_cast<Viewport*>(scroller.get_child());
+       view->set_shadow_type(Gtk::SHADOW_NONE);
+
+       main_contents.pack_start (scroller, true, true);
+
        prefheight = 0;
        build ();
 
+       if (is_scrollable) {
+               scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
+               scroller.set_name ("PluginEditor");
+       } else {
+               scroller.signal_size_request().connect (sigc::mem_fun(*this, &GenericPluginUI::scroller_size_request));
+               scroller.set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_NEVER);
+       }
+
+
        /* Listen for property changes that are not notified normally because
         * AutomationControl has only support for numeric values currently.
         * The only case is Variant::PATH for now */
@@ -171,6 +178,39 @@ GenericPluginUI::~GenericPluginUI ()
        }
 }
 
+void
+GenericPluginUI::scroller_size_request (Gtk::Requisition* a)
+{
+       Glib::RefPtr<Gdk::Screen> screen = get_screen();
+       if (!screen)
+               screen = Gdk::Screen::get_default();
+
+       int maximum_width;
+       {
+               Gdk::Rectangle monitor;
+               const int monitor_num = screen->get_monitor_at_window (get_window ());
+               screen->get_monitor_geometry (
+                               (monitor_num < 0) ? 0 : monitor_num,
+                               monitor);
+
+               maximum_width = monitor.get_width() * 0.9;
+       }
+
+       GtkRequisition request = hpacker.size_request();
+
+       if (request.width > maximum_width) {
+               for (vector<ControlUI*>::const_iterator cuip = input_controls.begin();
+                                                       cuip != input_controls.end();
+                                                       ++cuip) {
+                       if (!(*cuip)->short_autostate)
+                               set_short_autostate(*cuip, true);
+               }
+               request = hpacker.size_request();
+       }
+
+       a->width = min(request.width, maximum_width);
+}
+
 // Some functions for calculating the 'similarity' of two plugin
 // control labels.
 
@@ -527,6 +567,11 @@ GenericPluginUI::automatic_layout (const std::vector<ControlUI*>& control_uis)
        } else {
                delete output_table;
        }
+
+       if (plugin->has_inline_display () && plugin->inline_display_in_gui ()) {
+               PluginDisplay* pd = manage (new PluginDisplay (plugin, 300));
+               hpacker.pack_end (*pd, true, true);
+       }
        show_all();
 
 }
@@ -544,6 +589,11 @@ GenericPluginUI::custom_layout (const std::vector<ControlUI*>& control_uis)
                layout->attach (*cui, cui->x0, cui->x1, cui->y0, cui->y1, FILL, SHRINK, 2, 2);
        }
        hpacker.pack_start (*layout, true, true);
+
+       if (plugin->has_inline_display () && plugin->inline_display_in_gui ()) {
+               PluginDisplay* pd = manage (new PluginDisplay (plugin, 300));
+               hpacker.pack_end (*pd, true, true);
+       }
 }
 
 GenericPluginUI::ControlUI::ControlUI (const Evoral::Parameter& p)
@@ -562,13 +612,6 @@ GenericPluginUI::ControlUI::ControlUI (const Evoral::Parameter& p)
        automate_button.set_name ("plugin automation state button");
        set_tooltip (automate_button, _("Automation control"));
 
-       /* XXX translators: use a string here that will be at least as long
-          as the longest automation label (see ::automation_state_changed()
-          below). be sure to include a descender.
-       */
-
-       automate_button.set_sizing_text(_("Mgnual"));
-
        ignore_change = false;
        update_pending = false;
        button = false;
@@ -584,6 +627,21 @@ GenericPluginUI::ControlUI::~ControlUI()
        }
 }
 
+void
+GenericPluginUI::set_short_autostate (ControlUI* cui, bool value)
+{
+       cui->short_autostate = value;
+       if (value) {
+               cui->automate_button.set_sizing_text("M");
+       } else {
+               /* XXX translators: use a string here that will be at least as long
+                  as the longest automation label (see ::automation_state_changed()
+                  below). be sure to include a descender. */
+               cui->automate_button.set_sizing_text(_("Mgnual"));
+       }
+       automation_state_changed(cui);
+}
+
 void
 GenericPluginUI::automation_state_changed (ControlUI* cui)
 {
@@ -596,7 +654,7 @@ GenericPluginUI::automation_state_changed (ControlUI* cui)
 
        cui->automate_button.set_active((state != ARDOUR::Off));
 
-       if (cui->knobtable) {
+       if (cui->short_autostate) {
                cui->automate_button.set_text (
                                GainMeterBase::astate_string (state));
                return;
@@ -667,6 +725,7 @@ GenericPluginUI::build_control_ui (const Evoral::Parameter&             param,
        control_ui->label.set_alignment (0.0, 0.5);
        control_ui->label.set_name ("PluginParameterLabel");
        control_ui->set_spacing (5);
+       set_short_autostate(control_ui, false);
 
        if (is_input) {
 
@@ -786,7 +845,7 @@ GenericPluginUI::build_control_ui (const Evoral::Parameter&             param,
                }
 
                if (use_knob) {
-                       control_ui->automate_button.set_sizing_text("M");
+                       set_short_autostate(control_ui, true);
 
                        control_ui->label.set_alignment (0.5, 0.5);
                        control_ui->knobtable = manage (new Table());