[ardour-dev] dropframe patches

nick mainsbridge beatroot at optushome.com.au
Tue Apr 6 04:59:50 PDT 2004


these patches improve the display of dropframe smpte and correct the
recently reported "6/8" bug in the bbt ruler.
-- 
nick mainsbridge <beatroot at optushome.com.au>
-------------- next part --------------
--- ../Desktop/ardour/gtk_ardour/editor_rulers.cc	Wed Mar 10 06:39:44 2004
+++ gtk_ardour/editor_rulers.cc	Tue Apr  6 21:44:08 2004
@@ -804,10 +804,13 @@
 	jack_nframes_t spacer;
 	SMPTE_Time smpte;
 	gchar buf[16];
-	gint nmarks;
+	gint nmarks = 0;
 	gint n;
 	gint mark_modulo = 5;
+	gint extra_frames = 0;
+	gint skip_factor = 1;
 	bool show_bits = false;
+	bool show_frames = false;
 	bool show_seconds = false;
 	bool show_minutes = false;
 	bool show_hours = false;
@@ -827,84 +830,173 @@
 	range = upper - lower;
 
 	if (range < session->frames_per_smpte_frame()) { 
-		mark_interval = (jack_nframes_t)(fr / (2 * session->smpte_frames_per_second));
+		if ((int)session->smpte_frames_per_second == session->smpte_frames_per_second) {
+			mark_interval = (fr / (2 * (int)session->smpte_frames_per_second));
+		} else {
+			mark_interval = (jack_nframes_t)(fr / (2 * session->smpte_frames_per_second));
+		}
 		mark_modulo = 10;
 		show_bits = true;
-	} else if (range <= (jack_nframes_t) floor(fr * 0.1)) { /* 0-0.1 second */
-		mark_interval = (jack_nframes_t)(fr / session->smpte_frames_per_second);/* show single frames */
+	} else if (range <= (fr / 10)) { /* 0-0.1 second */
+		if ((int)session->smpte_frames_per_second == session->smpte_frames_per_second) {
+			mark_interval = fr / (int)session->smpte_frames_per_second;/* show single frames */
+		} else {
+			mark_interval = (jack_nframes_t)(fr / session->smpte_frames_per_second);/* show single frames */
+		}
 		mark_modulo = 1;
-	} else if (range <= fr/4) { /* 0-0.250 second */
-		mark_interval = (jack_nframes_t)(fr / session->smpte_frames_per_second);/* show single frames */
+		show_frames = true;
+	} else if (range <= (fr / 4)) { /* 0-0.250 second */
+		if ((int)session->smpte_frames_per_second == session->smpte_frames_per_second) {
+                        mark_interval = fr / (int)session->smpte_frames_per_second;/* show single frames */
+                } else {
+                        mark_interval = (jack_nframes_t)(fr / session->smpte_frames_per_second);/* show single frames */
+                }
 		mark_modulo = 1;
+		show_frames = true;
 	} else if (range <= fr) { /* 0-1 second */
-		mark_interval = (jack_nframes_t)(fr / session->smpte_frames_per_second);/* show single frames */
+		if ((int)session->smpte_frames_per_second == session->smpte_frames_per_second) {
+                        mark_interval = fr / (int)session->smpte_frames_per_second;/* show single frames */
+                } else {
+                        mark_interval = (jack_nframes_t)(fr / session->smpte_frames_per_second);/* show single frames */
+                }
+		show_frames = true;
 	} else if (range <= 2 * fr) { /* 1-2 seconds */
 		mark_modulo = (gint)(session->smpte_frames_per_second / 2);
 		if (session->smpte_frames_per_second == 24) {
-			mark_interval = (jack_nframes_t)(4 * fr / session->smpte_frames_per_second); /* show 4 frames */
+			if ((int)session->smpte_frames_per_second == session->smpte_frames_per_second) {
+	                         mark_interval = 4 * (fr / (int)session->smpte_frames_per_second);/* show single frames */
+	                 } else {
+                        	mark_interval = (jack_nframes_t)(4 * fr / session->smpte_frames_per_second);/* show 4 frames */
+                	}
 		} else {
-			mark_interval = (jack_nframes_t)(5 *  fr / session->smpte_frames_per_second);  /* show 5 frames */
+			if ((int)session->smpte_frames_per_second == session->smpte_frames_per_second) {
+                                  mark_interval = 5 * (fr / (int)session->smpte_frames_per_second);/* show single frames */
+                         } else {
+                                mark_interval = (jack_nframes_t)(5 * fr / session->smpte_frames_per_second);/* show 5 frames */
+                        }
 		}
+		show_frames = true;
 	} else if (range <= 8 * fr) { /* 2-5 seconds */
 		mark_modulo = (gint)session->smpte_frames_per_second;
                 if (session->smpte_frames_per_second == 24) {
-                        mark_interval = (jack_nframes_t)(4 * fr / session->smpte_frames_per_second); /* show 4 frames */
+			 if ((int)session->smpte_frames_per_second == session->smpte_frames_per_second) {
+                                  mark_interval = 4 * (fr / (int)session->smpte_frames_per_second);/* show single frames */
+                         } else {
+                                mark_interval = (jack_nframes_t)(4 * fr / session->smpte_frames_per_second);/* show 4 frames */
+                        }
                 } else {
-                        mark_interval = (jack_nframes_t)(5 *  fr / session->smpte_frames_per_second);  /* show 5 frames */
+			 if ((int)session->smpte_frames_per_second == session->smpte_frames_per_second) {
+                                   mark_interval = 5 * (fr / (int)session->smpte_frames_per_second);/* show single frames */
+                         } else {
+                                mark_interval = (jack_nframes_t)(5 * fr / session->smpte_frames_per_second);/* show 5 frames */
+                        }
                 }
+		show_frames = true;
 	} else if (range <= 16 * fr) { /* 8-16 seconds */
 		mark_interval =   fr; /* show seconds */
 		show_seconds = true;
+		skip_factor = 1;
 	} else if (range <= 30 * fr) { /* 10-30 seconds */
 		mark_interval =  fr; /* show 2 seconds */
 		show_seconds = true;
+		skip_factor = 1;
 	} else if (range <= 60 * fr) { /* 30-60 seconds */
 		mark_interval = 5 * fr; /* show 5 seconds */
 		show_seconds = true;
 		mark_modulo = 3;
+		skip_factor = 5;
 	} else if (range <= 2 * 60 * fr) { /* 1-2 minutes */
 		mark_interval = 5 * fr; /* show 5 seconds */
 		show_seconds = true;
 		mark_modulo = 3;
+		skip_factor = 5;
 	} else if (range <= 4 * 60 * fr) { /* 4 minutes */
 		mark_interval = 10 * fr; /* show 10 seconds */
 		show_seconds = true;
 		mark_modulo = 30;
+		skip_factor = 10;
 	} else if (range <= 10 * 60 * fr) { /* 10 minutes */
 		mark_interval = 30 * fr; /* show 30 seconds */
 		show_seconds = true;
 		mark_modulo = 60;
+		skip_factor = 30;
 	} else if (range <= 30 * 60 * fr) { /* 10-30 minutes */
 		mark_interval =  60 * fr; /* show 1 minute */
 		show_minutes = true;
+		skip_factor = 1;
+		if (session->smpte_drop_frames) {
+                        mark_interval -= 2 * session->frames_per_smpte_frame();
+                }
 	} else if (range <= 60 * 60 * fr) { /* 30 minutes - 1hr */
 		mark_interval = 2 * 60 * fr; /* show 2 minutes */
 		show_minutes = true;
 		 mark_modulo = 10;
+		skip_factor = 2;
+		if (session->smpte_drop_frames) {
+                        mark_interval -= 2 * skip_factor * session->frames_per_smpte_frame();
+                }
 	} else if (range <= 4 * 60 * 60 * fr) { /* 1 - 4 hrs*/
 		mark_interval = 5 * 60 * fr; /* show 10 minutes */
 		show_minutes = true;
 		mark_modulo = 30;
+		skip_factor = 5;
+		if (session->smpte_drop_frames) {
+                        mark_interval -= 2 * skip_factor * session->frames_per_smpte_frame();
+                }
 	} else if (range <= 8 * 60 * 60 * fr) { /* 4 - 8 hrs*/
-		mark_interval = 20 * 60 * fr; /* show 20 minutes */
+		mark_interval = 10 * 60 * fr; /* show 20 minutes */
 		show_minutes = true;
 		 mark_modulo = 60;
+		skip_factor = 10;
+		if (session->smpte_drop_frames) {
+                        mark_interval -= (20) * session->frames_per_smpte_frame();
+                }
 	} else if (range <= 16 * 60 * 60 * fr) { /* 16-24 hrs*/
 		mark_interval =  60 * 60 * fr; /* show 60 minutes */
 		show_hours = true;
                 mark_modulo = 2;
+		if (session->smpte_drop_frames) {
+                        mark_interval -= 108  * session->frames_per_smpte_frame();
+                }
 	} else {
 
 		/* not possible if jack_nframes_t is a 32 bit quantity */
 
 		mark_interval = 4 * 60 * 60 * fr; /* show 4 hrs */
+		mark_modulo = 8;
+		skip_factor = 4;
+		if (session->smpte_drop_frames) {
+                        mark_interval -= 108 * skip_factor * session->frames_per_smpte_frame();
+                }
 	}
 
