Apply panners/automation patch from torbenh (Panner is-a Processor).
[ardour.git] / gtk2_ardour / panner_ui.cc
index 6c10137548f65061b754c5b88cae18cdc40b5f9a..2be7be73ed43398c0fe38449d21bf05858837939 100644 (file)
@@ -14,8 +14,6 @@
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-  $Id$
 */
 
 #include <limits.h>
@@ -32,6 +30,7 @@
 #include "panner_ui.h"
 #include "panner2d.h"
 #include "utils.h"
+#include "panner.h"
 #include "gui_thread.h"
 
 #include <ardour/session.h>
 #include "i18n.h"
 
 using namespace ARDOUR;
+using namespace PBD;
 using namespace Gtkmm2ext;
 using namespace Gtk;
 using namespace sigc;
 
+const int PannerUI::pan_bar_height = 30;
 
-PannerUI::PannerUI (IO& io, Session& s)
+PannerUI::PannerUI (boost::shared_ptr<IO> io, Session& s)
        : _io (io),
          _session (s),
          hAdjustment(0.0, 0.0, 0.0),
@@ -68,12 +69,11 @@ PannerUI::PannerUI (IO& io, Session& s)
        ARDOUR_UI::instance()->tooltips().set_tip (pan_automation_state_button, _("Pan automation mode"));
        ARDOUR_UI::instance()->tooltips().set_tip (pan_automation_style_button, _("Pan automation type"));
 
-       set_size_request_to_display_given_text (pan_automation_state_button, X_("M"), 2, 2);
-       set_size_request_to_display_given_text (pan_automation_style_button, X_("M"), 2, 2);
+       //set_size_request_to_display_given_text (pan_automation_state_button, X_("O"), 2, 2);
+       //set_size_request_to_display_given_text (pan_automation_style_button, X_("0"), 2, 2);
 
        pan_bar_packer.set_size_request (-1, 61);
-       panning_viewport.set_size_request (61, 61);
-
+       panning_viewport.set_size_request (-1, 61);
        panning_viewport.set_name (X_("BaseFrame"));
 
        ARDOUR_UI::instance()->tooltips().set_tip (panning_link_button,
@@ -86,13 +86,13 @@ PannerUI::PannerUI (IO& io, Session& s)
 
        using namespace Menu_Helpers;
        pan_astate_menu.items().push_back (MenuElem (_("Manual"), 
-                                                    bind (mem_fun (_io.panner(), &Panner::set_automation_state), (AutoState) Off)));
+                                                    bind (mem_fun (_io->panner(), &Panner::set_automation_state), (AutoState) Off)));
        pan_astate_menu.items().push_back (MenuElem (_("Play"),
-                                                    bind (mem_fun (_io.panner(), &Panner::set_automation_state), (AutoState) Play)));
+                                                    bind (mem_fun (_io->panner(), &Panner::set_automation_state), (AutoState) Play)));
        pan_astate_menu.items().push_back (MenuElem (_("Write"),
-                                                    bind (mem_fun (_io.panner(), &Panner::set_automation_state), (AutoState) Write)));
+                                                    bind (mem_fun (_io->panner(), &Panner::set_automation_state), (AutoState) Write)));
        pan_astate_menu.items().push_back (MenuElem (_("Touch"),
-                                                    bind (mem_fun (_io.panner(), &Panner::set_automation_state), (AutoState) Touch)));
+                                                    bind (mem_fun (_io->panner(), &Panner::set_automation_state), (AutoState) Touch)));
 
        pan_astyle_menu.items().push_back (MenuElem (_("Trim")));
        pan_astyle_menu.items().push_back (MenuElem (_("Abs")));
@@ -103,29 +103,25 @@ PannerUI::PannerUI (IO& io, Session& s)
        pan_automation_style_button.signal_button_press_event().connect (mem_fun(*this, &PannerUI::pan_automation_style_button_event), false);
        pan_automation_state_button.signal_button_press_event().connect (mem_fun(*this, &PannerUI::pan_automation_state_button_event), false);
 
