add vector rendition of nudge icons.
[ardour.git] / gtk2_ardour / processor_box.cc
index cb72162773fb55fb770a6d21c970fed49cef0245..71435fe9e4f437843766e59aa06a67440dea9c8e 100644 (file)
 #include "ardour/audioengine.h"
 #include "ardour/internal_return.h"
 #include "ardour/internal_send.h"
+#include "ardour/meter.h"
 #include "ardour/panner_shell.h"
 #include "ardour/plugin_insert.h"
+#include "ardour/pannable.h"
 #include "ardour/port_insert.h"
 #include "ardour/profile.h"
 #include "ardour/return.h"
@@ -71,7 +73,7 @@
 #include "return_ui.h"
 #include "route_processor_selection.h"
 #include "send_ui.h"
-#include "utils.h"
+#include "timers.h"
 
 #include "i18n.h"
 
@@ -99,21 +101,25 @@ static const uint32_t midi_port_color = 0x960909FF; //Red
 ProcessorEntry::ProcessorEntry (ProcessorBox* parent, boost::shared_ptr<Processor> p, Width w)
        : _button (ArdourButton::led_default_elements)
        , _position (PreFader)
+       , _position_num(0)
+       , _selectable(true)
        , _parent (parent)
        , _processor (p)
        , _width (w)
-       , _visual_state (Gtk::STATE_NORMAL)
        , _input_icon(true)
        , _output_icon(false)
 {
        _vbox.show ();
        
-       _button.set_diameter (3);
        _button.set_distinct_led_click (true);
+       _button.set_fallthrough_to_parent(true);
        _button.set_led_left (true);
        _button.signal_led_clicked.connect (sigc::mem_fun (*this, &ProcessorEntry::led_clicked));
        _button.set_text (name (_width));
 
+       if (boost::dynamic_pointer_cast<PeakMeter> (_processor)) {
+               _button.set_elements(ArdourButton::Element(_button.elements() & ~ArdourButton::Indicator));
+       }
        if (_processor) {
 
                _vbox.pack_start (_routing_icon);
@@ -441,7 +447,7 @@ ProcessorEntry::build_controls_menu ()
        
        for (list<Control*>::iterator i = _controls.begin(); i != _controls.end(); ++i) {
                items.push_back (CheckMenuElem ((*i)->name ()));
-               CheckMenuItem* c = dynamic_cast<CheckMenuItem*> (&items.back ());
+               Gtk::CheckMenuItem* c = dynamic_cast<Gtk::CheckMenuItem*> (&items.back ());
                c->set_active ((*i)->visible ());
                c->signal_toggled().connect (sigc::bind (sigc::mem_fun (*this, &ProcessorEntry::toggle_control_visibility), *i));
        }
@@ -467,7 +473,7 @@ ProcessorEntry::build_send_options_menu ()
        if (send) {
 
                items.push_back (CheckMenuElem (_("Link panner controls")));
-               CheckMenuItem* c = dynamic_cast<CheckMenuItem*> (&items.back ());
+               Gtk::CheckMenuItem* c = dynamic_cast<Gtk::CheckMenuItem*> (&items.back ());
                c->set_active (send->panner_shell()->is_linked_to_route());
                c->signal_toggled().connect (sigc::mem_fun (*this, &ProcessorEntry::toggle_panner_link));
 
@@ -487,7 +493,7 @@ ProcessorEntry::toggle_panner_link ()
 ProcessorEntry::Control::Control (boost::shared_ptr<AutomationControl> c, string const & n)
        : _control (c)
        , _adjustment (gain_to_slider_position_with_max (1.0, Config->get_max_gain()), 0, 1, 0.01, 0.1)
-       , _slider (&_adjustment, 0, 13, false)
+       , _slider (&_adjustment, boost::shared_ptr<PBD::Controllable>(), 0, max(13.f, rintf(13.f * ARDOUR_UI::ui_scale)))
        , _slider_persistant_tooltip (&_slider)
        , _button (ArdourButton::led_default_elements)
        , _ignore_ui_adjustment (false)
@@ -516,20 +522,36 @@ ProcessorEntry::Control::Control (boost::shared_ptr<AutomationControl> c, string
                box.add (_slider);
                _slider.show ();
 
-               double const lo = c->internal_to_interface (c->lower ());
-               double const up = c->internal_to_interface (c->upper ());
-               
+               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);
+               }
+
                _adjustment.set_lower (lo);
                _adjustment.set_upper (up);
-               _adjustment.set_step_increment ((up - lo) / 100);
-               _adjustment.set_page_increment ((up - lo) / 10);
-               _slider.set_default_value (c->internal_to_interface (c->normal ()));
+               _adjustment.set_step_increment (smallstep);
+               _adjustment.set_page_increment (largestep);
+               _slider.set_default_value (normal);
                
                _adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &Control::slider_adjusted));
                c->Changed.connect (_connection, MISSING_INVALIDATOR, boost::bind (&Control::control_changed, this), gui_context ());
        }
 
