~ubuntu-branches/ubuntu/utopic/ardour3/utopic

« back to all changes in this revision

Viewing changes to libs/timecode/timecode/time.h

  • Committer: Package Import Robot
  • Author(s): Felipe Sateler
  • Date: 2013-09-21 19:05:02 UTC
  • Revision ID: package-import@ubuntu.com-20130921190502-8gsftrku6jnzhd7v
Tags: upstream-3.4~dfsg
ImportĀ upstreamĀ versionĀ 3.4~dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
enum TimecodeFormat {
 
36
        timecode_23976,
 
37
        timecode_24,
 
38
        timecode_24976,
 
39
        timecode_25,
 
40
        timecode_2997,
 
41
        timecode_2997drop,
 
42
        timecode_2997000,
 
43
        timecode_2997000drop,
 
44
        timecode_30,
 
45
        timecode_30drop,
 
46
        timecode_5994,
 
47
        timecode_60
 
48
};
 
49
 
 
50
struct Time {
 
51
        bool          negative;
 
52
        uint32_t      hours;
 
53
        uint32_t      minutes;
 
54
        uint32_t      seconds;
 
55
        uint32_t      frames;        ///< Timecode frames (not audio samples)
 
56
        uint32_t      subframes;     ///< Typically unused
 
57
        double        rate;          ///< Frame rate of this Time
 
58
        static double default_rate;  ///< Rate to use for default constructor
 
59
        bool          drop;          ///< Whether this Time uses dropframe Timecode
 
60
 
 
61
        Time (double a_rate = default_rate) {
 
62
                negative = false;
 
63
                hours = 0;
 
64
                minutes = 0;
 
65
                seconds = 0;
 
66
                frames = 0;
 
67
                subframes = 0;
 
68
                rate = a_rate;
 
69
        }
 
70
        
 
71
        bool operator== (const Time& other) const {
 
72
                return negative == other.negative && hours == other.hours &&
 
73
                       minutes == other.minutes && seconds == other.seconds &&
 
74
                       frames == other.frames && subframes == other.subframes &&
 
75
                       rate == other.rate && drop == other.drop;
 
76
        }
 
77
 
 
78
        std::ostream& print (std::ostream& ostr) const {
 
79
                if (negative) {
 
80
                        ostr << '-';
 
81
                }
 
82
                ostr << hours << ':' << minutes << ':' << seconds << ':'
 
83
                     << frames << '.' << subframes
 
84
                     << " @" << rate << (drop ? " drop" : " nondrop");
 
85
                return ostr;
 
86
        }
 
87
 
 
88
};
 
89
 
 
90
Wrap increment (Time& timecode, uint32_t);
 
91
Wrap decrement (Time& timecode, uint32_t);
 
92
Wrap increment_subframes (Time& timecode, uint32_t);
 
93
Wrap decrement_subframes (Time& timecode, uint32_t);
 
94
Wrap increment_seconds (Time& timecode, uint32_t);
 
95
Wrap increment_minutes (Time& timecode, uint32_t);
 
96
Wrap increment_hours (Time& timecode, uint32_t);
 
97
void frames_floor (Time& timecode);
 
98
void seconds_floor (Time& timecode);
 
99
void minutes_floor (Time& timecode);
 
100
void hours_floor (Time& timecode);
 
101
 
 
102
double timecode_to_frames_per_second(TimecodeFormat const t);
 
103
bool timecode_has_drop_frames(TimecodeFormat const t);
 
104
 
 
105
std::string timecode_format_name (TimecodeFormat const t);
 
106
 
 
107
std::string timecode_format_time (Timecode::Time const timecode);
 
108
 
 
109
std::string timecode_format_sampletime (
 
110
                int64_t sample,
 
111
                double sample_frame_rate,
 
112
                double timecode_frames_per_second, bool timecode_drop_frames
 
113
                );
 
114
 
 
115
bool parse_timecode_format(std::string tc, Timecode::Time &TC);
 
116
 
 
117
void
 
118
timecode_to_sample(
 
119
                Timecode::Time& timecode, int64_t& sample,
 
120
                bool use_offset, bool use_subframes,
 
121
    /* Note - framerate info is taken from Timecode::Time& */
 
122
                double sample_frame_rate /**< may include pull up/down */,
 
123
                uint32_t subframes_per_frame /**< must not be 0 if use_subframes==true */,
 
124
    /* optional offset  - can be improved: function pointer to lazily query this*/
 
125
                bool offset_is_negative, int64_t offset_samples
 
126
                );
 
127
 
 
128
void sample_to_timecode (
 
129
                int64_t sample, Timecode::Time& timecode,
 
130
                bool use_offset, bool use_subframes,
 
131
    /* framerate info */
 
132
                double timecode_frames_per_second,
 
133
                bool   timecode_drop_frames,
 
134
                double sample_frame_rate/**< can include pull up/down */,
 
135
                uint32_t subframes_per_frame,
 
136
    /* optional offset  - can be improved: function pointer to lazily query this*/
 
137
                bool offset_is_negative, int64_t offset_samples
 
138
                );
 
139
 
 
140
 
 
141
} // namespace Timecode
 
142
 
 
143
std::ostream& operator<< (std::ostream& ostr, const Timecode::Time& t);
 
144
 
 
145
#endif  // __timecode_time_h__