#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"
using namespace std;
using namespace ARDOUR;
-using namespace sigc;
using namespace MIDI;
using namespace PBD;
can_notify_on_unknown_rate = true;
did_reset_tc_format = false;
- pic = new PIController (1.0, 8);
+ pic = new PIChaser();
last_mtc_fps_byte = session.get_mtc_timecode_bits ();
mtc_frame = 0;
if (did_reset_tc_format) {
session.config.set_timecode_format (saved_tc_format);
}
+
delete pic;
delete [] speed_accumulator;
}
void
MTC_Slave::rebind (MIDI::Port& p)
{
- for (vector<sigc::connection>::iterator i = connections.begin(); i != connections.end(); ++i) {
- (*i).disconnect ();
- }
-
+ port_connections.drop_connections ();
+
port = &p;
-
- connections.push_back (port->input()->mtc_time.connect (mem_fun (*this, &MTC_Slave::update_mtc_time)));
- connections.push_back (port->input()->mtc_qtr.connect (mem_fun (*this, &MTC_Slave::update_mtc_qtr)));
- connections.push_back (port->input()->mtc_status.connect (mem_fun (*this, &MTC_Slave::update_mtc_status)));
+
+ 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 {
*
* its not the average, but we will assign it to current.speed below
*/
+
+ static nframes64_t last_seen_timestamp = 0;
+ static nframes64_t last_seen_position = 0;
+
+ if ((now - last_seen_timestamp) < 300) {
+ mtc_frame = (mtc_frame + last_seen_position)/2;
+ }
+
+ last_seen_timestamp = now;
+ last_seen_position = mtc_frame;
+
- average_speed = pic->get_ratio (session.audible_frame() - 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);
}
}
DEBUG_TRACE (DEBUG::MTC, string_compose ("MTC::speed_and_position %1 %2\n", last.speed, last.position));
+ if (give_slave_full_control_over_transport_speed()) {
+ bool in_control = (session.slave_state() == Session::Running);
+ nframes64_t pic_want_locate = 0;
+ //nframes64_t slave_pos = session.audible_frame();
+ nframes64_t slave_pos = session.transport_frame();
+ static double average_speed = 0;
+
+ average_speed = pic->get_ratio (last.timestamp, last.position, slave_pos, in_control );
+ pic_want_locate = pic->want_locate();
+
+ if (in_control && pic_want_locate) {
+ last.speed = average_speed + (double) (pic_want_locate - session.transport_frame()) / (double)session.get_block_size();
+ std::cout << "locate req " << pic_want_locate << " speed: " << average_speed << "\n";
+ } else {
+ last.speed = average_speed;
+ }
+ }
+
if (last.speed == 0.0f) {
elapsed = 0;
/* now add the most recent timecode value plus the estimated elapsed interval */
- pos = elapsed + last.position;
+ pos = last.position + elapsed;
speed = last.speed;
DEBUG_TRACE (DEBUG::MTC, string_compose ("MTC::speed_and_position FINAL %1 %2\n", last.speed, pos));
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;
have_first_speed_accumulator = false;
speed_accumulator_cnt = 0;
- pic->out_of_bounds();
+ pic->reset();
}
void
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