changes to waveform clipping display
[ardour.git] / gtk2_ardour / generic_pluginui.cc
index 8341883e9bbed801bb097739a4d96dd9686a7e70..52bb468a676a59054af654a1a03489113d25debe 100644 (file)
@@ -88,7 +88,8 @@ GenericPluginUI::GenericPluginUI (boost::shared_ptr<PluginInsert> pi, bool scrol
        set_latency_label ();
 
        smaller_hbox->pack_start (latency_button, false, false, 10);
-       smaller_hbox->pack_start (_preset_box, false, false);
+       smaller_hbox->pack_start (_preset_combo, false, false);
+       smaller_hbox->pack_start (_preset_modified, false, false);
        smaller_hbox->pack_start (add_button, false, false);
        smaller_hbox->pack_start (save_button, false, false);
        smaller_hbox->pack_start (delete_button, false, false);
@@ -100,6 +101,9 @@ GenericPluginUI::GenericPluginUI (boost::shared_ptr<PluginInsert> pi, bool scrol
        VBox* v1_box = manage (new VBox);
        VBox* v2_box = manage (new VBox);
        pack_end (plugin_analysis_expander, false, false);
+       if (!plugin->get_docs().empty()) {
+               pack_end (description_expander, false, false);
+       }
 
        v1_box->pack_start (*smaller_hbox, false, true);
        v2_box->pack_start (focus_button, false, true);
@@ -112,7 +116,7 @@ GenericPluginUI::GenericPluginUI (boost::shared_ptr<PluginInsert> pi, bool scrol
        main_contents.pack_start (*constraint_hbox, false, false);
 
        if (is_scrollable ) {
-               scroller.set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
+               scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
                scroller.set_name ("PluginEditor");
                scroller_view.set_name("PluginEditor");
                scroller_view.add (hpacker);
@@ -126,11 +130,7 @@ GenericPluginUI::GenericPluginUI (boost::shared_ptr<PluginInsert> pi, bool scrol
 
        pi->ActiveChanged.connect (active_connection, invalidator (*this), boost::bind (&GenericPluginUI::processor_active_changed, this, boost::weak_ptr<Processor>(pi)), gui_context());
 
-       if (!pi->active()) {
-               bypass_button.set_active_state (Gtkmm2ext::Active);
-       } else {
-               bypass_button.unset_active_state ();
-       }
+       bypass_button.set_active (!pi->active());
 
        prefheight = 0;
        build ();
@@ -256,6 +256,10 @@ GenericPluginUI::build ()
                                continue;
                        }
 
+                       if (plugin->describe_parameter (Evoral::Parameter(PluginAutomation, 0, i)) == X_("hidden")) {
+                               continue;
+                       }
+
                        ControlUI* cui;
 
                        boost::shared_ptr<ARDOUR::AutomationControl> c
@@ -267,6 +271,11 @@ GenericPluginUI::build ()
                                continue;
                        }
 
+                       const std::string param_docs = plugin->get_parameter_docs(i);
+                       if (!param_docs.empty()) {
+                               ARDOUR_UI::instance()->set_tip(cui, param_docs.c_str());
+                       }
+
                        if (cui->controller || cui->clickbox || cui->combo) {
                                // Get all of the controls into a list, so that
                                // we can lay them out a bit more nicely later.
@@ -442,9 +451,8 @@ GenericPluginUI::automation_state_changed (ControlUI* cui)
 
        // don't lock to avoid deadlock because we're triggered by
        // AutomationControl::Changed() while the automation lock is taken
-       switch (insert->get_parameter_automation_state (cui->parameter())
-                       & (Off|Play|Touch|Write)) {
-       case Off:
+       switch (insert->get_parameter_automation_state (cui->parameter()) & (ARDOUR::Off|Play|Touch|Write)) {
+       case ARDOUR::Off:
                cui->automate_button.set_label (S_("Automation|Manual"));
                break;
        case Play:
@@ -463,9 +471,25 @@ GenericPluginUI::automation_state_changed (ControlUI* cui)
 }
 
 
-static void integer_printer (char buf[32], Adjustment &adj, void */*arg*/)
+bool
+GenericPluginUI::integer_printer (char buf[32], Adjustment &adj, ControlUI* cui)
 {
-       snprintf (buf, 32, "%.0f", adj.get_value());
+       float const v = adj.get_value ();
+       
+       if (cui->scale_points) {
+               Plugin::ScalePoints::const_iterator i = cui->scale_points->begin ();
+               while (i != cui->scale_points->end() && i->second != v) {
+                       ++i;
+               }
+
+               if (i != cui->scale_points->end ()) {
+                       snprintf (buf, 32, "%s", i->first.c_str());
+                       return true;
+               }
+       }
+               
+       snprintf (buf, 32, "%.0f", v);
+       return true;
 }
 
 void
@@ -498,15 +522,25 @@ GenericPluginUI::build_control_ui (guint32 port_index, boost::shared_ptr<Automat
 
        if (plugin->parameter_is_input(port_index)) {
 
-               /* Build a combo box */
+               /* See if there any named values for our input value */
+               control_ui->scale_points = plugin->get_scale_points (port_index);
+
+               /* If this parameter is an integer, work out the number of distinct values
+                  it can take on (assuming that lower and upper values are allowed).
+               */
+               int const steps = desc.integer_step ? (desc.upper - desc.lower + 1) / desc.step : 0;
 
-               control_ui->combo_map = plugin->get_scale_points (port_index);
+               if (control_ui->scale_points && ((steps && int (control_ui->scale_points->size()) == steps) || desc.enumeration)) {
+                       
+                       /* Either:
+                        *   a) There is a label for each possible value of this input, or
+                        *   b) This port is marked as being an enumeration.
+                        */
 
-               if (control_ui->combo_map) {
                        std::vector<std::string> labels;
                        for (
-                               ARDOUR::Plugin::ScalePoints::const_iterator i = control_ui->combo_map->begin();
-                               i != control_ui->combo_map->end();
+                               ARDOUR::Plugin::ScalePoints::const_iterator i = control_ui->scale_points->begin();
+                               i != control_ui->scale_points->end();
                                ++i) {
                                
                                labels.push_back(i->first);
@@ -569,8 +603,8 @@ GenericPluginUI::build_control_ui (guint32 port_index, boost::shared_ptr<Automat
                Adjustment* adj = control_ui->controller->adjustment();
                boost::shared_ptr<PluginInsert::PluginControl> pc = boost::dynamic_pointer_cast<PluginInsert::PluginControl> (control_ui->control);
 
-               adj->set_lower (pc->user_to_ui (desc.lower));
-               adj->set_upper (pc->user_to_ui (desc.upper));
+               adj->set_lower (pc->internal_to_interface (desc.lower));
+               adj->set_upper (pc->internal_to_interface (desc.upper));
 
                adj->set_step_increment (desc.step);
                adj->set_page_increment (desc.largestep);
@@ -578,7 +612,7 @@ GenericPluginUI::build_control_ui (guint32 port_index, boost::shared_ptr<Automat
                if (desc.integer_step) {
                        control_ui->clickbox = new ClickBox (adj, "PluginUIClickBox");
                        Gtkmm2ext::set_size_request_to_display_given_text (*control_ui->clickbox, "g9999999", 2, 2);
-                       control_ui->clickbox->set_print_func (integer_printer, 0);
+                       control_ui->clickbox->set_printer (sigc::bind (sigc::mem_fun (*this, &GenericPluginUI::integer_printer), control_ui));
                } else {
                        //sigc::slot<void,char*,uint32_t> pslot = sigc::bind (sigc::mem_fun(*this, &GenericPluginUI::print_parameter), (uint32_t) port_index);
 
@@ -593,7 +627,7 @@ GenericPluginUI::build_control_ui (guint32 port_index, boost::shared_ptr<Automat
 
                }
 
-               adj->set_value (pc->plugin_to_ui (plugin->get_parameter (port_index)));
+               adj->set_value (pc->internal_to_interface (plugin->get_parameter (port_index)));
 
                /* XXX memory leak: SliderController not destroyed by ControlUI
                   destructor, and manage() reports object hierarchy
@@ -697,7 +731,7 @@ GenericPluginUI::astate_clicked (ControlUI* cui, uint32_t /*port*/)
 
        items.clear ();
        items.push_back (MenuElem (S_("Automation|Manual"),
-                                  sigc::bind (sigc::mem_fun(*this, &GenericPluginUI::set_automation_state), (AutoState) Off, cui)));
+                                  sigc::bind (sigc::mem_fun(*this, &GenericPluginUI::set_automation_state), (AutoState) ARDOUR::Off, cui)));
        items.push_back (MenuElem (_("Play"),
                                   sigc::bind (sigc::mem_fun(*this, &GenericPluginUI::set_automation_state), (AutoState) Play, cui)));
        items.push_back (MenuElem (_("Write"),
@@ -748,8 +782,8 @@ GenericPluginUI::update_control_display (ControlUI* cui)
 
        cui->ignore_change++;
 
-       if (cui->combo && cui->combo_map) {
-               for (ARDOUR::Plugin::ScalePoints::iterator it = cui->combo_map->begin(); it != cui->combo_map->end(); ++it) {
+       if (cui->combo && cui->scale_points) {
+               for (ARDOUR::Plugin::ScalePoints::iterator it = cui->scale_points->begin(); it != cui->scale_points->end(); ++it) {
                        if (it->second == val) {
                                cui->combo->set_active_text(it->first);
                                break;
@@ -791,9 +825,9 @@ GenericPluginUI::control_port_toggled (ControlUI* cui)
 void
 GenericPluginUI::control_combo_changed (ControlUI* cui)
 {
-       if (!cui->ignore_change && cui->combo_map) {
+       if (!cui->ignore_change && cui->scale_points) {
                string value = cui->combo->get_active_text();
-               insert->automation_control (cui->parameter())->set_value ((*cui->combo_map)[value]);
+               insert->automation_control (cui->parameter())->set_value ((*cui->scale_points)[value]);
        }
 }