add timecode format parser
authorRobin Gareus <robin@gareus.org>
Tue, 13 Nov 2012 16:14:25 +0000 (16:14 +0000)
committerRobin Gareus <robin@gareus.org>
Tue, 13 Nov 2012 16:14:25 +0000 (16:14 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@13479 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/timecode/src/time.cc
libs/timecode/timecode/time.h

index 10dfd2fb59df110358d712fe605de86203a8364e..b39da34d6ddeded63ba5adbed3bd955be7da89b4 100644 (file)
@@ -623,6 +623,24 @@ std::string timecode_format_sampletime (
        return timecode_format_time(t);
 }
 
+bool parse_timecode_format(std::string tc, Timecode::Time &TC) {
+       char negative[2];
+       char ignored[2];
+       TC.subframes = 0;
+       if (sscanf (tc.c_str(), "%[- ]%" PRId32 ":%" PRId32 ":%" PRId32 "%[:;]%" PRId32,
+                               negative, &TC.hours, &TC.minutes, &TC.seconds, ignored, &TC.frames) != 6) {
+               TC.hours = TC.minutes = TC.seconds = TC.frames = 0;
+               TC.negative = false;
+               return false;
+       }
+       if (negative[0]=='-') {
+               TC.negative = true;
+       } else {
+               TC.negative = false;
+       }
+       return true;
+}
+
 void
 timecode_to_sample(
                Timecode::Time& timecode, int64_t& sample,
index 23655bfe5ddc653707b87bf19361308e034e3156..dcd537c7e5791ec6b696f9ab534f668778904229 100644 (file)
@@ -112,6 +112,8 @@ std::string timecode_format_sampletime (
                double timecode_frames_per_second, bool timecode_drop_frames
                );
 
+bool parse_timecode_format(std::string tc, Timecode::Time &TC);
+
 void
 timecode_to_sample(
                Timecode::Time& timecode, int64_t& sample,