Hmm, that adds complications for 2 reasons, fromtext() (and
text_to_seconds) isn't frame-accurate since it rounds to "samples" which
can't be frames since "samplerate" is an int, and h:m:s:f can't be
negative so a "reverse" checkbox is needed to make the timecode count
backwards.  The reverse checkbox is probably more intuitive anyway.

Ok, so here is a patch to correct text_to_seconds (and add 
text_to_frames).  The fromtext() function should remain just as accurate 
as before.  Does this look ok?  If so, I'll send an updated patch for the 
titler...

Thanks.



On Fri, 24 Feb 2006, Andraz Tori wrote:

>I believe that offset should be entered in h:m:s:f format... can you fix
>that?
>
>
>And inlined attachments are not good, they get screwed by email
>readers... Attachments are much better as you have correctly guessed.
>
>bye
>andra?
>
>On ?et, 2006-02-23 at 22:30 -0500, Dan Streetman wrote:
>> Hi,
>> 
>> I needed to improve the titler timecode to generate a working clock so I 
>> added 2 fields, an offset (in frames) and a format.  The offset allows you 
>> to set the timecode value to any time (frame) you want (although without a 
>> multiplier it's still fixed to playback time of course).  The format 
>> displays the timecode in various formats from units.C.
>> 
>> Is the preference on the list to attach patches?  I usually like inline 
>> patches, but I'll do whatever :)  I've attached the patch this time.
>
>
>_______________________________________________
>Cinelerra mailing list
>[email protected]
>https://init.linpro.no/mailman/skolelinux.no/listinfo/cinelerra
>

-- 
Dan Streetman
[EMAIL PROTECTED]
---------------------
186,272 miles per second:
It isn't just a good idea, it's the law!
Index: guicast/units.h
===================================================================
--- guicast/units.h     (revision 746)
+++ guicast/units.h     (working copy)
@@ -138,6 +138,12 @@
                                int time_format, 
                                float frame_rate, 
                                float frames_per_foot);   
+// Convert text to frames
+       static int64_t text_to_frames(char *text, 
+                               int samplerate, 
+                               int time_format, 
+                               float frame_rate, 
+                               float frames_per_foot);   
 
        static char* print_time_format(int time_format, char *string);
 
Index: guicast/units.C
===================================================================
--- guicast/units.C     (revision 746)
+++ guicast/units.C     (working copy)
@@ -276,7 +276,7 @@
        return totext(text, (double)samples / samplerate, time_format, 
samplerate, frame_rate, frames_per_foot);
 }    
 
-int64_t Units::fromtext(char *text, 
+double Units::text_to_seconds(char *text, 
                        int samplerate, 
                        int time_format, 
                        float frame_rate,
@@ -286,13 +286,11 @@
        int64_t feet;
        double seconds;
        char string[BCTEXTLEN];
-       
+
        switch(time_format)
        {
                case TIME_SECONDS:
-                       seconds = atof(text);
-                       return (int64_t)(seconds * samplerate);
-                       break;
+                       return atof(text);
 
                case TIME_HMS:
                case TIME_HMS2:
@@ -319,9 +317,7 @@
                        string[j] = 0;
                        seconds = atof(string);
 
-                       total_samples = (uint64_t)(((double)seconds + minutes * 
60 + hours * 3600) * samplerate);
-                       return total_samples;
-                       break;
+                       return (seconds + minutes*60 + hours*3600);
 
                case TIME_HMSF:
 // get hours
@@ -355,21 +351,17 @@
                        string[j] = 0;
                        frames = atol(string);
                        
-                       total_samples = (int64_t)(((float)frames / frame_rate + 
seconds + minutes*60 + hours*3600) * samplerate);
-                       return total_samples;
-                       break;
+                       return (frames / frame_rate) + (seconds + minutes*60 + 
hours*3600);
 
                case TIME_SAMPLES:
-                       return atol(text);
-                       break;
+                       return atol(text) / samplerate;
                
                case TIME_SAMPLES_HEX:
                        sscanf(text, "%x", &total_samples);
-                       return total_samples;
+                       return total_samples / samplerate;
                
                case TIME_FRAMES:
-                       return (int64_t)(atof(text) / frame_rate * samplerate);
-                       break;
+                       return atof(text) / frame_rate;
                
                case TIME_FEET_FRAMES:
 // Get feet
@@ -387,23 +379,36 @@
                        while(text[i] >=48 && text[i] <= 57 && text[i] != 0 && 
j < 10) string[j++] = text[i++];
                        string[j] = 0;
                        frames = atol(string);
-                       return (int64_t)(((float)feet * frames_per_foot + 
frames) / frame_rate * samplerate);
-                       break;
+                       return ((float)feet * frames_per_foot + frames) / 
frame_rate;
        }
        return 0;
 }
 
-double Units::text_to_seconds(char *text, 
+// the return value is in samples
+int64_t Units::fromtext(char *text, 
+                       int samplerate, 
+                       int time_format, 
+                       float frame_rate,
+                       float frames_per_foot)
+{
+       return (int64_t)(samplerate * text_to_seconds(text, 
+               samplerate, 
+               time_format, 
+               frame_rate, 
+               frames_per_foot));
+}
+
+int64_t Units::text_to_frames(char *text, 
                                int samplerate, 
                                int time_format, 
                                float frame_rate, 
                                float frames_per_foot)
 {
-       return (double)fromtext(text, 
+       return (int64_t)(frame_rate * text_to_seconds(text, 
                samplerate, 
                time_format, 
                frame_rate, 
-               frames_per_foot) / samplerate;
+               frames_per_foot));
 }
 
 

Reply via email to