push2: remove Knob::set_position() overload
[ardour.git] / libs / surfaces / push2 / track_mix.cc
index 69d56425c018e4f44cb4ba1ec4935cde2559befe..139e2df341ae982e017c02d1f873285ec5cf1a06 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"
@@ -23,6 +24,7 @@
 #include "pbd/debug.h"
 #include "pbd/failed_constructor.h"
 #include "pbd/file_utils.h"
+#include "pbd/i18n.h"
 #include "pbd/search_path.h"
 #include "pbd/enumwriter.h"
 
 #include "ardour/session.h"
 #include "ardour/tempo.h"
 
+#include "gtkmm2ext/gui_thread.h"
 #include "gtkmm2ext/rgb_macros.h"
 
+#include "canvas.h"
 #include "knob.h"
 #include "menu.h"
 #include "push2.h"
 #include "track_mix.h"
 #include "utils.h"
 
-#include "i18n.h"
-
 using namespace ARDOUR;
 using namespace std;
 using namespace PBD;
 using namespace Glib;
 using namespace ArdourSurface;
+using namespace ArdourCanvas;
 
-TrackMixLayout::TrackMixLayout (Push2& p, Session& s, Cairo::RefPtr<Cairo::Context> context)
+TrackMixLayout::TrackMixLayout (Push2& p, Session& s)
        : Push2Layout (p, s)
-       , _dirty (false)
 {
-       name_layout = Pango::Layout::create (context);
-
-       Pango::FontDescription fd ("Sans Bold 14");
-       name_layout->set_font_description (fd);
-
        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);
-               upper_layout[n]->set_text ("solo");
-               lower_layout[n] = Pango::Layout::create (context);
-               lower_layout[n]->set_font_description (fd2);
-               lower_layout[n]->set_text ("mute");
-       }
-
-       Push2Knob* knob;
 
-       knob = new Push2Knob (p2, context);
-       knob->set_position (60, 80);
-       knob->set_radius (35);
-       knobs.push_back (knob);
+       for (int n = 0; n < 8; ++n) {
+               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()), 2));
 
-       knob = new Push2Knob (p2, context);
-       knob->set_position (180, 80);
-       knob->set_radius (35);
-       knobs.push_back (knob);
-}
+               upper_text.push_back (t);
 
-TrackMixLayout::~TrackMixLayout ()
-{
-       for (vector<Push2Knob*>::iterator k = knobs.begin(); k != knobs.end(); ++k) {
-               delete *k;
-       }
-}
+               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));
 
