a slew of unconnected mostly minor tweaks to get Push2 support back to where it was...
[ardour.git] / libs / surfaces / push2 / mix.cc
index 69d6373d42e968954e6e99220ef2a6b48584bb09..b564eaee0cc5d523206eb9bd8e8efad5c502020f 100644 (file)
@@ -16,6 +16,7 @@
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
+#include <cairomm/region.h>
 #include <pangomm/layout.h>
 
 #include "pbd/compose.h"
 #include "ardour/vca_manager.h"
 
 #include "canvas/colors.h"
+#include "canvas/rectangle.h"
 
+#include "gtkmm2ext/gui_thread.h"
+
+#include "canvas.h"
 #include "mix.h"
 #include "knob.h"
 #include "push2.h"
 #include "utils.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace ARDOUR;
 using namespace std;
 using namespace PBD;
 using namespace Glib;
 using namespace ArdourSurface;
+using namespace ArdourCanvas;
 
-MixLayout::MixLayout (Push2& p, Session& s, Cairo::RefPtr<Cairo::Context> context)
+MixLayout::MixLayout (Push2& p, Session& s)
        : Push2Layout (p, s)
-       , _dirty (true)
        , bank_start (0)
        , vpot_mode (Volume)
 {
+       selection_bg = new Rectangle (this);
+       selection_bg->hide ();
+
        Pango::FontDescription fd2 ("Sans 10");
        for (int n = 0; n < 8; ++n) {
-               upper_layout[n] = Pango::Layout::create (context);
-               upper_layout[n]->set_font_description (fd2);
+
+               /* background for text labels for knob function */
+
+               Rectangle* r = new Rectangle (this);
+               Coord x0 = 10 + (n*Push2Canvas::inter_button_spacing()) - 5;
+               r->set (Rect (x0, 2, x0 + Push2Canvas::inter_button_spacing(), 2 + 21));
+               backgrounds.push_back (r);
+
+               /* text labels for knob function*/
+
+               Text* t = new Text (this);
+               t->set_font_description (fd2);
+               t->set_color (p2.get_color (Push2::ParameterName));
+               t->set_position (Duple (10 + (n*Push2Canvas::inter_button_spacing()), 5));
 
                string txt;
                switch (n) {
@@ -94,37 +114,41 @@ MixLayout::MixLayout (Push2& p, Session& s, Cairo::RefPtr<Cairo::Context> contex
                        txt = _("E Sends");
                        break;
                }
-               upper_layout[n]->set_text (txt);
-       }
+               t->set (txt);
+               upper_text.push_back (t);
 
-       Pango::FontDescription fd3 ("Sans 10");
-       for (int n = 0; n < 8; ++n) {
-               lower_layout[n] = Pango::Layout::create (context);
-               lower_layout[n]->set_font_description (fd3);
-       }
+               /* knobs */
 
-       for (int n = 0; n < 8; ++n) {
-               knobs[n] = new Push2Knob (p2, context);
-               knobs[n]->set_position (60 + (n*120), 95);
+               knobs[n] = new Push2Knob (p2, this);
+               knobs[n]->set_position (Duple (60 + (n*Push2Canvas::inter_button_spacing()), 95));
                knobs[n]->set_radius (25);
+
+               /* stripable names */
+
+               t = new Text (this);
+               t->set_font_description (fd2);
+               t->set_color (p2.get_color (Push2::ParameterName));
+               t->set_position (Duple (10 + (n*Push2Canvas::inter_button_spacing()), 140));
+               lower_text.push_back (t);
+
        }
 
        mode_button = p2.button_by_id (Push2::Upper1);
 
-       session.RouteAdded.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&MixLayout::stripables_added, this), &p2);
-       session.vca_manager().VCAAdded.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&MixLayout::stripables_added, this), &p2);
+       session.RouteAdded.connect (session_connections, invalidator(*this), boost::bind (&MixLayout::stripables_added, this), &p2);
+       session.vca_manager().VCAAdded.connect (session_connections, invalidator (*this), boost::bind (&MixLayout::stripables_added, this), &p2);
 }
 
 MixLayout::~MixLayout ()
 {
-       for (int n = 0; n < 8; ++n) {
-               delete knobs[n];
-       }
+       // Item destructor deletes all children
 }
 
 void
-MixLayout::on_show ()
+MixLayout::show ()
 {
+       Container::show ();
+
        mode_button->set_color (Push2::LED::White);
        mode_button->set_state (Push2::LED::OneShot24th);
        p2.write (mode_button->state_msg());
@@ -132,116 +156,27 @@ MixLayout::on_show ()
        switch_bank (bank_start);
 }
 
