Update classkeys to match new total LuaSignal count (windows only)
[ardour.git] / libs / surfaces / push2 / track_mix.cc
index 67602a809aa11618a97325d929a0206fc845d1a4..ebb3c0731cf25828f2022542c44f062b1008f4aa 100644 (file)
 #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 "midi++/parser.h"
-#include "timecode/time.h"
-#include "timecode/bbt_time.h"
+
+#include "temporal/time.h"
+#include "temporal/bbt_time.h"
 
 #include "ardour/async_midi_port.h"
 #include "ardour/audioengine.h"
@@ -55,6 +55,7 @@
 #include "canvas/meter.h"
 #include "canvas/rectangle.h"
 #include "canvas/text.h"
+#include "canvas/types.h"
 
 #include "canvas.h"
 #include "knob.h"
 #include "track_mix.h"
 #include "utils.h"
 
+#include "pbd/i18n.h"
+
+#ifdef __APPLE__
+#define Rect ArdourCanvas::Rect
+#endif
+
 using namespace ARDOUR;
 using namespace std;
 using namespace PBD;
@@ -71,12 +78,12 @@ using namespace Glib;
 using namespace ArdourSurface;
 using namespace ArdourCanvas;
 
-TrackMixLayout::TrackMixLayout (Push2& p, Session& s)
-       : Push2Layout (p, s)
+TrackMixLayout::TrackMixLayout (Push2& p, Session & s, std::string const & name)
+       : Push2Layout (p, s, name)
 {
        Pango::FontDescription fd ("Sans 10");
 
-       bg = new Rectangle (this);
+       bg = new ArdourCanvas::Rectangle (this);
        bg->set (Rect (0, 0, display_width(), display_height()));
        bg->set_fill_color (p2.get_color (Push2::DarkBackground));
 
@@ -155,8 +162,6 @@ TrackMixLayout::TrackMixLayout (Push2& p, Session& s)
        minsec_text->set_font_description (fd2);
        minsec_text->set_color (p2.get_color (Push2::LightBackground));
        minsec_text->set_position (Duple (10 + (4 * Push2Canvas::inter_button_spacing()), 90));
-
-       ControlProtocol::StripableSelectionChanged.connect (selection_connection, invalidator (*this), boost::bind (&TrackMixLayout::selection_changed, this), &p2);
 }
 
 TrackMixLayout::~TrackMixLayout ()
@@ -166,45 +171,32 @@ TrackMixLayout::~TrackMixLayout ()
        }
 }
 
-void
-TrackMixLayout::selection_changed ()
-{
-       if (!parent()) {
-               return;
-       }
-
-       boost::shared_ptr<Stripable> s = ControlProtocol::first_selected_stripable();
-       if (s) {
-               set_stripable (s);
-       }
-}
-
 void
 TrackMixLayout::show ()
 {
-       selection_changed ();
-
        Push2::ButtonID lower_buttons[] = { Push2::Lower1, Push2::Lower2, Push2::Lower3, Push2::Lower4,
                                            Push2::Lower5, Push2::Lower6, Push2::Lower7, Push2::Lower8 };
 
        for (size_t n = 0; n < sizeof (lower_buttons) / sizeof (lower_buttons[0]); ++n) {
-               Push2::Button* b = p2.button_by_id (lower_buttons[n]);
+               boost::shared_ptr<Push2::Button> b = p2.button_by_id (lower_buttons[n]);
                b->set_color (Push2::LED::DarkGray);
                b->set_state (Push2::LED::OneShot24th);
                p2.write (b->state_msg());
        }
 
+       show_state ();
+
        Container::show ();
 }
 
 void
 TrackMixLayout::hide ()
 {
-       set_stripable (boost::shared_ptr<Stripable>());
+
 }
 
 void