-	nmarks = 1+ (range / mark_interval);
-	*marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * nmarks);
 	pos = ((lower + (mark_interval/2))/mark_interval) * mark_interval;
+	if (session->smpte_drop_frames) {
+		session->smpte_time (pos, smpte);
+		if (show_seconds) {
+			extra_frames = ((108 * smpte.hours) + (2 * smpte.minutes) - (2 * (smpte.minutes / 10)))  % (skip_factor * (int)session->smpte_frames_per_second);
+			nmarks = extra_frames;
+		} else if (show_minutes) {
+			if (smpte.minutes < 1) {
+				extra_frames = 0;
+			} else {
+				extra_frames =( - (12 * smpte.hours) - (2 * (smpte.minutes / 10)) - 2) % (60 * (int)session->smpte_frames_per_second);
+			}
+			nmarks = - extra_frames;
+		} else if (show_frames) {
+			 extra_frames = ((108 * smpte.hours) + (2 * smpte.minutes) - (2 * (smpte.minutes / 10)))  % (skip_factor * (int)session->smpte_frames_per_second);
+			nmarks = extra_frames;
+		} else {
+			extra_frames = 0;
+		}
+		pos -=  extra_frames * session->frames_per_smpte_frame(); 
+	}
+
 	pos += session->smpte_offset();
 
