crossfade hack and slash. removed overlap checks, overlap mode, default length,...
[ardour.git] / gtk2_ardour / panner_ui.cc
index 49720d781e5480723ef74627a73a97a3bb47b834..433b5b0c0258685b48393301eedc36a82335d174 100644 (file)
 
 #include <limits.h>
 
-#include "ardour/io.h"
-#include "ardour/dB.h"
 #include <gtkmm2ext/utils.h>
 #include <gtkmm2ext/barcontroller.h>
+
 #include "midi++/manager.h"
 #include "pbd/fastlog.h"
 
+#include "ardour/pannable.h"
+#include "ardour/panner.h"
+#include "ardour/panner_shell.h"
+#include "ardour/session.h"
+
 #include "ardour_ui.h"
 #include "panner_ui.h"
 #include "panner2d.h"
 #include "stereo_panner.h"
 #include "mono_panner.h"
 
-#include "ardour/delivery.h"
-#include "ardour/session.h"
-#include "ardour/panner.h"
-#include "ardour/pannable.h"
-#include "ardour/route.h"
-
 #include "i18n.h"
 
 using namespace std;
@@ -63,6 +61,7 @@ PannerUI::PannerUI (Session* s)
        pan_astyle_menu = 0;
        in_pan_update = false;
         _stereo_panner = 0;
+       _mono_panner = 0;
         _ignore_width_change = false;
         _ignore_position_change = false;
 
@@ -91,8 +90,11 @@ PannerUI::PannerUI (Session* s)
 }
 
 void
-PannerUI::set_panner (boost::shared_ptr<Panner> p)
+PannerUI::set_panner (boost::shared_ptr<PannerShell> ps, boost::shared_ptr<Panner> p)
 {
+        /* note that the panshell might not change here (i.e. ps == _panshell)
+         */
+
        connections.drop_connections ();
 
        delete pan_astyle_menu;
@@ -101,6 +103,7 @@ PannerUI::set_panner (boost::shared_ptr<Panner> p)
        delete pan_astate_menu;
        pan_astate_menu = 0;
 
+        _panshell = ps;
        _panner = p;
 
        delete twod_panner;
@@ -113,8 +116,7 @@ PannerUI::set_panner (boost::shared_ptr<Panner> p)
                return;
        }
 
-       _panner->Changed.connect (connections, invalidator (*this), boost::bind (&PannerUI::panner_changed, this, this), gui_context());
-       _panner->StateChanged.connect (connections, invalidator (*this), boost::bind (&PannerUI::update_pan_state, this), gui_context());
+       _panshell->Changed.connect (connections, invalidator (*this), boost::bind (&PannerUI::panshell_changed, this), gui_context());
 
         /* new panner object, force complete reset of panner GUI
          */
@@ -122,10 +124,9 @@ PannerUI::set_panner (boost::shared_ptr<Panner> p)
         _current_nouts = 0;
         _current_nins = 0;
 
-       panner_changed (0);
+        setup_pan ();
        update_pan_sensitive ();
        pan_automation_state_changed ();
-
 }
 
 void
@@ -140,9 +141,12 @@ PannerUI::build_astate_menu ()
                pan_astate_menu->items().clear ();
        }
 
-       pan_astate_menu->items().push_back (MenuElem (_("Manual"), sigc::bind (
+       /** TRANSLATORS: this is `Manual' in the sense of automation not being played,
+           so that changes to pan must be done by hand.
+       */
+       pan_astate_menu->items().push_back (MenuElem (S_("Automation|Manual"), sigc::bind (
                        sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
-                       (AutoState) Off)));
+                       (AutoState) ARDOUR::Off)));
        pan_astate_menu->items().push_back (MenuElem (_("Play"), sigc::bind (
                        sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
                        (AutoState) Play)));
@@ -171,13 +175,6 @@ PannerUI::build_astyle_menu ()
        pan_astyle_menu->items().push_back (MenuElem (_("Abs")));
 }
 
