Unbreak SMPTE ruler at non-30fps rates. Display 60fps properly. Use the same data...
authorNick Mainsbridge <beatroute@iprimus.com.au>
Fri, 8 Dec 2006 22:08:36 +0000 (22:08 +0000)
committerNick Mainsbridge <beatroute@iprimus.com.au>
Fri, 8 Dec 2006 22:08:36 +0000 (22:08 +0000)
git-svn-id: svn://localhost/ardour2/trunk@1198 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/session_time.cc
libs/surfaces/control_protocol/control_protocol/smpte.h
libs/surfaces/control_protocol/smpte.cc

index bc9778052fa33d5e2fb0527bd5a1a95bf9a378ed..61051e46325a3abd5b4c6c7a47a3b3e7a42c65e0 100644 (file)
@@ -281,6 +281,9 @@ Session::sample_to_smpte( nframes_t sample, SMPTE::Time& smpte, bool use_offset,
        if (!use_subframes) {
                smpte.subframes = 0;
        }
+       /* set frame rate and drop frame */
+       smpte.rate = Config->get_smpte_frames_per_second ();
+       smpte.drop = Config->get_smpte_drop_frames();
 }
 
 void
index 09c1c9616a341225380fb95766140bc708998ad2..b25a268aac45009c800885627dbb8b8753dbf5f9 100644 (file)
@@ -31,28 +31,18 @@ enum Wrap {
        HOURS
 };
 
