fix crash when copy'ing latent plugins
[ardour.git] / libs / ardour / mtc_slave.cc
index e9071af61917690bc7d86d4eb25205c2ebdb2f24..102694e7ac7d9a9ab637871f2e085eede99bc400 100644 (file)
 */
 #include <iostream>
 #include <errno.h>
-#include <poll.h>
 #include <sys/types.h>
 #include <unistd.h>
 
 #include "pbd/error.h"
+#include "pbd/pthread_utils.h"
 
 #include "ardour/audioengine.h"
 #include "ardour/debug.h"
@@ -32,7 +32,9 @@
 #include "ardour/session.h"
 #include "ardour/slave.h"
 
-#include "i18n.h"
+#include <glibmm/timer.h>
+
+#include "pbd/i18n.h"
 
 using namespace std;
 using namespace ARDOUR;
@@ -211,6 +213,7 @@ MTC_Slave::reset (bool with_position)
        window_end = 0;
        transport_direction = 1;
        current_delta = 0;
+       ActiveChanged(false);
 }
 
 void
@@ -236,7 +239,7 @@ MTC_Slave::read_current (SafeTime *st) const
        do {
                if (tries == 10) {
                        error << _("MTC Slave: atomic read of current time failed, sleeping!") << endmsg;
-                       usleep (20);
+                       Glib::usleep (20);
                        tries = 0;
                }
                *st = current;
@@ -299,7 +302,7 @@ MTC_Slave::update_mtc_qtr (Parser& /*p*/, int which_qtr, framepos_t now)
  * when a full TC has been received
  * OR on locate */
 void
-MTC_Slave::update_mtc_time (const byte *msg, bool was_full, framepos_t now)
+MTC_Slave::update_mtc_time (const MIDI::byte *msg, bool was_full, framepos_t now)
 {
        busy_guard1++;
 
@@ -307,8 +310,7 @@ MTC_Slave::update_mtc_time (const byte *msg, bool was_full, framepos_t now)
           to use a timestamp indicating when this MTC time was received. example: when we received
           a locate command via MMC.
        */
-
-       DEBUG_TRACE (DEBUG::MTC, string_compose ("MTC::update_mtc_time - TID:%1\n", ::pthread_self()));
+       DEBUG_TRACE (DEBUG::MTC, string_compose ("MTC::update_mtc_time - TID:%1\n", pthread_name()));
        TimecodeFormat tc_format;
        bool reset_tc = true;
 
@@ -467,6 +469,7 @@ MTC_Slave::update_mtc_time (const byte *msg, bool was_full, framepos_t now)
                                first_mtc_timestamp = now;
                                init_mtc_dll(mtc_frame, qtr);
                                mtc_frame_dll = mtc_frame;
+                               ActiveChanged (true); // emit signal
                        }
                        current.guard1++;
                        current.position = mtc_frame;
@@ -488,7 +491,7 @@ MTC_Slave::update_mtc_status (MIDI::MTC_Status status)
        /* XXX !!! thread safety ... called from MIDI I/O context
         * on locate (via ::update_mtc_time())
         */
-       DEBUG_TRACE (DEBUG::MTC, string_compose("MTC_Slave::update_mtc_status - TID:%1\n", ::pthread_self()));
+       DEBUG_TRACE (DEBUG::MTC, string_compose("MTC_Slave::update_mtc_status - TID:%1\n", pthread_name()));
        return; // why was this fn needed anyway ? it just messes up things -> use reset.
        busy_guard1++;
 
@@ -593,7 +596,7 @@ MTC_Slave::speed_and_position (double& speed, framepos_t& pos)
        read_current (&last);
 
        DEBUG_TRACE (DEBUG::MTC, string_compose ("speed&pos: timestamp %1 speed %2 initstate %3 dir %4 tpos %5 now %6 last-in %7\n",
-                                                last.timestamp, 
+                                                last.timestamp,
                                                 last.speed,
                                                 engine_dll_initstate,
                                                 transport_direction,
@@ -602,8 +605,8 @@ MTC_Slave::speed_and_position (double& speed, framepos_t& pos)
                                                 last_inbound_frame));
 
        /* re-init engine DLL here when state changed (direction, first_mtc_timestamp) */
-       if (last.timestamp == 0) { 
-               engine_dll_initstate = 0; 
+       if (last.timestamp == 0) {
+               engine_dll_initstate = 0;
        } else if (engine_dll_initstate != transport_direction && last.speed != 0) {
                engine_dll_initstate = transport_direction;
                init_engine_dll(last.position, session.engine().samples_per_cycle());
@@ -625,6 +628,7 @@ MTC_Slave::speed_and_position (double& speed, framepos_t& pos)
                session.request_transport_speed (0);
                engine_dll_initstate = 0;
                queue_reset (false);
+        ActiveChanged (false);
                DEBUG_TRACE (DEBUG::MTC, "MTC not seen for 2 frames - reset pending\n");
                return false;
        }