Remove unnecessary 0 checks before delete; see http://www.parashift.com/c++-faq-lite...
[ardour.git] / libs / ardour / mtc_slave.cc
index a86a3e9014d2da79aca68ab43c4341f166cdc386..1a8cd589da22f075f3c84bdeee592c2fec3d9c17 100644 (file)
@@ -16,7 +16,7 @@
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
 */
-
+#include <iostream>
 #include <errno.h>
 #include <poll.h>
 #include <sys/types.h>
@@ -43,6 +43,8 @@ MTC_Slave::MTC_Slave (Session& s, MIDI::Port& p)
 {
        can_notify_on_unknown_rate = true;
 
+       last_mtc_fps_byte = session.get_mtc_smpte_bits ();
+
        rebind (p);
        reset ();
 }
@@ -96,6 +98,8 @@ MTC_Slave::update_mtc_time (const byte *msg, bool was_full)
        smpte.seconds = msg[1];
        smpte.frames = msg[0];
 
+       last_mtc_fps_byte = msg[4];
+       
        switch (msg[4]) {
        case MTC_24_FPS:
                smpte.rate = 24;
@@ -120,7 +124,9 @@ MTC_Slave::update_mtc_time (const byte *msg, bool was_full)
        default:
                /* throttle error messages about unknown MTC rates */
                if (can_notify_on_unknown_rate) {
-                       error << _("Unknown rate/drop value in incoming MTC stream, session values used instead") << endmsg;
+                       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();
@@ -137,6 +143,7 @@ MTC_Slave::update_mtc_time (const byte *msg, bool was_full)
                current.guard2++;        
                
                session.request_locate (mtc_frame, false);       
+               session.request_transport_speed (0);
                update_mtc_status (MIDI::Parser::MTC_Stopped);   
 
                reset ();
@@ -169,8 +176,9 @@ MTC_Slave::update_mtc_time (const byte *msg, bool was_full)
 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];
@@ -271,6 +279,7 @@ MTC_Slave::speed_and_position (float& speed, nframes_t& pos)
                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;
@@ -325,7 +334,7 @@ MTC_Slave::speed_and_position (float& speed, nframes_t& pos)
        return true;
 }
 
-nframes_t
+ARDOUR::nframes_t
 MTC_Slave::resolution() const
 {
        return (nframes_t) session.frames_per_smpte_frame();