add editor to Theme Manager for modifiers
[ardour.git] / gtk2_ardour / processor_box.cc
index 1fdad0801dc86deac9ee60d311cc7e59e98d2b3b..361945d5e0f8de57f93317dbcb8b4750cf39e4ee 100644 (file)
@@ -108,7 +108,6 @@ ProcessorEntry::ProcessorEntry (ProcessorBox* parent, boost::shared_ptr<Processo
        , _parent (parent)
        , _processor (p)
        , _width (w)
-       , _visual_state (Gtk::STATE_NORMAL)
        , _input_icon(true)
        , _output_icon(false)
 {
@@ -493,7 +492,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)
+       , _slider (&_adjustment, boost::shared_ptr<PBD::Controllable>(), 0, 13)
        , _slider_persistant_tooltip (&_slider)
        , _button (ArdourButton::led_default_elements)
        , _ignore_ui_adjustment (false)
@@ -522,14 +521,30 @@ 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 ());
@@ -1273,19 +1288,10 @@ ProcessorBox::processor_operation (ProcessorOperation op)
 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)
 {
@@ -1612,56 +1618,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 ();
 }
 
@@ -1675,24 +1632,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");
@@ -1702,6 +1649,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()),
@@ -1714,19 +1664,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);
 }
 
@@ -2842,16 +2786,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;
 }
 
@@ -2862,24 +2800,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
@@ -2954,12 +2877,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) {
@@ -2982,7 +2903,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.
        */
@@ -2996,12 +2917,6 @@ ProcessorWindowProxy::session_handle()
        return 0;
 }
 
-bool
-ProcessorWindowProxy::valid() const
-{
-       return _valid;
-}
-
 XMLNode&
 ProcessorWindowProxy::get_state () const
 {