-bool
-MixLayout::redraw (Cairo::RefPtr<Cairo::Context> context) const
+void
+MixLayout::render (Rect const& area, Cairo::RefPtr<Cairo::Context> context) const
 {
-       bool children_dirty = false;
-
-       for (int n = 0; n < 8; ++n) {
-               if (knobs[n]->dirty()) {
-                       children_dirty = true;
-                       break;
-               }
-       }
-
-       for (int n = 0; n < 8; ++n) {
-               if (stripable[n]) {
-
-                       string shortname = short_version (stripable[n]->name(), 10);
-                       string text;
-                       boost::shared_ptr<AutomationControl> ac;
-                       ac = stripable[n]->solo_control();
-                       if (ac && ac->get_value()) {
-                               text += "* ";
-                       }
-                       boost::shared_ptr<MuteControl> mc;
-                       mc = stripable[n]->mute_control ();
-                       if (mc) {
-                               if (mc->muted_by_self_or_masters()) {
-                                       text += "! ";
-                               } else if (mc->muted_by_others_soloing()) {
-                                       text += "- "; // it would be nice to use Unicode mute"\uD83D\uDD07 ";
-                               }
-                       }
-                       text += shortname;
+       DEBUG_TRACE (DEBUG::Push2, string_compose ("mix render %1\n", area));
 
-                       if (text != lower_layout[n]->get_text()) {
-                               lower_layout[n]->set_text (text);
-                               children_dirty = true;
-                       }
-               }
-       }
-
-       if (!children_dirty && !_dirty) {
-               return false;
-       }
+       /* draw background */
 
        set_source_rgb (context, p2.get_color (Push2::DarkBackground));
-       context->rectangle (0, 0, p2.cols, p2.rows);
+       context->rectangle (0, 0, display_width(), display_height());
        context->fill ();
 
-       set_source_rgb (context, p2.get_color (Push2::ParameterName));
-
-       for (int n = 0; n < 8; ++n) {
-
-               if (upper_layout[n]->get_text().empty()) {
-                       continue;
-               }
-
-               /* Draw highlight box */
-
-               uint32_t color = p2.get_color (Push2::ParameterName);
-
-               if (n == (int) vpot_mode) {
-                       set_source_rgb (context, color);
-                       context->rectangle (10 + (n*120) - 5, 2, 120, 21);
-                       context->fill();
-                       set_source_rgb (context, ArdourCanvas::contrasting_text_color (color));
-               }  else {
-                       set_source_rgb (context, color);
-               }
-
-               context->move_to (10 + (n*120), 2);
-               upper_layout[n]->update_from_cairo_context (context);
-               upper_layout[n]->show_in_cairo_context (context);
-       }
+       /* draw line across top (below labels) */
 
        context->move_to (0, 22.5);
-       context->line_to (p2.cols, 22.5);
+       context->line_to (display_width(), 22.5);
        context->set_line_width (1.0);
        context->stroke ();
 
-       for (int n = 0; n < 8; ++n) {
-               knobs[n]->redraw (context);
-       }
-
-       for (int n = 0; n < 8; ++n) {
-
-               if (lower_layout[n]->get_text().empty()) {
-                       continue;
-               }
-
-               if (stripable[n]) {
-                       uint32_t color = stripable[n]->presentation_info().color();
+       /* show the kids ... */
 
-                       if (stripable[n]->presentation_info().selected()) {
-                               set_source_rgb (context, color);
-                               context->rectangle (10 + (n*120) - 5, 137, 120, 21);
-                               context->fill();
-                               set_source_rgb (context, ArdourCanvas::contrasting_text_color (color));
-                       }  else {
-                               set_source_rgb (context, color);
-                       }
-
-                       context->move_to (10 + (n*120), 140);
-                       lower_layout[n]->update_from_cairo_context (context);
-                       lower_layout[n]->show_in_cairo_context (context);
-               }
-       }
-
-       _dirty = false;
-
-       return true;
+       render_children (area, context);
 }
 
 void
@@ -301,6 +236,11 @@ MixLayout::show_vpot_mode ()
        mode_button->set_state (Push2::LED::OneShot24th);
        p2.write (mode_button->state_msg());
 
+       for (int s = 0; s < 8; ++s) {
+               backgrounds[s]->hide ();
+               upper_text[s]->set_color (p2.get_color (Push2::ParameterName));
+       }
+
        boost::shared_ptr<AutomationControl> ac;
        switch (vpot_mode) {
        case Volume:
@@ -312,6 +252,9 @@ MixLayout::show_vpot_mode ()
                        }
                        knobs[s]->remove_flag (Push2Knob::ArcToZero);
                }