-       ARDOUR_UI::RapidScreenUpdate.connect (sigc::mem_fun (*this, &Control::control_changed));
+       Timers::rapid_connect (sigc::mem_fun (*this, &Control::control_changed));
        
        control_changed ();
        set_tooltip ();
@@ -575,7 +597,7 @@ ProcessorEntry::Control::slider_adjusted ()
                return;
        }
 
-       c->set_value (c->interface_to_internal (_adjustment.get_value ()));
+       c->set_value ( c->interface_to_internal(_adjustment.get_value ()) );
        set_tooltip ();
 }
 
@@ -611,12 +633,8 @@ ProcessorEntry::Control::control_changed ()
                
        } else {
 
-               _adjustment.set_value (c->internal_to_interface (c->get_value ()));
-               
-               stringstream s;
-               s.precision (1);
-               s.setf (ios::fixed, ios::floatfield);
-               s << c->internal_to_user (c->get_value ());
+               _adjustment.set_value (c->internal_to_interface(c->get_value ()));
+               set_tooltip ();
        }
        
        _ignore_ui_adjustment = false;
@@ -716,7 +734,7 @@ PluginInsertProcessorEntry::plugin_insert_splitting_changed ()
                        _plugin_insert->input_streams().n_audio() < _plugin_insert->natural_input_streams().n_audio()
                 )
        {
-               _routing_icon.set_size_request (-1, 7);
+               _routing_icon.set_size_request (-1, std::max (7.f, rintf(7.f * ARDOUR_UI::ui_scale)));
                _routing_icon.set_visible(true);
                _input_icon.show();
        } else {
@@ -738,6 +756,11 @@ PluginInsertProcessorEntry::hide_things ()
        plugin_insert_splitting_changed ();
 }
 
+ProcessorEntry::PortIcon::PortIcon(bool input) {
+       _input = input;
+       _ports = ARDOUR::ChanCount(ARDOUR::DataType::AUDIO, 1);
+       set_size_request (-1, std::max (2.f, rintf(2.f * ARDOUR_UI::ui_scale)));
+}
 
 bool
 ProcessorEntry::PortIcon::on_expose_event (GdkEventExpose* ev)
@@ -757,6 +780,7 @@ ProcessorEntry::PortIcon::on_expose_event (GdkEventExpose* ev)
        cairo_rectangle (cr, 0, 0, width, height);
        cairo_fill (cr);
 
+       const double dx = rint(max(2., 2. * ARDOUR_UI::ui_scale));
        if (_ports.n_total() > 1) {
                for (uint32_t i = 0; i < _ports.n_total(); ++i) {
                        if (i < _ports.n_midi()) {
@@ -771,7 +795,7 @@ ProcessorEntry::PortIcon::on_expose_event (GdkEventExpose* ev)
                                                UINT_RGBA_B_FLT(audio_port_color));
                        }
                        const float x = rintf(width * (.2f + .6f * i / (_ports.n_total() - 1.f)));
-                       cairo_rectangle (cr, x-1, 0, 3, height);
+                       cairo_rectangle (cr, x-dx * .5, 0, 1+dx, height);
                        cairo_fill(cr);
                }
        } else if (_ports.n_total() == 1) {
@@ -787,7 +811,7 @@ ProcessorEntry::PortIcon::on_expose_event (GdkEventExpose* ev)
                                        UINT_RGBA_B_FLT(audio_port_color));
                }
                const float x = rintf(width * .5);
-               cairo_rectangle (cr, x-1, 0, 3, height);
+               cairo_rectangle (cr, x-dx * .5, 0, 1+dx, height);
                cairo_fill(cr);
                cairo_stroke(cr);
        }
@@ -804,7 +828,7 @@ ProcessorEntry::RoutingIcon::on_expose_event (GdkEventExpose* ev)
        cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height);
        cairo_clip (cr);
 
-       cairo_set_line_width (cr, 1.0);
+       cairo_set_line_width (cr, max (1.f, ARDOUR_UI::ui_scale));
        cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
 
        Gtk::Allocation a = get_allocation();
@@ -1126,6 +1150,8 @@ ProcessorBox::show_processor_menu (int arg)
                                gtk_menu_item_set_submenu (controls_menu_item->gobj(), 0);
                                controls_menu_item->set_sensitive (false);
                        }