-       Gtk::HBox* pan_button_hbox = manage (new Gtk::HBox());
+       panning_link_button.set_name (X_("PanningLinkButton"));
+       panning_link_direction_button.set_name (X_("PanningLinkDirectionButton"));
 
        panning_link_box.pack_start (panning_link_button, true, true);
        panning_link_box.pack_start (panning_link_direction_button, true, true);
-       pan_button_hbox->pack_start (panning_link_box, true, true);
-       pan_button_hbox->pack_start (pan_automation_state_button, true, true);
-
-       panning_link_button.set_name (X_("PanningLinkButton"));
-       panning_link_direction_button.set_name (X_("PanningLinkDirectionButton"));
+       panning_link_box.pack_start (pan_automation_state_button, true, true);
 
        /* the pixmap will be reset at some point, but the key thing is that
           we need a pixmap in the button just to get started.
        */
-
        panning_link_direction_button.add (*(manage (new Image (get_xpm("forwardblarrow.xpm")))));
 
        panning_link_direction_button.signal_clicked().connect
                (mem_fun(*this, &PannerUI::panning_link_direction_clicked));
 
        panning_link_button.signal_button_press_event().connect
-               (mem_fun(*this, &PannerUI::panning_link_button_press));
+               (mem_fun(*this, &PannerUI::panning_link_button_press), false);
        panning_link_button.signal_button_release_event().connect
-               (mem_fun(*this, &PannerUI::panning_link_button_release));
+               (mem_fun(*this, &PannerUI::panning_link_button_release), false);
 
        panning_up.set_border_width (3);
        panning_down.set_border_width (3);
@@ -136,48 +132,72 @@ PannerUI::PannerUI (IO& io, Session& s)
        panning_up_arrow.set_name (X_("PanScrollerArrow"));
        panning_down_arrow.set_name (X_("PanScrollerArrow"));
 
-       pan_vbox.set_spacing (4);
+       pan_vbox.set_spacing (2);
        pan_vbox.pack_start (panning_viewport, Gtk::PACK_SHRINK);
-       pan_vbox.pack_start (*pan_button_hbox, Gtk::PACK_SHRINK);
+       pan_vbox.pack_start (panning_link_box, Gtk::PACK_SHRINK);
 
-       pack_start (pan_vbox, true, false);
+       pack_start (pan_vbox, true, true);
 
        panner = 0;
 
-       _io.panner().Changed.connect (mem_fun(*this, &PannerUI::panner_changed));
-       _io.panner().LinkStateChanged.connect (mem_fun(*this, &PannerUI::update_pan_linkage));
-       _io.panner().StateChanged.connect (mem_fun(*this, &PannerUI::update_pan_state));
+       set_width(Narrow);
+
+       _io->panner().Changed.connect (mem_fun(*this, &PannerUI::panner_changed));
+       _io->panner().LinkStateChanged.connect (mem_fun(*this, &PannerUI::update_pan_linkage));
+       _io->panner().StateChanged.connect (mem_fun(*this, &PannerUI::update_pan_state));
 
        pan_changed (0);
        update_pan_sensitive ();
        update_pan_linkage ();
        pan_automation_state_changed ();
+
+       pan_bar_packer.show();
+       panning_viewport.show();
+       panning_up.show();
+       panning_up_arrow.show();
+       panning_down.show();
+       panning_down_arrow.show();
+       pan_vbox.show();
+       panning_link_button.show();
+       panning_link_direction_button.show();
+       panning_link_box.show();
+       pan_automation_style_button.show();
+       pan_automation_state_button.show();
+       show();
 }
 
-gint
+boost::shared_ptr<PBD::Controllable>
+PannerUI::get_controllable() 
+{ 
+       return pan_bars[0]->get_controllable();
+}
+
+bool
 PannerUI::panning_link_button_press (GdkEventButton* ev)
 {
-       return stop_signal (panning_link_button, "button-press-event");
+       cerr << "link press\n";
+       return true;
 }
 
