- port_connections.drop_connections ();
-
- port = &p;
-
- port->input()->mtc_time.connect_same_thread (port_connections, boost::bind (&MTC_Slave::update_mtc_time, this, _1, _2, _3));
- port->input()->mtc_qtr.connect_same_thread (port_connections, boost::bind (&MTC_Slave::update_mtc_qtr, this, _1, _2, _3));
- port->input()->mtc_status.connect_same_thread (port_connections, boost::bind (&MTC_Slave::update_mtc_status, this, _1));
+ Glib::Threads::Mutex::Lock lm (reset_lock);
+ reset_pending++;
+ if (reset_pos) {
+ reset_position = true;
+ }
+}
+
+void
+MTC_Slave::maybe_reset ()
+{
+ Glib::Threads::Mutex::Lock lm (reset_lock);
+
+ if (reset_pending) {
+ reset (reset_position);
+ reset_pending = 0;
+ reset_position = false;
+ }
+}
+
+void
+MTC_Slave::reset (bool with_position)
+{
+ DEBUG_TRACE (DEBUG::MTC, string_compose ("MTC_Slave reset %1\n", with_position?"with position":"without position"));
+ if (with_position) {
+ last_inbound_frame = 0;
+ current.guard1++;
+ current.position = 0;
+ current.timestamp = 0;
+ current.speed = 0;
+ current.guard2++;
+ } else {
+ last_inbound_frame = 0;
+ current.guard1++;
+ current.timestamp = 0;
+ current.speed = 0;
+ current.guard2++;
+ }
+ first_mtc_timestamp = 0;
+ window_begin = 0;
+ window_end = 0;
+ transport_direction = 1;
+ current_delta = 0;
+}
+
+void
+MTC_Slave::handle_locate (const MIDI::byte* mmc_tc)
+{
+ MIDI::byte mtc[5];
+ DEBUG_TRACE (DEBUG::MTC, "MTC_Slave::handle_locate\n");
+
+ mtc[4] = last_mtc_fps_byte;
+ mtc[3] = mmc_tc[0] & 0xf; /* hrs only */
+ mtc[2] = mmc_tc[1];
+ mtc[1] = mmc_tc[2];
+ mtc[0] = mmc_tc[3];
+
+ update_mtc_time (mtc, true, 0);
+}
+
+void
+MTC_Slave::read_current (SafeTime *st) const
+{
+ int tries = 0;
+
+ do {
+ if (tries == 10) {
+ error << _("MTC Slave: atomic read of current time failed, sleeping!") << endmsg;
+ usleep (20);
+ tries = 0;
+ }
+ *st = current;
+ tries++;
+
+ } while (st->guard1 != st->guard2);
+}
+
+void
+MTC_Slave::init_mtc_dll(framepos_t tme, double qtr)
+{
+ omega = 2.0 * M_PI * qtr / 2.0 / double(session.frame_rate());
+ b = 1.4142135623730950488 * omega;
+ c = omega * omega;
+
+ e2 = qtr;
+ t0 = double(tme);
+ t1 = t0 + e2;
+ DEBUG_TRACE (DEBUG::MTC, string_compose ("[re-]init MTC DLL %1 %2 %3\n", t0, t1, e2));