Clean up libtimecode, make license of bbt_time.h LGPL.
[ardour.git] / libs / timecode / timecode / time.h
1 /*
2         Copyright (C) 2006-2010 Paul Davis
3         
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.
8         
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
12         for more details.
13         
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.
17 */
18
19 #ifndef __timecode_time_h__
20 #define __timecode_time_h__
21
22 #include <ostream>
23 #include <inttypes.h>
24
25 namespace Timecode {
26
27 enum Wrap {
28         NONE = 0,
29         FRAMES,
30         SECONDS,
31         MINUTES,
32         HOURS
33 };
34
35 struct Time {
36         bool         negative;
37         uint32_t     hours;
38         uint32_t     minutes;
39         uint32_t     seconds;
40         uint32_t     frames;        ///< Timecode frames (not audio samples)
41         uint32_t     subframes;     ///< Typically unused
42         float        rate;          ///< Frame rate of this Time
43         static float default_rate;  ///< Rate to use for default constructor
44         bool         drop;          ///< Whether this Time uses dropframe Timecode
45
46         Time (float a_rate = default_rate) {
47                 negative = false;
48                 hours = 0;
49                 minutes = 0;
50                 seconds = 0;
51                 frames = 0;
52                 subframes = 0;
53                 rate = a_rate;
54         }
55
56         std::ostream& print (std::ostream& ostr) const {
57                 if (negative) {
58                         ostr << '-';
59                 }
60                 ostr << hours << ':' << minutes << ':' << seconds << ':'
61                      << frames << '.' << subframes
62                      << " @" << rate << (drop ? " drop" : " nondrop");
63                 return ostr;
64         }
65
66 };
67
68 Wrap increment (Time& timecode, uint32_t);
69 Wrap decrement (Time& timecode, uint32_t);
70 Wrap increment_subframes (Time& timecode, uint32_t);
71 Wrap decrement_subframes (Time& timecode, uint32_t);
72 Wrap increment_seconds (Time& timecode, uint32_t);
73 Wrap increment_minutes (Time& timecode, uint32_t);
74 Wrap increment_hours (Time& timecode, uint32_t);
75 void frames_floor (Time& timecode);
76 void seconds_floor (Time& timecode);
77 void minutes_floor (Time& timecode);
78 void hours_floor (Time& timecode);
79
80 } // namespace Timecode
81
82 std::ostream& operator<< (std::ostream& ostr, const Timecode::Time& t);
83
84 #endif  // __timecode_time_h__