#include <poll.h>
#include <sys/types.h>
#include <unistd.h>
+
#include "pbd/error.h"
+#include "pbd/stacktrace.h"
#include "pbd/enumwriter.h"
#include "pbd/failed_constructor.h"
#include "pbd/pthread_utils.h"
MTC_Slave::MTC_Slave (Session& s, MIDI::Port& p)
: session (s)
- , port_connections (0)
{
can_notify_on_unknown_rate = true;
did_reset_tc_format = false;
MTC_Slave::~MTC_Slave()
{
- delete port_connections;
-
if (did_reset_tc_format) {
session.config.set_timecode_format (saved_tc_format);
}
void
MTC_Slave::rebind (MIDI::Port& p)
{
- delete port_connections;
- port_connections = new ScopedConnectionList;
+ port_connections.drop_connections ();
port = &p;
- port_connections->add_connection (port->input()->mtc_time.connect ( boost::bind (&MTC_Slave::update_mtc_time, this, _1, _2, _3)));
- port_connections->add_connection (port->input()->mtc_qtr.connect (boost::bind (&MTC_Slave::update_mtc_qtr, this, _1, _2, _3)));
- port_connections->add_connection (port->input()->mtc_status.connect (boost::bind (&MTC_Slave::update_mtc_status, this, _1)));
+ 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));
}
void
MTC_Slave::update_mtc_qtr (Parser& /*p*/, int which_qtr, nframes_t now)
{
+ DEBUG_TRACE (DEBUG::MTC, string_compose ("update MTC qtr does a reset, qtr = %1 now = %2\n", which_qtr, now));
maybe_reset ();
DEBUG_TRACE (DEBUG::MTC, string_compose ("qtr frame %1 at %2\n", which_qtr, now));
*/
if (now) {
+ DEBUG_TRACE (DEBUG::MTC, string_compose ("update MTC time does a reset, was full ? %1 now = %2\n", was_full, now));
maybe_reset ();
}
DEBUG_TRACE (DEBUG::MTC, string_compose ("MTC time timestamp = %1 TC %2 = frame %3 (from full message ? %4)\n",
now, timecode, mtc_frame, was_full));
-
+
if (was_full || outside_window (mtc_frame)) {
session.timecode_to_sample (timecode, mtc_frame, true, false);
session.request_locate (mtc_frame, false);
session.request_transport_speed (0);
+ DEBUG_TRACE (DEBUG::MTC, string_compose ("reset MTC status to stopped, outside MTC window (%1 .. %2 vs. %3)\n",
+ window_begin, window_end, mtc_frame));
update_mtc_status (MIDI::MTC_Stopped);
- reset_window (mtc_frame);
+ DEBUG_TRACE (DEBUG::MTC, string_compose ("outside, so window root reset to %1\n", mtc_frame));
reset ();
+ reset_window (mtc_frame);
} else {
}
if (window_root >= 0) {
+ DEBUG_TRACE (DEBUG::MTC, string_compose ("window root reset to %1\n", window_root));
reset_window (window_root);
}
}
void
MTC_Slave::queue_reset ()
{
+ DEBUG_TRACE (DEBUG::MTC, "queue reset of MTC slave state\n");
+ PBD::stacktrace (cerr, 35);
Glib::Mutex::Lock lm (reset_lock);
reset_pending++;
}
reset_lock.lock ();
if (reset_pending) {
+ DEBUG_TRACE (DEBUG::MTC, "actually reset\n");
reset ();
reset_pending = 0;
}
void
MTC_Slave::reset ()
{
+ DEBUG_TRACE (DEBUG::MTC, "*****************\n\n\n MTC SLAVE reset ********************\n\n\n");
+ PBD::stacktrace (cerr, 35);
port->input()->reset_mtc_state ();
last_inbound_frame = 0;
ahead of the window root (taking direction into account).
*/
+ DEBUG_TRACE (DEBUG::MTC, string_compose ("trying to reset MTC window with state = %1\n", enum_2_string (port->input()->mtc_running())));
+
switch (port->input()->mtc_running()) {
case MTC_Forward:
+ DEBUG_TRACE (DEBUG::MTC, "set MTC window while running forward\n");
window_begin = root;
if (session.slave_state() == Session::Running) {
window_end = root + (session.frames_per_timecode_frame() * frame_tolerance);
} else {
window_end = root + seekahead_distance ();
}
- DEBUG_TRACE (DEBUG::MTC, string_compose ("legal MTC window now %1 .. %2\n", window_begin, window_end));
break;
case MTC_Backward:
+ DEBUG_TRACE (DEBUG::MTC, "set MTC window while running backward\n");
if (session.slave_state() == Session::Running) {
nframes_t d = session.frames_per_timecode_frame() * frame_tolerance;
if (root > d) {
}
}
window_end = root;
- DEBUG_TRACE (DEBUG::MTC, string_compose ("legal MTC window now %1 .. %2\n", window_begin, window_end));
break;
default:
+ DEBUG_TRACE (DEBUG::MTC, "not touching MTC window - MTC_Stopped\n");
/* do nothing */
break;
}
+
+ DEBUG_TRACE (DEBUG::MTC, string_compose ("legal MTC window now %1 .. %2\n", window_begin, window_end));
}
nframes64_t