-boost::shared_ptr<PBD::Controllable>
-PannerUI::get_controllable()
-{
-        assert (!pan_bars.empty());
-       return pan_bars[0]->get_controllable();
-}
-
 void
 PannerUI::on_size_allocate (Allocation& a)
 {
@@ -192,61 +189,58 @@ PannerUI::set_width (Width w)
 
 PannerUI::~PannerUI ()
 {
-       for (vector<MonoPanner*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
-               delete (*i);
-       }
-
        delete twod_panner;
        delete big_window;
        delete pan_menu;
        delete pan_astyle_menu;
        delete pan_astate_menu;
         delete _stereo_panner;
+        delete _mono_panner;
 }
 
-
 void
-PannerUI::panner_changed (void* src)
+PannerUI::panshell_changed ()
 {
+        set_panner (_panshell, _panshell->panner());
        setup_pan ();
 }
 
-void
-PannerUI::update_pan_state ()
-{
-       /* currently nothing to do */
-}
-
 void
 PannerUI::setup_pan ()
 {
-       if (!_panner) {
-               return;
-       } 
-       uint32_t const nouts = _panner->out().n_audio();
-       uint32_t const nins = _panner->in().n_audio();
+       int const nouts = _panner ? _panner->out().n_audio() : -1;
+       int const nins = _panner ? _panner->in().n_audio() : -1;
 
-       if (int32_t (nouts) == _current_nouts && int32_t (nins) == _current_nins) {
+       if (nouts == _current_nouts && nins == _current_nins) {
                return;
        }
 
+        _current_nins = nins;
+        _current_nouts = nouts;
+
         container_clear (pan_vbox);
 
         delete twod_panner;
         twod_panner = 0;
         delete _stereo_panner;
         _stereo_panner = 0;
-        
-       if (nouts == 0 || nouts == 1) {
+       delete _mono_panner;
+       _mono_panner = 0;
 
-                delete _stereo_panner;
-                delete twod_panner;
+       if (!_panner) {
+               return;
+       }
+
+       if (nouts == 0 || nouts == 1) {
 
                /* stick something into the panning viewport so that it redraws */
 
                EventBox* eb = manage (new EventBox());
                pan_vbox.pack_start (*eb, false, false);
 
+               delete big_window;
+               big_window = 0;
+
        } else if (nouts == 2) {
 
                 if (nins == 2) {
@@ -262,48 +256,50 @@ PannerUI::setup_pan ()
                         boost::shared_ptr<AutomationControl> ac;
 
                         ac = pannable->pan_azimuth_control;
-                        _stereo_panner->StartPositionGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::start_touch), 
-                                                              boost::weak_ptr<AutomationControl> (ac)));
-                        _stereo_panner->StopPositionGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::stop_touch), 
-                                                             boost::weak_ptr<AutomationControl>(ac)));
+                        _stereo_panner->StartPositionGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::start_touch),
+                                                                                  boost::weak_ptr<AutomationControl> (ac)));
+                        _stereo_panner->StopPositionGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::stop_touch),
+                                                                                 boost::weak_ptr<AutomationControl>(ac)));
 
                         ac = pannable->pan_width_control;
-                        _stereo_panner->StartWidthGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::start_touch), 
-                                                              boost::weak_ptr<AutomationControl> (ac)));
-                        _stereo_panner->StopWidthGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::stop_touch), 
-                                                             boost::weak_ptr<AutomationControl>(ac)));
+                        _stereo_panner->StartWidthGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::start_touch),
+                                                                               boost::weak_ptr<AutomationControl> (ac)));
+                        _stereo_panner->StopWidthGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::stop_touch),
+                                                                              boost::weak_ptr<AutomationControl>(ac)));
+                        _stereo_panner->signal_button_release_event().connect (sigc::mem_fun(*this, &PannerUI::pan_button_event));
 
                 } else if (nins == 1) {
                         /* 1-in/2out */
-                        
-                        MonoPanner* mp;
+
                         boost::shared_ptr<Pannable> pannable = _panner->pannable();
                         boost::shared_ptr<AutomationControl> ac = pannable->pan_azimuth_control;
-                        
-                        mp = new MonoPanner (ac);
-                        
-                        mp->StartGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::start_touch), 
+
+                        _mono_panner = new MonoPanner (_panner);
+                       
+                        _mono_panner->StartGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::start_touch),
                                                                       boost::weak_ptr<AutomationControl> (ac)));
-                        mp->StopGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::stop_touch), 
+                        _mono_panner->StopGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::stop_touch),
                                                              boost::weak_ptr<AutomationControl>(ac)));
-                        
-                        mp->signal_button_release_event().connect (sigc::mem_fun(*this, &PannerUI::pan_button_event));
-                        
-                        mp->set_size_request (-1, pan_bar_height);
-                        
+
+                        _mono_panner->signal_button_release_event().connect (sigc::mem_fun(*this, &PannerUI::pan_button_event));
+
+                        _mono_panner->set_size_request (-1, pan_bar_height);
+
                         update_pan_sensitive ();
