2 Copyright (C) 2006-2010 Paul Davis
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Lesser General Public License as published
6 by the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 675 Mass Ave, Cambridge, MA 02139, USA.
19 #ifndef __timecode_time_h__
20 #define __timecode_time_h__
26 #include "timecode/visibility.h"
53 struct LIBTIMECODE_API Time {
58 uint32_t frames; ///< Timecode frames (not audio frames)
59 uint32_t subframes; ///< Typically unused
60 double rate; ///< Frame rate of this Time
61 static double default_rate; ///< Rate to use for default constructor
62 bool drop; ///< Whether this Time uses dropframe Timecode
64 Time (double a_rate = default_rate) {
72 drop = (lrintf(100.f * (float)a_rate) == (long)2997);
75 bool operator== (const Time& other) const {
76 return negative == other.negative && hours == other.hours &&
77 minutes == other.minutes && seconds == other.seconds &&
78 frames == other.frames && subframes == other.subframes &&
79 rate == other.rate && drop == other.drop;
82 std::ostream& print (std::ostream& ostr) const {
86 ostr << hours << ':' << minutes << ':' << seconds << ':'
87 << frames << '.' << subframes
88 << " @" << rate << (drop ? " drop" : " nondrop");
94 Wrap LIBTIMECODE_API increment (Time& timecode, uint32_t);
95 Wrap LIBTIMECODE_API decrement (Time& timecode, uint32_t);
96 Wrap LIBTIMECODE_API increment_subframes (Time& timecode, uint32_t);
97 Wrap LIBTIMECODE_API decrement_subframes (Time& timecode, uint32_t);
98 Wrap LIBTIMECODE_API increment_seconds (Time& timecode, uint32_t);
99 Wrap LIBTIMECODE_API increment_minutes (Time& timecode, uint32_t);
100 Wrap LIBTIMECODE_API increment_hours (Time& timecode, uint32_t);
101 void LIBTIMECODE_API frames_floot (Time& timecode);
102 void LIBTIMECODE_API seconds_floor (Time& timecode);
103 void LIBTIMECODE_API minutes_floor (Time& timecode);
104 void LIBTIMECODE_API hours_floor (Time& timecode);
106 double LIBTIMECODE_API timecode_to_frames_per_second(TimecodeFormat const t);
107 bool LIBTIMECODE_API timecode_has_drop_frames(TimecodeFormat const t);
109 std::string LIBTIMECODE_API timecode_format_name (TimecodeFormat const t);
111 std::string LIBTIMECODE_API timecode_format_time (Timecode::Time const timecode);
113 std::string LIBTIMECODE_API timecode_format_sampletime (
115 double sample_sample_rate,
116 double timecode_frames_per_second, bool timecode_drop_frames
119 bool LIBTIMECODE_API parse_timecode_format(std::string tc, Timecode::Time &TC);
121 void LIBTIMECODE_API timecode_to_sample(
122 Timecode::Time& timecode, int64_t& sample,
123 bool use_offset, bool use_subframes,
124 /* Note - framerate info is taken from Timecode::Time& */
125 double sample_sample_rate /**< may include pull up/down */,
126 uint32_t subframes_per_frame /**< must not be 0 if use_subframes==true */,
127 /* optional offset - can be improved: function pointer to lazily query this*/
128 bool offset_is_negative, int64_t offset_samples
131 void LIBTIMECODE_API sample_to_timecode (
132 int64_t sample, Timecode::Time& timecode,
133 bool use_offset, bool use_subframes,
135 double timecode_frames_per_second,
136 bool timecode_drop_frames,
137 double sample_sample_rate/**< can include pull up/down */,
138 uint32_t subframes_per_frame,
139 /* optional offset - can be improved: function pointer to lazily query this*/
140 bool offset_is_negative, int64_t offset_samples
144 } // namespace Timecode
146 extern LIBTIMECODE_API std::ostream& operator<< (std::ostream& ostr, const Timecode::Time& t);
148 #endif // __timecode_time_h__