-gint
+bool
 PannerUI::panning_link_button_release (GdkEventButton* ev)
 {
+       cerr << "link release\n";
        if (!ignore_toggle) {
-               _io.panner().set_linked (!_io.panner().linked());
+               _io->panner().set_linked (!_io->panner().linked());
        }
-       return TRUE;
+       return true;
 }
 
 void
 PannerUI::panning_link_direction_clicked()
 {
-       switch (_io.panner().link_direction()) {
+       switch (_io->panner().link_direction()) {
        case Panner::SameDirection:
-               _io.panner().set_link_direction (Panner::OppositeDirection);
+               _io->panner().set_link_direction (Panner::OppositeDirection);
                break;
        default:
-               _io.panner().set_link_direction (Panner::SameDirection);
+               _io->panner().set_link_direction (Panner::SameDirection);
                break;
        }
 }
@@ -187,7 +207,7 @@ PannerUI::update_pan_linkage ()
 {
        ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::update_pan_linkage));
        
-       bool x = _io.panner().linked();
+       bool x = _io->panner().linked();
        bool bx = panning_link_button.get_active();
        
        if (x != bx) {
@@ -199,7 +219,7 @@ PannerUI::update_pan_linkage ()
 
        panning_link_direction_button.set_sensitive (x);
 
-       switch (_io.panner().link_direction()) {
+       switch (_io->panner().link_direction()) {
        case Panner::SameDirection:
                panning_link_direction_button.set_image (*(manage (new Image (get_xpm ("forwardblarrow.xpm")))));
                break;
@@ -214,23 +234,9 @@ PannerUI::set_width (Width w)
 {
        switch (w) {
        case Wide:
-               panning_viewport.set_size_request (61, 61);
-               if (panner) {
-                       panner->set_size_request (61, 61);
-               }
-               for (vector<BarController*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
-                               (*i)->set_size_request (61, 15);
-               }
                panning_link_button.set_label (_("link"));
                break;
        case Narrow:
-               panning_viewport.set_size_request (31, 61);
-               if (panner) {
-                       panner->set_size_request (31, 61);
-               }
-               for (vector<BarController*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
-                               (*i)->set_size_request (31, 15);
-               }
                panning_link_button.set_label (_("L"));
                break;
        }
@@ -245,7 +251,7 @@ PannerUI::~PannerUI ()
                delete (*i);
        }
        
-       for (vector<BarController*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
+       for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
                delete (*i);
        }
 
@@ -277,7 +283,7 @@ PannerUI::update_pan_state ()
 void
 PannerUI::setup_pan ()
 {
-       uint32_t nouts = _io.n_outputs ();
+       uint32_t nouts = _io->n_outputs ().n_audio();
 
        if (nouts == 0 || nouts == 1) {
 
@@ -288,10 +294,17 @@ PannerUI::setup_pan ()
                        pan_adjustments.pop_back ();
                }
 
+               /* stick something into the panning viewport so that it redraws */
+
+               EventBox* eb = manage (new EventBox());
+               panning_viewport.remove ();
+               panning_viewport.add (*eb);
+               panning_viewport.show_all ();
+
        } else if (nouts == 2) {
 
                vector<Adjustment*>::size_type asz;
-               uint32_t npans = _io.panner().size();
+               uint32_t npans = _io->panner().npanners();
 
                while (!pan_adjustments.empty()) {
                        delete pan_bars.back();
@@ -302,55 +315,52 @@ PannerUI::setup_pan ()
 
                while ((asz = pan_adjustments.size()) < npans) {
 
-                       float x;
-                       BarController* bc;
+                       float x, rx;
+                       PannerBar* bc;
+
+                       /* initialize adjustment with 0.0 (L) or 1.0 (R) for the first and second panners,
+                          which serves as a default, otherwise use current value */
 
-                       /* initialize adjustment with current value of panner */
+                       rx = _io->panner().pan_control( asz)->get_value();
 
-                       _io.panner()[asz]->get_position (x);
+                       if (npans == 1) {
+                               x = 0.5;
+                       } else if (asz == 0) {
+                               x = 0.0;
+                       } else if (asz == 1) {
+                               x = 1.0;
+                       } else {
+                               x = rx;
+                       }
 
                        pan_adjustments.push_back (new Adjustment (x, 0, 1.0, 0.05, 0.1));
+                       bc = new PannerBar (*pan_adjustments[asz],
+                               boost::static_pointer_cast<PBD::Controllable>( _io->panner().pan_control( asz )) );
+
+                       /* now set adjustment with current value of panner, then connect the signals */
+                       pan_adjustments.back()->set_value(rx);
                        pan_adjustments.back()->signal_value_changed().connect (bind (mem_fun(*this, &PannerUI::pan_adjustment_changed), (uint32_t) asz));
 
-                       _io.panner()[asz]->Changed.connect (bind (mem_fun(*this, &PannerUI::pan_value_changed), (uint32_t) asz));
+                       _io->panner().pan_control( asz )->Changed.connect (bind (mem_fun(*this, &PannerUI::pan_value_changed), (uint32_t) asz));
 
-                       bc = new BarController (*pan_adjustments[asz], 
-                                               &_io.panner()[asz]->midi_control(),
-                                               bind (mem_fun(*this, &PannerUI::pan_printer), pan_adjustments[asz]));
-                       
-                       if (_session.midi_port()) {
-                               _io.panner()[asz]->reset_midi_control (_session.midi_port(), true);
-                       }
                        
                        bc->set_name ("PanSlider");
                        bc->set_shadow_type (Gtk::SHADOW_NONE);
-                       bc->set_style (BarController::Line);
 
-                       bc->StartGesture.connect (bind (mem_fun (_io, &IO::start_pan_touch), (uint32_t) asz));
-                       bc->StopGesture.connect (bind (mem_fun (_io, &IO::end_pan_touch), (uint32_t) asz));
+                       bc->StartGesture.connect (bind (mem_fun (*_io, &IO::start_pan_touch), (uint32_t) asz));
+                       bc->StopGesture.connect (bind (mem_fun (*_io, &IO::end_pan_touch), (uint32_t) asz));
 
                        char buf[64];
-#ifdef __APPLE__
-                       snprintf (buf, sizeof (buf), _("panner for channel %lu"), asz + 1);
-#else
-                       snprintf (buf, sizeof (buf), _("panner for channel %u"), asz + 1);
-#endif
+                       snprintf (buf, sizeof (buf), _("panner for channel %zu"), asz + 1);
                        ARDOUR_UI::instance()->tooltips().set_tip (bc->event_widget(), buf);
 
                        bc->event_widget().signal_button_release_event().connect
                                (bind (mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) asz));
 
-                       pan_bars.push_back (bc);
-                       switch (_width) {
-                       case Wide:
-                               pan_bars.back()->set_size_request (61, 15);
-                               break;
-                       case Narrow:
-                               pan_bars.back()->set_size_request (31, 15);
-                               break;
-                       }
+                       bc->set_size_request (-1, pan_bar_height);
 
-                       pan_bar_packer.pack_start (*pan_bars.back(), false, false);
+                       pan_bars.push_back (bc);
+                       pan_bar_packer.pack_start (*bc, false, false);
                }
 
                /* now that we actually have the pan bars,
@@ -366,26 +376,15 @@ PannerUI::setup_pan ()
 
        } else {
 
-               int w = 0;
-
-               switch (_width) {
-               case Wide:
-                       w = 61;
-                       break;
-               case Narrow:
-                       w = 31;
-                       break;
-               }
-
                if (panner == 0) {
-                       panner = new Panner2d (_io.panner(), w, 61);
+                       panner = new Panner2d (_io->panner(), 61);
                        panner->set_name ("MixerPanZone");
                        panner->show ();
                }
                
                update_pan_sensitive ();
-               panner->reset (_io.n_inputs());
-               panner->set_size_request (w, 61);
+               panner->reset (_io->n_inputs().n_audio());
+               panner->set_size_request (-1, 61);
 
                /* and finally, add it to the panner frame */
 
@@ -395,7 +394,7 @@ PannerUI::setup_pan ()
        }
 }
 
-gint
+bool
 PannerUI::pan_button_event (GdkEventButton* ev, uint32_t which)
 {
        switch (ev->button) {
@@ -406,13 +405,13 @@ PannerUI::pan_button_event (GdkEventButton* ev, uint32_t which)
                }
                build_pan_menu (which);
                pan_menu->popup (1, ev->time);
-               return TRUE;
+               return true;
                break;
        default:
-               return FALSE;
+               return false;
        }
 
-       return FALSE; // what's wrong with gcc?
+       return false; // what's wrong with gcc?
 }
 
 void
@@ -427,7 +426,7 @@ PannerUI::build_pan_menu (uint32_t which)
        
        /* set state first, connect second */
 
-       (dynamic_cast<CheckMenuItem*> (&items.back()))->set_active (_io.panner()[which]->muted());
+       (dynamic_cast<CheckMenuItem*> (&items.back()))->set_active (_io->panner().streampanner(which).muted());
        (dynamic_cast<CheckMenuItem*> (&items.back()))->signal_toggled().connect
                (bind (mem_fun(*this, &PannerUI::pan_mute), which));
 
@@ -436,7 +435,7 @@ PannerUI::build_pan_menu (uint32_t which)
 
        /* set state first, connect second */
 
-       bypass_menu_item->set_active (_io.panner().bypassed());
+       bypass_menu_item->set_active (_io->panner().bypassed());
        bypass_menu_item->signal_toggled().connect (mem_fun(*this, &PannerUI::pan_bypass_toggle));
 
        items.push_back (MenuElem (_("Reset"), mem_fun(*this, &PannerUI::pan_reset)));
@@ -447,15 +446,15 @@ PannerUI::build_pan_menu (uint32_t which)
 void
 PannerUI::pan_mute (uint32_t which)
 {
-       StreamPanner* sp = _io.panner()[which];
-       sp->set_muted (!sp->muted());
+       StreamPanner& sp = _io->panner().streampanner(which);
+       sp.set_muted (!sp.muted());
 }
 
 void
 PannerUI::pan_bypass_toggle ()
 {
-       if (bypass_menu_item && (_io.panner().bypassed() != bypass_menu_item->get_active())) {
-               _io.panner().set_bypassed (!_io.panner().bypassed());
+       if (bypass_menu_item && (_io->panner().bypassed() != bypass_menu_item->get_active())) {
+               _io->panner().set_bypassed (!_io->panner().bypassed());
        }
 }
 
@@ -467,11 +466,11 @@ PannerUI::pan_reset ()
 void
 PannerUI::effective_pan_display ()
 {
-       if (_io.panner().empty()) {
+       if (_io->panner().empty()) {
                return;
        }
 
-       switch (_io.n_outputs()) {
+       switch (_io->n_outputs().n_audio()) {
        case 0: 
        case 1:
                /* relax */
@@ -482,7 +481,7 @@ PannerUI::effective_pan_display ()
                break;
 
        default:
-                //panner->move_puck (pan_value (v, right), 0.5);
+               //panner->move_puck (pan_value (v, right), 0.5);
                break;
        }
 }
@@ -494,18 +493,21 @@ PannerUI::pan_changed (void *src)
                return;
        }
 
-       switch (_io.panner().size()) {
+       switch (_io->panner().npanners()) {
        case 0:
-               panning_link_box.set_sensitive (false);
+               panning_link_direction_button.set_sensitive (false);
+               panning_link_button.set_sensitive (false);
                return;
        case 1:
-               panning_link_box.set_sensitive (false);
+               panning_link_direction_button.set_sensitive (false);
+               panning_link_button.set_sensitive (false);
                break;
        default:
-               panning_link_box.set_sensitive (true);
+               panning_link_direction_button.set_sensitive (true);
+               panning_link_button.set_sensitive (true);
        }
 
-       uint32_t nouts = _io.n_outputs();
+       uint32_t nouts = _io->n_outputs().n_audio();
 
        switch (nouts) {
        case 0:
@@ -526,11 +528,11 @@ PannerUI::pan_changed (void *src)
 void
 PannerUI::pan_adjustment_changed (uint32_t which)
 {
-       if (!in_pan_update && which < _io.panner().size()) {
+       if (!in_pan_update && which < _io->panner().npanners()) {
 
                float xpos;
                float val = pan_adjustments[which]->get_value ();
-               _io.panner()[which]->get_position (xpos);
+               xpos = _io->panner().pan_control( which )->get_value();
 
                /* add a kinda-sorta detent for the middle */
                
@@ -547,7 +549,7 @@ PannerUI::pan_adjustment_changed (uint32_t which)
                
                if (!Panner::equivalent (val, xpos)) {
 
-                       _io.panner()[which]->set_position (val);
+                       _io->panner().streampanner(which).set_position (val);
                        /* XXX 
                           the panner objects have no access to the session,
                           so do this here. ick.
@@ -562,11 +564,11 @@ PannerUI::pan_value_changed (uint32_t which)
 {
        ENSURE_GUI_THREAD (bind (mem_fun(*this, &PannerUI::pan_value_changed), which));
                                                           
-       if (_io.n_outputs() > 1 && which < _io.panner().size()) {
+       if (_io->n_outputs().n_audio() > 1 && which < _io->panner().npanners()) {
                float xpos;
                float val = pan_adjustments[which]->get_value ();
 
-               _io.panner()[which]->get_position (xpos);
+               _io->panner().streampanner(which).get_position (xpos);
 
                if (!Panner::equivalent (val, xpos)) {
                        in_pan_update = true;
@@ -592,14 +594,14 @@ PannerUI::update_pan_bars (bool only_if_aplay)
                float xpos, val;
 
                if (only_if_aplay) {
-                       AutomationList& alist (_io.panner()[n]->automation());
+                       boost::shared_ptr<AutomationList> alist (_io->panner().streampanner(n).pan_control()->alist());
                        
-                       if (!alist.automation_playback()) {
+                       if (!alist->automation_playback()) {
                                continue;
                        }
                }
 
-               _io.panner()[n]->get_effective_position (xpos);
+               _io->panner().streampanner(n).get_effective_position (xpos);
                val = (*i)->get_value ();
                
                if (!Panner::equivalent (val, xpos)) {
@@ -630,14 +632,14 @@ PannerUI::pan_printer (char *buf, uint32_t len, Adjustment* adj)
 void
 PannerUI::update_pan_sensitive ()
 {
-       bool sensitive = !(_io.panner().automation_state() & Play);
+       bool sensitive = !(_io->panner().automation_state() & Play);
 
-       switch (_io.n_outputs()) {
+       switch (_io->n_outputs().n_audio()) {
        case 0:
        case 1:
                break;
        case 2:
-               for (vector<BarController*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
+               for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
                        (*i)->set_sensitive (sensitive);
                }
                break;
@@ -693,10 +695,10 @@ PannerUI::pan_automation_style_changed ()
        
        switch (_width) {
        case Wide:
-               pan_automation_style_button.set_label (astyle_string(_io.panner().automation_style()));
+               pan_automation_style_button.set_label (astyle_string(_io->panner().automation_style()));
                break;
        case Narrow:
-               pan_automation_style_button.set_label (short_astyle_string(_io.panner().automation_style()));
+               pan_automation_style_button.set_label (short_astyle_string(_io->panner().automation_style()));
                break;
        }
 }
@@ -710,10 +712,10 @@ PannerUI::pan_automation_state_changed ()
 
        switch (_width) {
        case Wide:
-         pan_automation_state_button.set_label (astate_string(_io.panner().automation_state()));
+         pan_automation_state_button.set_label (astate_string(_io->panner().automation_state()));
                break;
        case Narrow:
-         pan_automation_state_button.set_label (short_astate_string(_io.panner().automation_state()));
+         pan_automation_state_button.set_label (short_astate_string(_io->panner().automation_state()));
                break;
        }
 
@@ -722,11 +724,11 @@ PannerUI::pan_automation_state_changed ()
           here.
        */
 
-       if (_io.panner().empty()) {
+       if (_io->panner().empty()) {
                return;
        }
 
-       x = (_io.panner().front()->automation().automation_state() != Off);
+       x = (_io->panner().streampanner(0).pan_control()->alist()->automation_state() != Off);
 
        if (pan_automation_state_button.get_active() != x) {
        ignore_toggle = true;