[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20724] branches/blender2.5/blender/source /blender/editors/animation/anim_draw.c: 2. 5 - Time indicator label for time-codes now draws in SMPTE format

Joshua Leung aligorith at gmail.com
Mon Jun 8 04:33:25 CEST 2009


Revision: 20724
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20724
Author:   aligorith
Date:     2009-06-08 04:33:24 +0200 (Mon, 08 Jun 2009)

Log Message:
-----------
2.5 - Time indicator label for time-codes now draws in SMPTE format

When an Animation Editor is showing timing in 'seconds' (instead of frames), the indicator label is now drawn with the same style of timecodes as the scrollbar labels are.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/editors/animation/anim_draw.c

Modified: branches/blender2.5/blender/source/blender/editors/animation/anim_draw.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/animation/anim_draw.c	2009-06-08 01:29:58 UTC (rev 20723)
+++ branches/blender2.5/blender/source/blender/editors/animation/anim_draw.c	2009-06-08 02:33:24 UTC (rev 20724)
@@ -28,6 +28,7 @@
  
 #include <string.h>
 #include <stdio.h>
+#include <math.h>
 
 #include "DNA_anim_types.h"
 #include "DNA_action_types.h"
@@ -81,8 +82,52 @@
 	UI_view2d_getscale(v2d, &xscale, &yscale);
 	glScalef(1.0f/xscale, 1.0f, 1.0f);
 	
-	if (time) 
-		sprintf(str, "   %.2f", FRA2TIME(CFRA));
+	if (time) {
+		/* SMPTE timecode style:
+		 *	- In general, minutes and seconds should be shown, as most clips will be
+		 *	  within this length. Hours will only be included if relevant.
+		 *	- Only show frames when zoomed in enough for them to be relevant 
+		 *	  (using separator convention of ';' for frames, ala QuickTime).
+		 *	  When showing frames, use slightly different display to avoid confusion with mm:ss format
+		 */
+		float val= FRA2TIME(CFRA);
+		int hours=0, minutes=0, seconds=0, frames=0;
+		char neg[2]= "";
+		
+		/* get values */
+		if (val < 0) {
+			/* correction for negative values */
+			sprintf(neg, "-");
+			val = -val;
+		}
+		if (val >= 3600) {
+			/* hours */
+			/* XXX should we only display a single digit for hours since clips are 
+			 * 	   VERY UNLIKELY to be more than 1-2 hours max? However, that would 
+			 *	   go against conventions...
+			 */
+			hours= (int)val / 3600;
+			val= (float)fmod(val, 3600);
+		}
+		if (val >= 60) {
+			/* minutes */
+			minutes= (int)val / 60;
+			val= (float)fmod(val, 60);
+		}
+		{
+			/* seconds + frames
+			 *	Frames are derived from 'fraction' of second. We need to perform some additional rounding
+			 *	to cope with 'half' frames, etc., which should be fine in most cases
+			 */
+			seconds= (int)val;
+			frames= (int)floor( ((val - seconds) * FPS) + 0.5f );
+		}
+		
+		/* print timecode to temp string buffer */
+		if (hours) sprintf(str, "   %s%02d:%02d:%02d;%02d", neg, hours, minutes, seconds, frames);
+		else if (minutes) sprintf(str, "   %s%02d:%02d;%02d", neg, minutes, seconds, frames);
+		else sprintf(str, "   %s%d;%02d", neg, seconds, frames);
+	}
 	else 
 		sprintf(str, "   %d", CFRA);
 	slen= (short)UI_GetStringWidth(str) - 1;





More information about the Bf-blender-cvs mailing list