+               backgrounds[0]->set_fill_color (p2.get_color (Push2::ParameterName));
+               backgrounds[0]->show ();
+               upper_text[0]->set_color (contrasting_text_color (p2.get_color (Push2::ParameterName)));
                break;
        case PanAzimuth:
                for (int s = 0; s < 8; ++s) {
@@ -323,6 +266,9 @@ MixLayout::show_vpot_mode ()
 
                        }
                }
+               backgrounds[1]->set_fill_color (p2.get_color (Push2::ParameterName));
+               backgrounds[1]->show ();
+               upper_text[1]->set_color (contrasting_text_color (p2.get_color (Push2::ParameterName)));
                break;
        case PanWidth:
                for (int s = 0; s < 8; ++s) {
@@ -334,6 +280,9 @@ MixLayout::show_vpot_mode ()
                        }
                        knobs[s]->remove_flag (Push2Knob::ArcToZero);
                }
+               backgrounds[2]->set_fill_color (p2.get_color (Push2::ParameterName));
+               backgrounds[2]->show ();
+               upper_text[2]->set_color (contrasting_text_color (p2.get_color (Push2::ParameterName)));
                break;
        case Send1:
                for (int s = 0; s < 8; ++s) {
@@ -345,6 +294,9 @@ MixLayout::show_vpot_mode ()
                        }
                        knobs[s]->remove_flag (Push2Knob::ArcToZero);
                }
+               backgrounds[3]->set_fill_color (p2.get_color (Push2::ParameterName));
+               backgrounds[3]->show ();
+               upper_text[3]->set_color (contrasting_text_color (p2.get_color (Push2::ParameterName)));
                break;
        case Send2:
                for (int s = 0; s < 8; ++s) {
@@ -356,6 +308,9 @@ MixLayout::show_vpot_mode ()
                        }
                        knobs[s]->remove_flag (Push2Knob::ArcToZero);
                }
+               backgrounds[4]->set_fill_color (p2.get_color (Push2::ParameterName));
+               backgrounds[4]->show ();
+               upper_text[4]->set_color (contrasting_text_color (p2.get_color (Push2::ParameterName)));
                break;
        case Send3:
                for (int s = 0; s < 8; ++s) {
@@ -367,6 +322,9 @@ MixLayout::show_vpot_mode ()
                        }
                        knobs[s]->remove_flag (Push2Knob::ArcToZero);
                }
+               backgrounds[5]->set_fill_color (p2.get_color (Push2::ParameterName));
+               backgrounds[5]->show ();
+               upper_text[5]->set_color (contrasting_text_color (p2.get_color (Push2::ParameterName)));
                break;
        case Send4:
                for (int s = 0; s < 8; ++s) {
@@ -378,6 +336,9 @@ MixLayout::show_vpot_mode ()
                        }
                        knobs[s]->remove_flag (Push2Knob::ArcToZero);
                }
+               backgrounds[6]->set_fill_color (p2.get_color (Push2::ParameterName));
+               backgrounds[6]->show ();
+               upper_text[6]->set_color (contrasting_text_color (p2.get_color (Push2::ParameterName)));
                break;
        case Send5:
                for (int s = 0; s < 8; ++s) {
@@ -389,12 +350,13 @@ MixLayout::show_vpot_mode ()
                        }
                        knobs[s]->remove_flag (Push2Knob::ArcToZero);
                }
+               backgrounds[7]->set_fill_color (p2.get_color (Push2::ParameterName));
+               backgrounds[7]->show ();
+               upper_text[7]->set_color (contrasting_text_color (p2.get_color (Push2::ParameterName)));
                break;
        default:
                break;
        }
-
-       _dirty = true;
 }
 
 void
@@ -457,21 +419,81 @@ MixLayout::strip_vpot_touch (int n, bool touching)
 }
 
 void
-MixLayout::stripable_property_change (PropertyChange const& what_changed, int which)
+MixLayout::stripable_property_change (PropertyChange const& what_changed, uint32_t which)
 {
+       if (what_changed.contains (Properties::hidden)) {
+               switch_bank (bank_start);
+       }
+
        if (what_changed.contains (Properties::selected)) {
+
                if (!stripable[which]) {
                        return;
                }
 
-               /* cancel string, which will cause a redraw on the next update
-                * cycle. The redraw will reflect selected status
-                */
+               if (stripable[which]->presentation_info().selected()) {
+                       show_selection (which);
+               } else {
+                       hide_selection (which);
+               }
+       }
+
+}
 