+               } else {
+                       controls_menu_item->set_sensitive (false);
                }
        }
 
@@ -1140,6 +1166,8 @@ ProcessorBox::show_processor_menu (int arg)
                                gtk_menu_item_set_submenu (send_menu_item->gobj(), 0);
                                send_menu_item->set_sensitive (false);
                        }
+               } else {
+                       send_menu_item->set_sensitive (false);
                }
        }
 
@@ -1191,14 +1219,14 @@ ProcessorBox::leave_notify (GdkEventCrossing*)
        return false;
 }
 
-void
+bool
 ProcessorBox::processor_operation (ProcessorOperation op) 
 {
        ProcSelection targets;
 
        get_selected_processors (targets);
 
-       if (targets.empty()) {
+/*     if (targets.empty()) {
 
                int x, y;
                processor_display.get_pointer (x, y);
@@ -1209,12 +1237,20 @@ ProcessorBox::processor_operation (ProcessorOperation op)
                        targets.push_back (pointer.first->processor ());
                }
        }
+*/
 
+       if ( (op == ProcessorsDelete) && targets.empty() )
+               return false;  //nothing to delete.  return false so the editor-mixer, because the user was probably intending to delete something in the editor
+       
        switch (op) {
        case ProcessorsSelectAll:
                processor_display.select_all ();
                break;
 
+       case ProcessorsSelectNone:
+               processor_display.select_none ();
+               break;
+
        case ProcessorsCopy:
                copy_processors (targets);
                break;
@@ -1252,24 +1288,17 @@ ProcessorBox::processor_operation (ProcessorOperation op)
        default:
                break;
        }
+       
+       return true;
 }
 
 ProcessorWindowProxy* 
 ProcessorBox::find_window_proxy (boost::shared_ptr<Processor> processor) const
 {
-       for (list<ProcessorWindowProxy*>::const_iterator i = _processor_window_info.begin(); i != _processor_window_info.end(); ++i) {
-               boost::shared_ptr<Processor> p = (*i)->processor().lock();
-
-               if (p && p == processor) {
-                       return (*i);
-               }
-       }
-
-       return 0;
+       return  processor->window_proxy();
 }
 
 
-
 bool
 ProcessorBox::processor_button_press_event (GdkEventButton *ev, ProcessorEntry* child)
 {
@@ -1286,7 +1315,9 @@ ProcessorBox::processor_button_press_event (GdkEventButton *ev, ProcessorEntry*
                if (_session->engine().connected()) {
                        /* XXX giving an error message here is hard, because we may be in the midst of a button press */
 
-                       if (!one_processor_can_be_edited ()) return true;
+                       if (!one_processor_can_be_edited ()) {
+                               return true;
+                       }
 
                        if (Keyboard::modifier_state_equals (ev->state, Keyboard::SecondaryModifier)) {
                                generic_edit_processor (processor);
@@ -1297,6 +1328,12 @@ ProcessorBox::processor_button_press_event (GdkEventButton *ev, ProcessorEntry*
 
                ret = true;
 
+       } else if (Keyboard::is_context_menu_event (ev)) {
+
+               show_processor_menu (ev->time);
+               
+               ret = true;
+
        } else if (processor && ev->button == 1 && selected) {
 
                // this is purely informational but necessary for route params UI
@@ -1325,10 +1362,6 @@ ProcessorBox::processor_button_release_event (GdkEventButton *ev, ProcessorEntry
                                sigc::mem_fun(*this, &ProcessorBox::idle_delete_processor),
                                boost::weak_ptr<Processor>(processor)));
 
-       } else if (Keyboard::is_context_menu_event (ev)) {
-
-               show_processor_menu (ev->time);
-
        } else if (processor && Keyboard::is_button2_event (ev)
 #ifndef GTKOSX
                   && (Keyboard::no_modifier_keys_pressed (ev) && ((ev->state & Gdk::BUTTON2_MASK) == Gdk::BUTTON2_MASK))
@@ -1454,7 +1487,8 @@ ProcessorBox::choose_insert ()
 void
 ProcessorBox::choose_send ()
 {
-       boost::shared_ptr<Send> send (new Send (*_session, _route->pannable(), _route->mute_master()));
+       boost::shared_ptr<Pannable> sendpan(new Pannable (*_session));
+       boost::shared_ptr<Send> send (new Send (*_session, sendpan, _route->mute_master()));
 
        /* make an educated guess at the initial number of outputs for the send */
        ChanCount outs = (_session->master_out())
@@ -1593,56 +1627,7 @@ ProcessorBox::redisplay_processors ()
                                               &_visible_prefader_processors, &fader_seen));
 
        _route->foreach_processor (sigc::mem_fun (*this, &ProcessorBox::add_processor_to_display));
-
-       for (ProcessorWindowProxies::iterator i = _processor_window_info.begin(); i != _processor_window_info.end(); ++i) {
-               (*i)->marked = false;
-       }
-
        _route->foreach_processor (sigc::mem_fun (*this, &ProcessorBox::maybe_add_processor_to_ui_list));
-
-       /* trim dead wood from the processor window proxy list */
-
-       ProcessorWindowProxies::iterator i = _processor_window_info.begin();
-       while (i != _processor_window_info.end()) {
-               ProcessorWindowProxies::iterator j = i;
-               ++j;
-
-               if (!(*i)->valid()) {
-
-                       WM::Manager::instance().remove (*i);
-                       delete *i;
-                       _processor_window_info.erase (i);
-                       
-               } else if (!(*i)->marked) {
-
-                       /* this processor is no longer part of this processor
-                        * box.
-                        *
-                        * that could be because it was deleted or it could be
-                        * because the route being displayed in the parent
-                        * strip changed.
-                        *
-                        * The latter only happens with the editor mixer strip.
-                        */
-
-                       if (is_editor_mixer_strip()) {
-                               
-                               /* editor mixer strip .. DO NOTHING
-                                *
-                                * note: the processor window stays visible if
-                                * it is already visible
-                                */
-                       } else {
-                               (*i)->hide ();
-                               WM::Manager::instance().remove (*i);
-                               delete *i;
-                               _processor_window_info.erase (i);
-                       } 
-               } 
-
-               i = j;
-       }
-
        setup_entry_positions ();
 }
 
@@ -1656,24 +1641,14 @@ ProcessorBox::maybe_add_processor_to_ui_list (boost::weak_ptr<Processor> w)
        if (!p) {
                return;
        }
-
-       ProcessorWindowProxies::iterator i = _processor_window_info.begin ();
-       while (i != _processor_window_info.end()) {
-
-               boost::shared_ptr<Processor> t = (*i)->processor().lock ();
-
-               if (p == t) {
-                       /* this processor is already on the list; done */
-                       (*i)->marked = true;
-                       return;
-               }
-
-               ++i;
+       if (p->window_proxy()) {
+               return;
        }
 
        /* not on the list; add it */
 
        string loc;
+#if 0 // is this still needed? Why?
        if (_parent_strip) {
                if (_parent_strip->mixer_owned()) {
                        loc = X_("M");
@@ -1683,6 +1658,9 @@ ProcessorBox::maybe_add_processor_to_ui_list (boost::weak_ptr<Processor> w)
        } else {
                loc = X_("P");
        }
+#else
+       loc = X_("P");
+#endif
 
        ProcessorWindowProxy* wp = new ProcessorWindowProxy (
                string_compose ("%1-%2-%3", loc, _route->id(), p->id()),
@@ -1695,19 +1673,13 @@ ProcessorBox::maybe_add_processor_to_ui_list (boost::weak_ptr<Processor> w)
                wp->set_state (*ui_xml);
        }
        
-       wp->marked = true;
-
-        /* if the processor already has an existing UI,
-           note that so that we don't recreate it
-        */
-
         void* existing_ui = p->get_ui ();
 
         if (existing_ui) {
                 wp->use_window (*(reinterpret_cast<Gtk::Window*>(existing_ui)));
         }
 
-       _processor_window_info.push_back (wp);
+       p->set_window_proxy (wp);
        WM::Manager::instance().register_window (wp);
 }
 
@@ -1738,6 +1710,7 @@ ProcessorBox::add_processor_to_display (boost::weak_ptr<Processor> p)
        }
 
        boost::shared_ptr<PluginInsert> plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (processor);
+       
        ProcessorEntry* e = 0;
        if (plugin_insert) {
                e = new PluginInsertProcessorEntry (this, plugin_insert, _width);
@@ -1745,14 +1718,32 @@ ProcessorBox::add_processor_to_display (boost::weak_ptr<Processor> p)
                e = new ProcessorEntry (this, processor, _width);
        }
 
+       boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (processor);
+       boost::shared_ptr<PortInsert> ext = boost::dynamic_pointer_cast<PortInsert> (processor);
+       
+       //faders and meters are not deletable, copy/paste-able, so they shouldn't be selectable
+       if (!send && !plugin_insert && !ext)
+               e->set_selectable(false);
+
+       bool mark_send_visible = false;
+       if (send && _parent_strip) {
+               /* show controls of new sends by default */
+               GUIObjectState& st = _parent_strip->gui_object_state ();
+               XMLNode* strip = st.get_or_add_node (_parent_strip->state_id ());
+               assert (strip);
+               /* check if state exists, if not it must be a new send */
+               if (!st.get_node(strip, e->state_id())) {
+                       mark_send_visible = true;
+               }
+       }
+
        /* Set up this entry's state from the GUIObjectState */
        XMLNode* proc = entry_gui_object_state (e);
        if (proc) {
                e->set_control_state (proc);
        }
-       
-       if (boost::dynamic_pointer_cast<Send> (processor)) {
-               /* Always show send controls */
+
+       if (mark_send_visible) {
                e->show_all_controls ();
        }
 
@@ -2103,9 +2094,10 @@ ProcessorBox::paste_processor_state (const XMLNodeList& nlist, boost::shared_ptr
                                        continue;
                                }
 
+                               boost::shared_ptr<Pannable> sendpan(new Pannable (*_session));
                                XMLNode n (**niter);
-                                InternalSend* s = new InternalSend (*_session, _route->pannable(), _route->mute_master(),
-                                                                   boost::shared_ptr<Route>(), Delivery::Aux); 
+                               InternalSend* s = new InternalSend (*_session, sendpan, _route->mute_master(),
+                                               _route, boost::shared_ptr<Route>(), Delivery::Aux);
 
                                IOProcessor::prepare_for_reset (n, s->name());
 
@@ -2118,7 +2110,9 @@ ProcessorBox::paste_processor_state (const XMLNodeList& nlist, boost::shared_ptr
 
                        } else if (type->value() == "send") {
 
+                               boost::shared_ptr<Pannable> sendpan(new Pannable (*_session));
                                XMLNode n (**niter);
+
                                Send* s = new Send (*_session, _route->pannable(), _route->mute_master());
 
                                IOProcessor::prepare_for_reset (n, s->name());
@@ -2812,16 +2806,10 @@ ProcessorBox::generate_processor_title (boost::shared_ptr<PluginInsert> pi)
 Window *
 ProcessorBox::get_processor_ui (boost::shared_ptr<Processor> p) const
 {
-       list<ProcessorWindowProxy*>::const_iterator i = _processor_window_info.begin ();
-       while (i != _processor_window_info.end()) {
-               boost::shared_ptr<Processor> t = (*i)->processor().lock ();
-               if (t && t == p) {
-                       return (*i)->get ();
-               }
-
-               ++i;
+       ProcessorWindowProxy* wp = p->window_proxy();
+       if (wp) {
+               return wp->get ();
        }
-
        return 0;
 }
 
@@ -2832,24 +2820,9 @@ ProcessorBox::get_processor_ui (boost::shared_ptr<Processor> p) const
 void
 ProcessorBox::set_processor_ui (boost::shared_ptr<Processor> p, Gtk::Window* w)
 {
-       list<ProcessorWindowProxy*>::iterator i = _processor_window_info.begin ();
-
+       assert (p->window_proxy());
        p->set_ui (w);
-
-       while (i != _processor_window_info.end()) {
-               boost::shared_ptr<Processor> t = (*i)->processor().lock ();
-               if (t && t == p) {
-                       (*i)->use_window (*w);
-                       return;
-               }
-
-               ++i;
-       }
-
-       /* we shouldn't get here, because the ProcessorUIList should always contain
-          an entry for each processor.
-       */
-       assert (false);
+       p->window_proxy()->use_window (*w);
 }
 
 void
@@ -2924,12 +2897,10 @@ ProcessorBox::is_editor_mixer_strip() const
 
 ProcessorWindowProxy::ProcessorWindowProxy (string const & name, ProcessorBox* box, boost::weak_ptr<Processor> processor)
        : WM::ProxyBase (name, string())
-       , marked (false)
        , _processor_box (box)
        , _processor (processor)
        , is_custom (false)
        , want_custom (false)
-       , _valid (true)
 {
        boost::shared_ptr<Processor> p = _processor.lock ();
        if (!p) {
@@ -2952,7 +2923,7 @@ ProcessorWindowProxy::processor_going_away ()
 {
        delete _window;
        _window = 0;
-       _valid = false;
+       WM::Manager::instance().remove (this);
        /* should be no real reason to do this, since the object that would
           send DropReferences is about to be deleted, but lets do it anyway.
        */
@@ -2966,12 +2937,6 @@ ProcessorWindowProxy::session_handle()
        return 0;
 }
 
-bool
-ProcessorWindowProxy::valid() const
-{
-       return _valid;
-}
-
 XMLNode&
 ProcessorWindowProxy::get_state () const
 {