-TrackMixLayout::render (ArdourCanvas::Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
+TrackMixLayout::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
 {
        Container::render (area, context);
 }
@@ -225,23 +217,31 @@ TrackMixLayout::button_lower (uint32_t n)
 
        switch (n) {
        case 0:
-               stripable->mute_control()->set_value (!stripable->mute_control()->get_value(), PBD::Controllable::UseGroup);
+               if (stripable->mute_control()) {
+                       stripable->mute_control()->set_value (!stripable->mute_control()->get_value(), PBD::Controllable::UseGroup);
+               }
                break;
        case 1:
-               stripable->solo_control()->set_value (!stripable->solo_control()->get_value(), PBD::Controllable::UseGroup);
+               if (stripable->solo_control()) {
+                       stripable->solo_control()->set_value (!stripable->solo_control()->get_value(), PBD::Controllable::UseGroup);
+               }
                break;
        case 2:
-               stripable->rec_enable_control()->set_value (!stripable->rec_enable_control()->get_value(), PBD::Controllable::UseGroup);
+               if (stripable->rec_enable_control()) {
+                       stripable->rec_enable_control()->set_value (!stripable->rec_enable_control()->get_value(), PBD::Controllable::UseGroup);
+               }
                break;
        case 3:
-               mc = stripable->monitoring_control()->monitoring_choice();
-               switch (mc) {
-               case MonitorInput:
-                       stripable->monitoring_control()->set_value (MonitorAuto, PBD::Controllable::UseGroup);
-                       break;
-               default:
-                       stripable->monitoring_control()->set_value (MonitorInput, PBD::Controllable::UseGroup);
-                       break;
+               if (stripable->monitor_control()) {
+                       mc = stripable->monitoring_control()->monitoring_choice();
+                       switch (mc) {
+                       case MonitorInput:
+                               stripable->monitoring_control()->set_value (MonitorAuto, PBD::Controllable::UseGroup);
+                               break;
+                       default:
+                               stripable->monitoring_control()->set_value (MonitorInput, PBD::Controllable::UseGroup);
+                               break;
+                       }
                }
                break;
        case 4:
@@ -256,10 +256,14 @@ TrackMixLayout::button_lower (uint32_t n)
                }
                break;
        case 5:
-               stripable->solo_isolate_control()->set_value (!stripable->solo_isolate_control()->get_value(), PBD::Controllable::UseGroup);
+               if (stripable->solo_isolate_control()) {
+                       stripable->solo_isolate_control()->set_value (!stripable->solo_isolate_control()->get_value(), PBD::Controllable::UseGroup);
+               }
                break;
        case 6:
-               stripable->solo_safe_control()->set_value (!stripable->solo_safe_control()->get_value(), PBD::Controllable::UseGroup);
+               if (stripable->solo_safe_control()) {
+                       stripable->solo_safe_control()->set_value (!stripable->solo_safe_control()->get_value(), PBD::Controllable::UseGroup);
+               }
                break;
        case 7:
                /* nothing here */
@@ -286,7 +290,7 @@ TrackMixLayout::simple_control_change (boost::shared_ptr<AutomationControl> ac,
                return;
        }
 
-       Push2::Button* b = p2.button_by_id (bid);
+       boost::shared_ptr<Push2::Button> b = p2.button_by_id (bid);
 
        if (!b) {
                return;
@@ -308,7 +312,7 @@ TrackMixLayout::solo_mute_change ()
                return;
        }
 
-       Push2::Button* b = p2.button_by_id (Push2::Lower2);
+       boost::shared_ptr<Push2::Button> b = p2.button_by_id (Push2::Lower2);
 
        if (b) {
                boost::shared_ptr<SoloControl> sc = stripable->solo_control();
@@ -399,8 +403,8 @@ TrackMixLayout::monitoring_change ()
                return;
        }
 
-       Push2::Button* b1 = p2.button_by_id (Push2::Lower4);
-       Push2::Button* b2 = p2.button_by_id (Push2::Lower5);
+       boost::shared_ptr<Push2::Button> b1 = p2.button_by_id (Push2::Lower4);
+       boost::shared_ptr<Push2::Button> b2 = p2.button_by_id (Push2::Lower5);
        uint8_t b1_color;
        uint8_t b2_color;
 
@@ -434,6 +438,28 @@ TrackMixLayout::monitoring_change ()
        p2.write (b2->state_msg());
 }
 
+void
+TrackMixLayout::show_state ()
+{
+       if (!parent()) {
+               return;
+       }
+
+       if (stripable) {
+               name_changed ();
+               color_changed ();
+               solo_mute_change ();
+               rec_enable_change ();
+               solo_iso_change ();
+               solo_safe_change ();
+               monitoring_change ();
+
+               meter->set_meter (stripable->peak_meter ().get());
+       } else {
+               meter->set_meter (0);
+       }
+}
+
 void
 TrackMixLayout::set_stripable (boost::shared_ptr<Stripable> s)
 {
@@ -471,19 +497,9 @@ TrackMixLayout::set_stripable (boost::shared_ptr<Stripable> s)
                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 ();
-               solo_mute_change ();
-               rec_enable_change ();
-               solo_iso_change ();
-               solo_safe_change ();
-               monitoring_change ();
-
-               meter->set_meter (stripable->peak_meter ().get());
-       } else {
-               meter->set_meter (0);
        }
+
+       show_state ();
 }
 
 void
