along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id$
*/
-
+#include <iostream>
#include <errno.h>
#include <poll.h>
#include <sys/types.h>
#include <unistd.h>
-#include <pbd/error.h>
-#include <pbd/failed_constructor.h>
-#include <pbd/pthread_utils.h>
+#include "pbd/error.h"
+#include "pbd/failed_constructor.h"
+#include "pbd/pthread_utils.h"
-#include <midi++/port.h>
-#include <ardour/slave.h>
-#include <ardour/session.h>
-#include <ardour/audioengine.h>
-#include <ardour/cycles.h>
+#include "midi++/port.h"
+#include "ardour/slave.h"
+#include "ardour/session.h"
+#include "ardour/audioengine.h"
+#include "ardour/cycles.h"
#include "i18n.h"
+using namespace std;
using namespace ARDOUR;
using namespace sigc;
using namespace MIDI;
MTC_Slave::MTC_Slave (Session& s, MIDI::Port& p)
: session (s)
{
+ can_notify_on_unknown_rate = true;
+
+ last_mtc_fps_byte = session.get_mtc_smpte_bits ();
+
rebind (p);
reset ();
}
}
void
-MTC_Slave::update_mtc_qtr (Parser& p)
+MTC_Slave::update_mtc_qtr (Parser& /*p*/)
{
cycles_t cnow = get_cycles ();
nframes_t now = session.engine().frame_time();
smpte.minutes = msg[2];
smpte.seconds = msg[1];
smpte.frames = msg[0];
+
+ last_mtc_fps_byte = msg[4];
- session.smpte_to_sample( smpte, mtc_frame, true, false );
+ switch (msg[4]) {
+ case MTC_24_FPS:
+ smpte.rate = 24;
+ smpte.drop = false;
+ can_notify_on_unknown_rate = true;
+ break;
+ case MTC_25_FPS:
+ smpte.rate = 25;
+ smpte.drop = false;
+ can_notify_on_unknown_rate = true;
+ break;
+ case MTC_30_FPS_DROP:
+ smpte.rate = 30;
+ smpte.drop = true;
+ can_notify_on_unknown_rate = true;
+ break;
+ case MTC_30_FPS:
+ smpte.rate = 30;
+ smpte.drop = false;
+ can_notify_on_unknown_rate = true;
+ break;
+ default:
+ /* throttle error messages about unknown MTC rates */
+ if (can_notify_on_unknown_rate) {
+ error << string_compose (_("Unknown rate/drop value %1 in incoming MTC stream, session values used instead"),
+ (int) msg[4])
+ << endmsg;
+ can_notify_on_unknown_rate = false;
+ }
+ smpte.rate = session.smpte_frames_per_second();
+ smpte.drop = session.smpte_drop_frames();
+ }
+
+ session.smpte_to_sample (smpte, mtc_frame, true, false);
if (was_full) {
current.guard2++;
session.request_locate (mtc_frame, false);
+ session.request_transport_speed (0);
update_mtc_status (MIDI::Parser::MTC_Stopped);
reset ();
void
MTC_Slave::handle_locate (const MIDI::byte* mmc_tc)
{
- MIDI::byte mtc[4];
+ MIDI::byte mtc[5];
+ mtc[4] = last_mtc_fps_byte;
mtc[3] = mmc_tc[0] & 0xf; /* hrs only */
mtc[2] = mmc_tc[1];
mtc[1] = mmc_tc[2];
}
bool
-MTC_Slave::speed_and_position (float& speed, nframes_t& pos)
+MTC_Slave::speed_and_position (double& speed, nframes_t& pos)
{
nframes_t now = session.engine().frame_time();
SafeTime last;
nframes_t frame_rate;
nframes_t elapsed;
- float speed_now;
+ double speed_now;
read_current (&last);
mtc_speed = 0;
pos = last.position;
session.request_locate (pos, false);
+ session.request_transport_speed (0);
update_mtc_status (MIDI::Parser::MTC_Stopped);
reset();
return false;
frame_rate = session.frame_rate();
- speed_now = (float) ((last.position - first_mtc_frame) / (double) (now - first_mtc_time));
+ speed_now = (double) ((last.position - first_mtc_frame) / (double) (now - first_mtc_time));
accumulator[accumulator_index++] = speed_now;
}
if (have_first_accumulated_speed) {
- float total = 0;
+ double total = 0;
for (int32_t i = 0; i < accumulator_size; ++i) {
total += accumulator[i];
return true;
}
-nframes_t
+ARDOUR::nframes_t
MTC_Slave::resolution() const
{
return (nframes_t) session.frames_per_smpte_frame();