-/** SMPTE frame rate (in frames per second).
- *
- * This should be eliminated in favour of a float to support arbitrary rates.
- */
-enum FPS {
-    MTC_24_FPS = 0,
-    MTC_25_FPS = 1,
-    MTC_30_FPS_DROP = 2,
-    MTC_30_FPS = 3
-};
-
 struct Time {
        bool       negative;
        uint32_t   hours;
        uint32_t   minutes;
        uint32_t   seconds;
-       uint32_t   frames;       ///< SMPTE frames (not audio samples)
-       uint32_t   subframes;    ///< Typically unused
-       FPS        rate;         ///< Frame rate of this Time
-       static FPS default_rate; ///< Rate to use for default constructor
+       uint32_t   frames;        ///< SMPTE frames (not audio samples)
+       uint32_t   subframes;     ///< Typically unused
+       float      rate;          ///< Frame rate of this Time
+       static float default_rate;///< Rate to use for default constructor
+       bool       drop;          ///< Whether this Time uses dropframe SMPTE
 
-       Time(FPS a_rate = default_rate) {
+       Time(float a_rate = default_rate) {
                negative = false;
                hours = 0;
                minutes = 0;
index 9b99d051600b2b2c4a4cbc1f41fdef8292e887a8..5df159a52bf45760253cec76258a783e9ce39709 100644 (file)
@@ -24,7 +24,7 @@
 
 namespace SMPTE {
 
-FPS Time::default_rate = MTC_30_FPS;
+float Time::default_rate = 30.0;
 
 
 /** Increment @a smpte by exactly one frame (keep subframes value).
@@ -51,34 +51,42 @@ increment( Time& smpte )
                }
                return wrap;
        }
-  
-       switch (smpte.rate) {
-       case MTC_24_FPS:
+
+       switch ((int)ceil(smpte.rate)) {
+       case 24:
                if (smpte.frames == 23) {
                        smpte.frames = 0;
                        wrap = SECONDS;
                }
                break;
-       case MTC_25_FPS:
+       case 25:
                if (smpte.frames == 24) {
                        smpte.frames = 0;
                        wrap = SECONDS;
                }
                break;
-       case MTC_30_FPS_DROP:
-               if (smpte.frames == 29) {
-                       if ( ((smpte.minutes + 1) % 10) && (smpte.seconds == 59) ) {
-                               smpte.frames = 2;
-                       }
-                       else {
-                               smpte.frames = 0;
-                       }
-                       wrap = SECONDS;
+       case 30:
+               if (smpte.drop) {
+                      if (smpte.frames == 29) {
+                             if ( ((smpte.minutes + 1) % 10) && (smpte.seconds == 59) ) {
+                                    smpte.frames = 2;
+                             }
+                             else {
+                                    smpte.frames = 0;
+                             }
+                             wrap = SECONDS;
+                      }
+               } else {
+
+                      if (smpte.frames == 29) {
+                             smpte.frames = 0;
+                             wrap = SECONDS;
+                      }
                }
                break;
-       case MTC_30_FPS:
-               if (smpte.frames == 29) {
-                       smpte.frames = 0;
+       case 60:
+               if (smpte.frames == 59) {
+                       smpte.frames = 0;
                        wrap = SECONDS;
                }
                break;
@@ -127,33 +135,41 @@ decrement( Time& smpte )
                return SECONDS;
        }
   
-       switch (smpte.rate) {
-       case MTC_24_FPS:
+       switch ((int)ceil(smpte.rate)) {
+       case 24:
                if (smpte.frames == 0) {
                        smpte.frames = 23;
                        wrap = SECONDS;
                }
                break;
-       case MTC_25_FPS:
+       case 25:
                if (smpte.frames == 0) {
                        smpte.frames = 24;
                        wrap = SECONDS;
                }
                break;
-       case MTC_30_FPS_DROP:
-               if ((smpte.minutes % 10) && (smpte.seconds == 0)) {
-                       if (smpte.frames <= 2) {
-                               smpte.frames = 29;
+       case 30:
+               if (smpte.drop) {
+                       if ((smpte.minutes % 10) && (smpte.seconds == 0)) {
+                               if (smpte.frames <= 2) {
+                                       smpte.frames = 29;
+                                       wrap = SECONDS;
+                               }
+                       } else if (smpte.frames == 0) {
+                               smpte.frames = 29;
+                               wrap = SECONDS;
+                       }
+                       
+               } else {
+                       if (smpte.frames == 0) {
+                               smpte.frames = 29;
                                wrap = SECONDS;
                        }
-               } else if (smpte.frames == 0) {
-                       smpte.frames = 29;
-                       wrap = SECONDS;
                }
                break;
-       case MTC_30_FPS:
-               if (smpte.frames == 0) {
-                       smpte.frames = 29;
+       case 60:
+               if (smpte.frames == 0) {
+                       smpte.frames = 59;
                        wrap = SECONDS;
                }
                break;
@@ -275,17 +291,19 @@ increment_seconds( Time& smpte )
                }
        } else {
                // Go to highest possible frame in this second
-               switch (smpte.rate) {
-               case MTC_24_FPS:
+         switch ((int)ceil(smpte.rate)) {
+               case 24:
                        smpte.frames = 23;
                        break;
-               case MTC_25_FPS:
+               case 25:
                        smpte.frames = 24;
                        break;
-               case MTC_30_FPS_DROP:
-               case MTC_30_FPS:
+               case 30:
                        smpte.frames = 29;
                        break;
+               case 60:
+                       smpte.frames = 59;
+                       break;
                }
     
                // Increment by one frame
@@ -305,17 +323,20 @@ seconds_floor( Time& smpte )
        frames_floor( smpte );
   
        // Go to lowest possible frame in this second
-       switch (smpte.rate) {
-       case MTC_24_FPS:
-       case MTC_25_FPS:
-       case MTC_30_FPS:
-               smpte.frames = 0;
-               break;
-       case MTC_30_FPS_DROP:
-               if ((smpte.minutes % 10) && (smpte.seconds == 0)) {
-                       smpte.frames = 2;
+       switch ((int)ceil(smpte.rate)) {
+       case 24:
+       case 25:
+       case 30:
+       case 60:
+               if (!(smpte.drop)) {
+                       smpte.frames = 0;
                } else {
-                       smpte.frames = 0;
+
+                       if ((smpte.minutes % 10) && (smpte.seconds == 0)) {
+                               smpte.frames = 2;
+                       } else {
+                               smpte.frames = 0;
+                       }
                }
                break;
        }