-                        pan_vbox.pack_start (*mp, false, false);
+                        pan_vbox.pack_start (*_mono_panner, false, false);
 
                 } else {
                         warning << string_compose (_("No panner user interface is currently available for %1-in/2out tracks/busses"),
                                                    nins) << endmsg;
                 }
 
+               delete big_window;
+               big_window = 0;
 
        } else {
 
                if (!twod_panner) {
-                       twod_panner = new Panner2d (_panner, 61);
+                       twod_panner = new Panner2d (_panshell, 61);
                        twod_panner->set_name ("MixerPanZone");
                        twod_panner->show ();
                        twod_panner->signal_button_press_event().connect (sigc::mem_fun(*this, &PannerUI::pan_button_event), false);
@@ -351,7 +347,7 @@ PannerUI::pan_button_event (GdkEventButton* ev)
        case 1:
                if (twod_panner && ev->type == GDK_2BUTTON_PRESS) {
                        if (!big_window) {
-                               big_window = new Panner2dWindow (_panner, 400, _panner->in().n_audio());
+                               big_window = new Panner2dWindow (_panshell, 400, _panner->in().n_audio());
                        }
                        big_window->show ();
                        return true;
@@ -387,17 +383,28 @@ PannerUI::build_pan_menu ()
 
        /* set state first, connect second */
 
-       bypass_menu_item->set_active (_panner->bypassed());
+       bypass_menu_item->set_active (_panshell->bypassed());
        bypass_menu_item->signal_toggled().connect (sigc::mem_fun(*this, &PannerUI::pan_bypass_toggle));
 
        items.push_back (MenuElem (_("Reset"), sigc::mem_fun (*this, &PannerUI::pan_reset)));
+       items.push_back (MenuElem (_("Edit..."), sigc::mem_fun (*this, &PannerUI::pan_edit)));
 }
 
 void
 PannerUI::pan_bypass_toggle ()
 {
-       if (bypass_menu_item && (_panner->bypassed() != bypass_menu_item->get_active())) {
-               _panner->set_bypassed (!_panner->bypassed());
+       if (bypass_menu_item && (_panshell->bypassed() != bypass_menu_item->get_active())) {
+               _panshell->set_bypassed (!_panshell->bypassed());
+       }
+}
+
+void
+PannerUI::pan_edit ()
+{
+       if (_mono_panner) {
+               _mono_panner->edit ();
+       } else if (_stereo_panner) {
+               _stereo_panner->edit ();
        }
 }
 
@@ -414,11 +421,7 @@ PannerUI::effective_pan_display ()
                 _stereo_panner->queue_draw ();
         } else if (twod_panner) {
                 twod_panner->queue_draw ();
-        } else {
-                for (vector<MonoPanner*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
-                        (*i)->queue_draw ();
-                }
-       }
+        }
 }
 
 void
@@ -426,9 +429,8 @@ PannerUI::update_pan_sensitive ()
 {
        bool const sensitive = !(_panner->pannable()->automation_state() & Play);
 
-#ifdef PANNER_HACKS
         pan_vbox.set_sensitive (sensitive);
-#endif
+
         if (big_window) {
                 big_window->set_sensitive (sensitive);
         }
@@ -506,8 +508,8 @@ PannerUI::pan_automation_state_changed ()
                break;
        }
 
-       bool x = (pannable->automation_state() != Off);
-        
+       bool x = (pannable->automation_state() != ARDOUR::Off);
+
        if (pan_automation_state_button.get_active() != x) {
                 ignore_toggle = true;
                pan_automation_state_button.set_active (x);
@@ -515,11 +517,11 @@ PannerUI::pan_automation_state_changed ()
        }
 
        update_pan_sensitive ();
-        
+
        /* start watching automation so that things move */
-        
+
        pan_watching.disconnect();
-        
+
        if (x) {
                pan_watching = ARDOUR_UI::RapidScreenUpdate.connect (sigc::mem_fun (*this, &PannerUI::effective_pan_display));
        }
@@ -543,7 +545,7 @@ PannerUI::_astate_string (AutoState state, bool shrt)
        string sstr;
 
        switch (state) {
-       case Off:
+       case ARDOUR::Off:
                sstr = (shrt ? "M" : _("M"));
                break;
        case Play: