[ardour-dev] Reverse motion MTC quarter frames

Joshua Leach leachj at cae.wisc.edu
Mon Jun 28 21:49:09 PDT 2004


Sorry I didn't get this here for the beta17 release, but here is a
small patch once again to session_midi.cc. This one enables ardour to
generate quarter frame messages while rolling backward.

-- 
----------------------------
-Joshua Leach
-------------- next part --------------
--- ardour-0.9beta16.1/libs/ardour/session_midi.cc	2004-06-28 23:14:47.215627048 -0500
+++ /usr/local/src/ardour-0.9beta16.1/libs/ardour/session_midi.cc	2004-06-28 23:25:59.979351416 -0500
@@ -613,18 +613,23 @@
 	jack_nframes_t elapsed_smpte_frames;
 	jack_nframes_t current_smpte_frame;
 	unsigned long n;
+	long incr;
 	SMPTE_Time smpte;
 
 	current_smpte_frame = (jack_nframes_t) floor ((double) _transport_frame /
 						 ((1.0/smpte_frames_per_second)/
 						  (1.0/_current_frame_rate)));
 
-	if (current_smpte_frame < last_mtc_smpte_frame) {
-		/* XXX backwards motion ... help ! */
-		return 0;
-	}
-
-	elapsed_smpte_frames = current_smpte_frame - last_mtc_smpte_frame;
+	if(current_smpte_frame < last_mtc_smpte_frame)
+	  {
+	    incr=-2;
+	    elapsed_smpte_frames = last_mtc_smpte_frame - current_smpte_frame;
+	  }
+	else
+	  {
+	    incr=2;
+	    elapsed_smpte_frames = current_smpte_frame - last_mtc_smpte_frame;
+	  }
 
 	/* Assumption: elapsed frames < smpte_frames_per_second
 
@@ -653,16 +658,28 @@
 		for (n = 0; n < elapsed_smpte_frames; n += 2) {
 			
 			hb = mtc_smpte_bits|smpte.hours;
-			
-			mtc_msg[1] =  0x00 | (smpte.frames & 0xf);
-			mtc_msg[3] =  0x10 | ((smpte.frames & 0xf0) >> 4);
-			mtc_msg[5] =  0x20 | (smpte.seconds & 0xf);
-			mtc_msg[7] =  0x30 | ((smpte.seconds & 0xf0) >> 4);
-			mtc_msg[9] =  0x40 | (smpte.minutes & 0xf);
-			mtc_msg[11] = 0x50 | ((smpte.minutes & 0xf0) >> 4);
-			mtc_msg[13] = 0x60 | (hb & 0xf);
-			mtc_msg[15] = 0x70 | ((hb & 0xf0) >> 4);
-			
+			if(incr>0)
+			  {
+			    mtc_msg[1] =  0x00 | (smpte.frames & 0xf);
+			    mtc_msg[3] =  0x10 | ((smpte.frames & 0xf0) >> 4);
+			    mtc_msg[5] =  0x20 | (smpte.seconds & 0xf);
+			    mtc_msg[7] =  0x30 | ((smpte.seconds & 0xf0) >> 4);
+			    mtc_msg[9] =  0x40 | (smpte.minutes & 0xf);
+			    mtc_msg[11] = 0x50 | ((smpte.minutes & 0xf0) >> 4);
+			    mtc_msg[13] = 0x60 | (hb & 0xf);
+			    mtc_msg[15] = 0x70 | ((hb & 0xf0) >> 4);
+			  }
+			else
+			  {
+			    mtc_msg[15] =  0x00 | (smpte.frames & 0xf);
+			    mtc_msg[13] =  0x10 | ((smpte.frames & 0xf0) >> 4);
+			    mtc_msg[11] =  0x20 | (smpte.seconds & 0xf);
+			    mtc_msg[9] =  0x30 | ((smpte.seconds & 0xf0) >> 4);
+			    mtc_msg[7] =  0x40 | (smpte.minutes & 0xf);
+			    mtc_msg[5] = 0x50 | ((smpte.minutes & 0xf0) >> 4);
+			    mtc_msg[3] = 0x60 | (hb & 0xf);
+			    mtc_msg[1] = 0x70 | ((hb & 0xf0) >> 4);			    
+			  }
 			if (_mtc_port->midimsg (mtc_msg, sizeof (mtc_msg))) {
 				error << compose(_("Session: cannot send quarter-frame MTC message (%1)"), strerror (errno)) 
 				      << endmsg;
@@ -675,8 +692,8 @@
 				return -1;
 			}
 			
-			smpte.frames += 2;
-			last_mtc_smpte_frame += 2;
+			smpte.frames += incr;
+			last_mtc_smpte_frame += incr;
 		}
 	}
 


More information about the Ardour-Dev mailing list