+	nmarks += 1 + (range / mark_interval);
+        *marks = (GtkCustomRulerMark *) g_malloc (sizeof(GtkCustomRulerMark) * nmarks);
+
 	if (show_bits) {
 		for (n = 0; n < nmarks; pos += mark_interval, ++n) {
                         session->smpte_time_subframes (pos, smpte);
@@ -934,8 +1026,13 @@
                         if ((smpte.seconds % mark_modulo) == 0) {
 				if (smpte.seconds == 0) {
 					(*marks)[n].style = GtkCustomRulerMarkMajor;
+					(*marks)[n].position = pos;
+					if ((session->smpte_drop_frames) && (smpte.minutes % 10 != 0) &&(smpte.frames == 2) && (mark_interval > (2 * session->frames_per_smpte_frame()))) {
+						pos -=  2 * session->frames_per_smpte_frame();
+					}
 				} else {
 					(*marks)[n].style = GtkCustomRulerMarkMinor;
+					(*marks)[n].position = pos;
 				}
 				if (smpte.negative) {
                                         snprintf (buf, sizeof(buf), "-%02ld:%02ld:%02ld:%02ld", smpte.hours, smpte.minutes, smpte.seconds, smpte.frames);
@@ -945,10 +1042,10 @@
                         } else {
                                 snprintf (buf, sizeof(buf)," ");
                                 (*marks)[n].style = GtkCustomRulerMarkMicro;
+				(*marks)[n].position = pos;
                                                                                                                    
                         }
                         (*marks)[n].label = g_strdup (buf);
-                        (*marks)[n].position = pos;
                 }
 	} else if (show_minutes) {
 		 for (n = 0; n < nmarks; pos += mark_interval, ++n) {
@@ -971,6 +1068,11 @@
                         }
                         (*marks)[n].label = g_strdup (buf);
                         (*marks)[n].position = pos;
+			if (session->smpte_drop_frames) {
+				if ((smpte.minutes % 10) == 0) {
+					pos += 2 * session->frames_per_smpte_frame();
+				}
+			}
                 }
 	} else if (show_hours) {
                  for (n = 0; n < nmarks; pos += mark_interval, ++n) {
@@ -989,24 +1091,34 @@
 	} else {
 		for (n = 0; n < nmarks; pos += mark_interval, ++n) {
 			session->smpte_time (pos, smpte);
-			if ((smpte.frames % mark_modulo) == 0) {
-				if ((smpte.frames == 0) || (session->smpte_drop_frames && (smpte.frames == 2))) {
+			if ((smpte.frames % mark_modulo) == 0)  {
 					(*marks)[n].style = GtkCustomRulerMarkMajor;
-				} else {
-					(*marks)[n].style = GtkCustomRulerMarkMinor;
-				}
-				if (smpte.negative) {
-					snprintf (buf, sizeof(buf), "-%02ld:%02ld:%02ld:%02ld", smpte.hours, smpte.minutes, smpte.seconds, smpte.frames);
-				} else {
-					snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld:%02ld", smpte.hours, smpte.minutes, smpte.seconds, smpte.frames);
-				}
+					(*marks)[n].position = pos;
+					if (smpte.negative) {
+                                        	snprintf (buf, sizeof(buf), "-%02ld:%02ld:%02ld:%02ld", smpte.hours, smpte.minutes, smpte.seconds, smpte.frames);
+                                	} else {
+                                        	snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld:%02ld", smpte.hours, smpte.minutes, smpte.seconds, smpte.frames);
+                                	}
+			} else if (session->smpte_drop_frames && (smpte.seconds == 0) && (smpte.frames == 2)) {
+					(*marks)[n].style = GtkCustomRulerMarkMajor;
+                                        (*marks)[n].position = pos;
+					if ((session->smpte_drop_frames) && (smpte.minutes % 10 != 0) && (smpte.frames == 2)) {
+                                                if (mark_interval > (2 * session->frames_per_smpte_frame())) {
+							pos -= 2 * session->frames_per_smpte_frame();
+						}
+                                        }
+					if (smpte.negative) {
+                                                snprintf (buf, sizeof(buf), "-%02ld:%02ld:%02ld:%02ld", smpte.hours, smpte.minutes, smpte.seconds, smpte.frames);
+                                        } else {
+                                                snprintf (buf, sizeof(buf), "%02ld:%02ld:%02ld:%02ld", smpte.hours, smpte.minutes, smpte.seconds, smpte.frames);
+					}
 			} else {
 				snprintf (buf, sizeof(buf)," ");
 				(*marks)[n].style = GtkCustomRulerMarkMicro;
+				(*marks)[n].position = pos;
 			
 			}
 			(*marks)[n].label = g_strdup (buf);
-			(*marks)[n].position = pos;
 		}
 	}
 
@@ -1127,7 +1239,7 @@
 				tick = 0;
 				((((*i).frame < position_of_helper) && bar_helper_on) || !we_need_ticks) ?
 					snprintf (buf, sizeof(buf), " ") : snprintf (buf, sizeof(buf), "%lu", (*i).beat);
-				if (((*i).beat % 4 == 3) || we_need_ticks) {
+				if (((*i).beat % 2 == 1) || we_need_ticks) {
 					(*marks)[n].style = GtkCustomRulerMarkMinor;
 				} else {
 					(*marks)[n].style = GtkCustomRulerMarkMicro;
@@ -1367,30 +1479,30 @@
 	}
 	range = upper - lower;
 
-	if (range < (jack_nframes_t) floor (fr * 0.02)) {
-		mark_interval = (jack_nframes_t) (fr * 0.01); /* show 1/100 seconds */
+	if (range <  (fr / 50)) {
+		mark_interval =  fr / 100; /* show 1/100 seconds */
 		mark_modulo = 10;
-	} else if (range <= (jack_nframes_t) floor(fr * 0.1)) { /* 0-0.1 second */
-		mark_interval = (jack_nframes_t) (fr * 0.02); /* show 1/50 seconds */
+	} else if (range <= (fr / 10)) { /* 0-0.1 second */
+		mark_interval = fr / 50; /* show 1/50 seconds */
 		mark_modulo = 20;
-	} else if (range <= fr/2) { /* 0-0.5 second */
-		mark_interval = (jack_nframes_t) (fr * 0.05);  /* show 1/20 seconds */
+	} else if (range <= (fr / 2)) { /* 0-0.5 second */
+		mark_interval = fr / 20;  /* show 1/20 seconds */
 		mark_modulo = 100;
 	} else if (range <= fr) { /* 0-1 second */
-		mark_interval = (jack_nframes_t) (fr * 0.1);  /* show 1/10 seconds */
+		mark_interval = fr / 10;  /* show 1/10 seconds */
 		mark_modulo = 200;
 	} else if (range <= 2 * fr) { /* 1-2 seconds */
-		mark_interval = (jack_nframes_t) floor (fr * 0.1); /* show 1/2 seconds */
+		mark_interval = fr / 2; /* show 1/2 seconds */
 		mark_modulo = 500;
 	} else if (range <= 8 * fr) { /* 2-5 seconds */
-		mark_interval =  (jack_nframes_t) floor (fr * 0.2); /* show 2 seconds */
+		mark_interval =  fr / 5; /* show 2 seconds */
 		mark_modulo = 1000;
 	} else if (range <= 16 * fr) { /* 8-16 seconds */
-		mark_interval =  1 * fr; /* show 1 seconds */
+		mark_interval =  fr; /* show 1 seconds */
 		show_seconds = true;
 		mark_modulo = 5;
 	} else if (range <= 30 * fr) { /* 10-30 seconds */
-		mark_interval = 1 * fr; /* show 10 seconds */
+		mark_interval =  fr; /* show 10 seconds */
 		show_seconds = true;
                 mark_modulo = 5;
 	} else if (range <= 60 * fr) { /* 30-60 seconds */
-------------- next part --------------
--- ../Desktop/ardour/libs/ardour/session_time.cc	Wed Mar 10 06:39:45 2004
+++ libs/ardour/session_time.cc	Mon Apr  5 18:44:35 2004
@@ -51,7 +51,11 @@
 {
 	smpte_frames_per_second = fps;
 	smpte_drop_frames = drop_frames;
-	_frames_per_smpte_frame = (jack_nframes_t) ceil ((double) _current_frame_rate / (double) smpte_frames_per_second);
+	if ((int) smpte_frames_per_second == smpte_frames_per_second) {
+		_frames_per_smpte_frame =  _current_frame_rate / (int) smpte_frames_per_second;
+	} else {
+		_frames_per_smpte_frame = (jack_nframes_t) ceil ((double) _current_frame_rate / (double) smpte_frames_per_second);
+	}
 	last_smpte_valid = false;
 
 	switch ((int) ceil (fps)) {


More information about the Ardour-Dev mailing list