*/
#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 "midi++/port.h"
#include "ardour/debug.h"
reset_pending = 0;
reset_position = false;
mtc_frame = 0;
+ mtc_frame_dll = 0;
engine_dll_initstate = 0;
busy_guard1 = busy_guard2 = 0;
a3e_timecode = session.config.get_timecode_format();
printed_timecode_warning = false;
+ session.config.ParameterChanged.connect_same_thread (config_connection, boost::bind (&MTC_Slave::parameter_changed, this, _1));
+ parse_timecode_offset();
reset (true);
rebind (p);
}
MTC_Slave::~MTC_Slave()
{
port_connections.drop_connections();
+ config_connection.disconnect();
while (busy_guard1 != busy_guard2) {
/* make sure MIDI parser is not currently calling any callbacks in here,
port->parser()->mtc_status.connect_same_thread (port_connections, boost::bind (&MTC_Slave::update_mtc_status, this, _1));
}
+void
+MTC_Slave::parse_timecode_offset() {
+ Timecode::Time offset_tc;
+ Timecode::parse_timecode_format(session.config.get_slave_timecode_offset(), offset_tc);
+ offset_tc.rate = session.timecode_frames_per_second();
+ offset_tc.drop = session.timecode_drop_frames();
+ session.timecode_to_sample(offset_tc, timecode_offset, false, false);
+ timecode_negative_offset = offset_tc.negative;
+}
+
+void
+MTC_Slave::parameter_changed (std::string const & p)
+{
+ if (p == "slave-timecode-offset"
+ || p == "timecode-format"
+ ) {
+ parse_timecode_offset();
+ }
+}
+
bool
MTC_Slave::give_slave_full_control_over_transport_speed() const
{
{
busy_guard1++;
const double qtr_d = quarter_frame_duration;
- const framepos_t qtr = rint(qtr_d);
- mtc_frame += qtr * transport_direction;
+ mtc_frame_dll += qtr_d * (double) transport_direction;
+ mtc_frame = rint(mtc_frame_dll);
DEBUG_TRACE (DEBUG::MTC, string_compose ("qtr frame %1 at %2 -> mtc_frame: %3\n", which_qtr, now, mtc_frame));
double mtc_speed = 0;
if (first_mtc_timestamp != 0) {
/* update MTC DLL and calculate speed */
- const double e = mtc_frame - (double(transport_direction) * (double(now) - double(current.timestamp) + t0));
+ const double e = mtc_frame_dll - (double)transport_direction * ((double)now - (double)current.timestamp + t0);
t0 = t1;
t1 += b * e + e2;
e2 += c * e;
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;
can_notify_on_unknown_rate = true;
break;
case MTC_30_FPS_DROP:
- timecode.rate = (30000.0/1001.0);
+ if (Config->get_timecode_source_2997()) {
+ tc_format = Timecode::timecode_2997000drop;
+ timecode.rate = (29970.0/1000.0);
+ } else {
+ tc_format = timecode_2997drop;
+ timecode.rate = (30000.0/1001.0);
+ }
timecode.drop = true;
- tc_format = timecode_2997drop;
can_notify_on_unknown_rate = true;
break;
case MTC_30_FPS:
did_reset_tc_format = true;
}
if (cur_timecode != tc_format) {
- warning << string_compose(_("Session framerate adjusted from %1 TO: MTC's %2."),
- Timecode::timecode_format_name(cur_timecode),
- Timecode::timecode_format_name(tc_format))
- << endmsg;
+ if (ceil(Timecode::timecode_to_frames_per_second(cur_timecode)) != ceil(Timecode::timecode_to_frames_per_second(tc_format))) {
+ warning << string_compose(_("Session framerate adjusted from %1 TO: MTC's %2."),
+ Timecode::timecode_format_name(cur_timecode),
+ Timecode::timecode_format_name(tc_format))
+ << endmsg;
+ }
}
session.config.set_timecode_format (tc_format);
} else {
if (a3e_timecode != cur_timecode) printed_timecode_warning = false;
if (cur_timecode != tc_format && ! printed_timecode_warning) {
- warning << string_compose(_("Session and MTC framerate mismatch: MTC:%1 Ardour:%2."),
- Timecode::timecode_format_name(tc_format),
- Timecode::timecode_format_name(cur_timecode))
- << endmsg;
+ if (ceil(Timecode::timecode_to_frames_per_second(cur_timecode)) != ceil(Timecode::timecode_to_frames_per_second(tc_format))) {
+ warning << string_compose(_("Session and MTC framerate mismatch: MTC:%1 %2:%3."),
+ Timecode::timecode_format_name(tc_format),
+ PROGRAM_NAME,
+ Timecode::timecode_format_name(cur_timecode))
+ << endmsg;
+ }
printed_timecode_warning = true;
}
}
Timecode::timecode_to_sample (timecode, mtc_frame, true, false,
double(session.frame_rate()),
session.config.get_subframes_per_frame(),
- session.config.get_timecode_offset_negative(), session.config.get_timecode_offset()
+ timecode_negative_offset, timecode_offset
);
DEBUG_TRACE (DEBUG::MTC, string_compose ("MTC at %1 TC %2 = mtc_frame %3 (from full message ? %4) tc-ratio %5\n",
now, timecode, mtc_frame, was_full, speedup_due_to_tc_mismatch));
if (was_full || outside_window (mtc_frame)) {
- DEBUG_TRACE (DEBUG::MTC, string_compose ("update_mtc_time: full TC or outside window. - TID:%1\n", ::pthread_self()));
+ DEBUG_TRACE (DEBUG::MTC, string_compose ("update_mtc_time: full TC or outside window. - TID:%1\n", pthread_name()));
session.request_locate (mtc_frame, false);
session.request_transport_speed (0);
update_mtc_status (MIDI::MTC_Stopped);
if (first_mtc_timestamp == 0 || current.timestamp == 0) {
first_mtc_timestamp = now;
init_mtc_dll(mtc_frame, qtr);
+ mtc_frame_dll = mtc_frame;
}
current.guard1++;
current.position = mtc_frame;
/* 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++;
std::string
MTC_Slave::approximate_current_delta() const
{
- char delta[24];
+ char delta[80];
SafeTime last;
read_current (&last);
if (last.timestamp == 0 || reset_pending) {
snprintf(delta, sizeof(delta), "\u2012\u2012\u2012\u2012");
} else {
- // TODO if current_delta > 1 frame -> display timecode.
- snprintf(delta, sizeof(delta), "%s%4" PRIi64 " sm",
- PLUSMINUS(-current_delta), abs(current_delta));
+ snprintf(delta, sizeof(delta), "\u0394<span foreground=\"green\" face=\"monospace\" >%s%s%" PRIi64 "</span>sm",
+ LEADINGZERO(abs(current_delta)), PLUSMINUS(-current_delta), abs(current_delta));
}
return std::string(delta);
}