-               lower_layout[which]->set_text (string());
+void
+MixLayout::show_selection (uint32_t n)
+{
+       selection_bg->show ();
+       selection_bg->set_fill_color (stripable[n]->presentation_info().color());
+       const Coord x0 = 10  + (n * Push2Canvas::inter_button_spacing()) - 5;
+       selection_bg->set (Rect (x0, 137, x0 + Push2Canvas::inter_button_spacing(), 137 + 21));
+       lower_text[n]->set_color (ArdourCanvas::contrasting_text_color (selection_bg->fill_color()));
+}
+
+void
+MixLayout::hide_selection (uint32_t n)
+{
+       selection_bg->hide ();
+       if (stripable[n]) {
+               lower_text[n]->set_color (stripable[n]->presentation_info().color());
        }
 }
 
+void
+MixLayout::solo_changed (uint32_t n)
+{
+       solo_mute_changed (n);
+}
+
+void
+MixLayout::mute_changed (uint32_t n)
+{
+       solo_mute_changed (n);
+}
+
+void
+MixLayout::solo_mute_changed (uint32_t n)
+{
+       string shortname = short_version (stripable[n]->name(), 10);
+       string text;
+       boost::shared_ptr<AutomationControl> ac;
+       ac = stripable[n]->solo_control();
+       if (ac && ac->get_value()) {
+               text += "* ";
+       }
+       boost::shared_ptr<MuteControl> mc;
+       mc = stripable[n]->mute_control ();
+       if (mc) {
+               if (mc->muted_by_self_or_masters()) {
+                       text += "! ";
+               } else if (mc->muted_by_others_soloing()) {
+                       text += "- "; // it would be nice to use Unicode mute"\uD83D\uDD07 ";
+               }
+       }
+       text += shortname;
+       lower_text[n]->set (text);
+}
+
 void
 MixLayout::switch_bank (uint32_t base)
 {
@@ -480,26 +502,27 @@ MixLayout::switch_bank (uint32_t base)
        /* work backwards so we can tell if we should actually switch banks */
 
        boost::shared_ptr<Stripable> s[8];
-       uint32_t old_empty = 0;
-       uint32_t new_empty = 0;
+       uint32_t different = 0;
 
        for (int n = 0; n < 8; ++n) {
-               if (!stripable[n]) {
-                       old_empty++;
-               }
                s[n] = session.get_remote_nth_stripable (base+n, PresentationInfo::Flag (PresentationInfo::Route|PresentationInfo::VCA));
-               if (!s[n]) {
-                       new_empty++;
+               if (s[n] != stripable[n]) {
+                       different++;
                }
        }
 
-       if ((new_empty != 0) && (new_empty >= old_empty)) {
+       if (!different) {
                /* some missing strips; new bank the same or more empty stripables than the old one, do
                   nothing since we had already reached the end.
                */
                return;
        }
 
+       if (!s[0]) {
+               /* not even the first stripable exists, do nothing */
+               return;
+       }
+
        for (int n = 0; n < 8; ++n) {
                stripable[n] = s[n];
        }
@@ -510,13 +533,31 @@ MixLayout::switch_bank (uint32_t base)
 
        for (int n = 0; n < 8; ++n) {
                if (!stripable[n]) {
+                       lower_text[n]->hide ();
+                       hide_selection (n);
                        continue;
                }
 
+               lower_text[n]->show ();
+
                /* stripable goes away? refill the bank, starting at the same point */
 
-               stripable[n]->DropReferences.connect (stripable_connections, MISSING_INVALIDATOR, boost::bind (&MixLayout::switch_bank, this, bank_start), &p2);
-               stripable[n]->presentation_info().PropertyChanged.connect (stripable_connections, MISSING_INVALIDATOR, boost::bind (&MixLayout::stripable_property_change, this, _1, n), &p2);
+               stripable[n]->DropReferences.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::switch_bank, this, bank_start), &p2);
+               stripable[n]->presentation_info().PropertyChanged.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::stripable_property_change, this, _1, n), &p2);
+               stripable[n]->solo_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::solo_changed, this, n), &p2);
+               stripable[n]->mute_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::mute_changed, this, n), &p2);
+
+               if (stripable[n]->presentation_info().selected()) {
+                       show_selection (n);
+               } else {
+                       hide_selection (n);
+               }
+
+               /* this will set lower text to the correct value (basically
+                  the stripable name)
+               */
+
+               solo_mute_changed (n);
 
                Push2::Button* b;