-bool
-TrackMixLayout::redraw (Cairo::RefPtr<Cairo::Context> context) const
-{
-       bool children_dirty = false;
+               lower_text.push_back (t);
 
-       for (vector<Push2Knob*>::const_iterator k = knobs.begin(); k != knobs.end(); ++k) {
-               if ((*k)->dirty()) {
-                       children_dirty = true;
+               switch (n) {
+               case 0:
+                       upper_text[n]->set (_("TRACK VOLUME"));
+                       lower_text[n]->set (_("MUTE"));
+                       break;
+               case 1:
+                       upper_text[n]->set (_("TRACK PAN"));
+                       lower_text[n]->set (_("SOLO"));
+                       break;
+               case 2:
+                       upper_text[n]->set (_("TRACK WIDTH"));
+                       lower_text[n]->set (_("REC-ENABLE"));
+                       break;
+               case 3:
+                       upper_text[n]->set (_("TRACK TRIM"));
+                       lower_text[n]->set (_("IN"));
+                       break;
+               case 4:
+                       upper_text[n]->set (_(""));
+                       lower_text[n]->set (_("DISK"));
+                       break;
+               case 5:
+                       upper_text[n]->set (_(""));
+                       lower_text[n]->set (_("SOLO ISO"));
+                       break;
+               case 6:
+                       upper_text[n]->set (_(""));
+                       lower_text[n]->set (_("SOLO LOCK"));
+                       break;
+               case 7:
+                       upper_text[n]->set (_(""));
+                       lower_text[n]->set (_(""));
                        break;
                }
-       }
 
-       if (!children_dirty && !_dirty) {
-               return false;
+               knobs[n] = new Push2Knob (p2, this);
+               knobs[n]->set_position (Duple (60 + (Push2Canvas::inter_button_spacing()*n), 95));
+               knobs[n]->set_radius (25);
        }
 
-       set_source_rgb (context, p2.get_color (Push2::DarkBackground));
-       context->rectangle (0, 0, p2.cols, p2.rows);
-       context->fill ();
+       ControlProtocol::StripableSelectionChanged.connect (selection_connection, invalidator (*this), boost::bind (&TrackMixLayout::selection_changed, this), &p2);
+}
 
-       if (stripable) {
-               int r,g,b,a;
-               UINT_TO_RGBA (stripable->presentation_info().color(), &r, &g, &b, &a);
-               context->set_source_rgb (r/255.0, g/255.0, b/255.0);
-       } else {
-               context->set_source_rgb (0.23, 0.0, 0.349);
+TrackMixLayout::~TrackMixLayout ()
+{
+       for (int n = 0; n < 8; ++n) {
+               delete knobs[n];
        }
-       context->move_to (10, 2);
-       name_layout->update_from_cairo_context (context);
-       name_layout->show_in_cairo_context (context);
+}
 
-       for (vector<Push2Knob*>::const_iterator k = knobs.begin(); k != knobs.end(); ++k) {
-               (*k)->redraw (context);
+void
+TrackMixLayout::selection_changed ()
+{
+       boost::shared_ptr<Stripable> s = ControlProtocol::first_selected_stripable();
+       if (s) {
+               set_stripable (s);
        }
-
-       return true;
 }
-
 void
-TrackMixLayout::button_upper (uint32_t n)
+TrackMixLayout::show ()
 {
+       selection_changed ();
 }
 
 void
-TrackMixLayout::button_lower (uint32_t n)
+TrackMixLayout::render (ArdourCanvas::Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
 {
+       set_source_rgb (context, p2.get_color (Push2::DarkBackground));
+       context->rectangle (0, 0, display_width(), display_height());
+       context->fill ();
+
+       context->move_to (0, 22.5);
+       context->line_to (display_width(), 22.5);
+       context->set_line_width (1.0);
+       context->stroke ();
+
+       Container::render_children (area, context);
 }
 
 void
-TrackMixLayout::strip_vpot (int n, int delta)
+TrackMixLayout::button_upper (uint32_t n)
 {
-       if (!stripable) {
-               return;
-       }
-
-       switch (n) {
-       case 0: /* gain */
-               boost::shared_ptr<AutomationControl> ac = stripable->gain_control();
-               if (ac) {
-                       ac->set_value (ac->get_value() + ((2.0/64.0) * delta), PBD::Controllable::UseGroup);
-               }
-               break;
-       }
 }
 
 void
-TrackMixLayout::strip_vpot_touch (int, bool)
+TrackMixLayout::button_lower (uint32_t n)
 {
 }
 
 void
 TrackMixLayout::set_stripable (boost::shared_ptr<Stripable> s)
 {
+       stripable_connections.drop_connections ();
+
        stripable = s;
 
        if (stripable) {
-               stripable->DropReferences.connect (stripable_connections, MISSING_INVALIDATOR, boost::bind (&TrackMixLayout::drop_stripable, this), &p2);
 
-               stripable->PropertyChanged.connect (stripable_connections, MISSING_INVALIDATOR, boost::bind (&TrackMixLayout::stripable_property_change, this, _1), &p2);
-               stripable->presentation_info().PropertyChanged.connect (stripable_connections, MISSING_INVALIDATOR, boost::bind (&TrackMixLayout::stripable_property_change, this, _1), &p2);
+               stripable->DropReferences.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::drop_stripable, this), &p2);
+
+               stripable->PropertyChanged.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::stripable_property_change, this, _1), &p2);
+               stripable->presentation_info().PropertyChanged.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::stripable_property_change, this, _1), &p2);
 
                knobs[0]->set_controllable (stripable->gain_control());
                knobs[1]->set_controllable (stripable->pan_azimuth_control());
+               knobs[1]->add_flag (Push2Knob::ArcToZero);
+               knobs[2]->set_controllable (stripable->pan_width_control());
+               knobs[3]->set_controllable (stripable->trim_control());
+               knobs[3]->add_flag (Push2Knob::ArcToZero);
+               knobs[4]->set_controllable (boost::shared_ptr<AutomationControl>());
+               knobs[5]->set_controllable (boost::shared_ptr<AutomationControl>());
+               knobs[6]->set_controllable (boost::shared_ptr<AutomationControl>());
+               knobs[7]->set_controllable (boost::shared_ptr<AutomationControl>());
 
                name_changed ();
                color_changed ();
@@ -197,7 +211,6 @@ TrackMixLayout::drop_stripable ()
 void
 TrackMixLayout::name_changed ()
 {
-       name_layout->set_text (stripable->name());
        _dirty = true;
 }
 
@@ -205,12 +218,12 @@ void
 TrackMixLayout::color_changed ()
 {
        uint32_t rgb = stripable->presentation_info().color();
-       uint8_t index = p2.get_color_index (rgb);
 
-       Push2::Button* b = p2.button_by_id (Push2::Upper1);
-       b->set_color (index);
-       b->set_state (Push2::LED::OneShot24th);
-       p2.write (b->state_msg ());
+       for (int n = 0; n < 8; ++n) {
+               knobs[n]->set_text_color (rgb);
+               knobs[n]->set_arc_start_color (rgb);
+               knobs[n]->set_arc_end_color (rgb);
+       }
 }
 
 void
@@ -223,3 +236,26 @@ TrackMixLayout::stripable_property_change (PropertyChange const& what_changed)
                name_changed ();
        }
 }
+
+void
+TrackMixLayout::strip_vpot (int n, int delta)
+{
+       boost::shared_ptr<Controllable> ac = knobs[n]->controllable();
+
+       if (ac) {
+               ac->set_value (ac->get_value() + ((2.0/64.0) * delta), PBD::Controllable::UseGroup);
+       }
+}
+
+void
+TrackMixLayout::strip_vpot_touch (int n, bool touching)
+{
+       boost::shared_ptr<AutomationControl> ac = knobs[n]->controllable();
+       if (ac) {
+               if (touching) {
+                       ac->start_touch (session.audible_frame());
+               } else {
+                       ac->stop_touch (true, session.audible_frame());
+               }
+       }
+}