@@ -497,10 +513,16 @@ void
 TrackMixLayout::name_changed ()
 {
        if (stripable) {
-               /* poor-man's right justification */
-               char buf[92];
-               snprintf (buf, sizeof (buf), "%*s", (int) sizeof (buf) - 1, stripable->name().c_str());
-               name_text->set (buf);
+
+               name_text->set (stripable->name());
+
+               /* right justify */
+
+               Duple pos;
+               pos.y = name_text->position().y;
+               pos.x = display_width() - 10 - name_text->width();
+
+               name_text->set_position (pos);
        }
 }
 
@@ -511,7 +533,7 @@ TrackMixLayout::color_changed ()
                return;
        }
 
-       Color rgba = stripable->presentation_info().color();
+       Gtkmm2ext::Color rgba = stripable->presentation_info().color();
        selection_color = p2.get_color_index (rgba);
 
        name_text->set_color (rgba);
@@ -550,9 +572,9 @@ 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());
+                       ac->start_touch (session.audible_sample());
                } else {
-                       ac->stop_touch (true, session.audible_frame());
+                       ac->stop_touch (session.audible_sample());
                }
        }
 }
@@ -570,7 +592,7 @@ TrackMixLayout::update_meters ()
 void
 TrackMixLayout::update_clocks ()
 {
-       framepos_t pos = session.audible_frame();
+       samplepos_t pos = session.audible_sample();
        bool negative = false;
 
        if (pos < 0) {
@@ -579,7 +601,7 @@ TrackMixLayout::update_clocks ()
        }
 
        char buf[16];
-       Timecode::BBT_Time BBT = session.tempo_map().bbt_at_frame (pos);
+       Timecode::BBT_Time BBT = session.tempo_map().bbt_at_sample (pos);
 
 #define BBT_BAR_CHAR "|"
 
@@ -593,22 +615,22 @@ TrackMixLayout::update_clocks ()
 
        bbt_text->set (buf);
 
-       framecnt_t left;
+       samplecnt_t left;
        int hrs;
        int mins;
        int secs;
        int millisecs;
 
-       const double frame_rate = session.frame_rate ();
+       const double sample_rate = session.sample_rate ();
 
        left = pos;
-       hrs = (int) floor (left / (frame_rate * 60.0f * 60.0f));
-       left -= (framecnt_t) floor (hrs * frame_rate * 60.0f * 60.0f);
-       mins = (int) floor (left / (frame_rate * 60.0f));
-       left -= (framecnt_t) floor (mins * frame_rate * 60.0f);
-       secs = (int) floor (left / (float) frame_rate);
-       left -= (framecnt_t) floor ((double)(secs * frame_rate));
-       millisecs = floor (left * 1000.0 / (float) frame_rate);
+       hrs = (int) floor (left / (sample_rate * 60.0f * 60.0f));
+       left -= (samplecnt_t) floor (hrs * sample_rate * 60.0f * 60.0f);
+       mins = (int) floor (left / (sample_rate * 60.0f));
+       left -= (samplecnt_t) floor (mins * sample_rate * 60.0f);
+       secs = (int) floor (left / (float) sample_rate);
+       left -= (samplecnt_t) floor ((double)(secs * sample_rate));
+       millisecs = floor (left * 1000.0 / (float) sample_rate);
 
        if (negative) {
                snprintf (buf, sizeof (buf), "-%02" PRId32 ":%02" PRId32 ":%02" PRId32 ".%03" PRId32, hrs, mins, secs, millisecs);