Ardour  8.12
time.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Paul Davis <paul@linuxaudiosystems.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * 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,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License 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  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #ifndef __timecode_time_h__
20 #define __timecode_time_h__
21 
22 #include <cmath>
23 #include <inttypes.h>
24 #include <ostream>
25 
26 #include "temporal/visibility.h"
27 
28 namespace Timecode
29 {
30 
31 enum Wrap {
32  NONE = 0,
36  HOURS
37 };
38 
52 };
53 
55  bool negative;
56  uint32_t hours;
57  uint32_t minutes;
58  uint32_t seconds;
59  uint32_t frames;
60  uint32_t subframes;
61  double rate;
62  static double default_rate;
63  bool drop;
64 
65  Time (double a_rate = default_rate)
66  {
67  negative = false;
68  hours = 0;
69  minutes = 0;
70  seconds = 0;
71  frames = 0;
72  subframes = 0;
73  rate = a_rate;
74  drop = (lrintf (100.f * (float)a_rate) == (long)2997);
75  }
76 
77  bool operator== (const Time& other) const
78  {
79  return negative == other.negative && hours == other.hours &&
80  minutes == other.minutes && seconds == other.seconds &&
81  frames == other.frames && subframes == other.subframes &&
82  rate == other.rate && drop == other.drop;
83  }
84 
85  std::ostream& print (std::ostream& ostr) const
86  {
87  if (negative) {
88  ostr << '-';
89  }
90  ostr << hours << ':' << minutes << ':' << seconds << ':'
91  << frames << '.' << subframes
92  << " @" << rate << (drop ? " drop" : " nondrop");
93  return ostr;
94  }
95 };
96 
97 Wrap LIBTEMPORAL_API increment (Time& timecode, uint32_t);
98 Wrap LIBTEMPORAL_API decrement (Time& timecode, uint32_t);
103 Wrap LIBTEMPORAL_API increment_hours (Time& timecode, uint32_t);
108 
111 
114 
116 
117 std::string LIBTEMPORAL_API
119  int64_t sample,
120  double sample_sample_rate,
121  double timecode_frames_per_second, bool timecode_drop_frames);
122 
134 void LIBTEMPORAL_API
136  Timecode::Time const& timecode, int64_t& sample,
137  bool use_offset, bool use_subframes,
138  double sample_sample_rate,
139  uint32_t subframes_per_frame,
140  bool offset_is_negative, int64_t offset_samples);
141 
155 void LIBTEMPORAL_API
157  int64_t sample, Timecode::Time& timecode,
158  bool use_offset, bool use_subframes,
159  double timecode_frames_per_second,
160  bool timecode_drop_frames,
161  double sample_sample_rate,
162  uint32_t subframes_per_frame,
163  bool offset_is_negative, int64_t offset_samples);
164 
165 } // namespace Timecode
166 
167 extern LIBTEMPORAL_API std::ostream& operator<< (std::ostream& ostr, const Timecode::Time& t);
168 
169 #endif // __timecode_time_h__
Definition: time.h:29
TimecodeFormat
Definition: time.h:39
@ timecode_60
Definition: time.h:51
@ timecode_25
Definition: time.h:43
@ timecode_23976
Definition: time.h:40
@ timecode_2997
Definition: time.h:44
@ timecode_24976
Definition: time.h:42
@ timecode_2997drop
Definition: time.h:45
@ timecode_30drop
Definition: time.h:49
@ timecode_2997000
Definition: time.h:46
@ timecode_24
Definition: time.h:41
@ timecode_5994
Definition: time.h:50
@ timecode_2997000drop
Definition: time.h:47
@ timecode_30
Definition: time.h:48
void frames_floot(Time &timecode)
void timecode_to_sample(Timecode::Time const &timecode, int64_t &sample, bool use_offset, bool use_subframes, double sample_sample_rate, uint32_t subframes_per_frame, bool offset_is_negative, int64_t offset_samples)
Wrap increment_subframes(Time &timecode, uint32_t)
void seconds_floor(Time &timecode)
double timecode_to_frames_per_second(TimecodeFormat const t)
Wrap increment(Time &timecode, uint32_t)
void minutes_floor(Time &timecode)
bool parse_timecode_format(std::string tc, Timecode::Time &TC)
bool timecode_has_drop_frames(TimecodeFormat const t)
std::string timecode_format_sampletime(int64_t sample, double sample_sample_rate, double timecode_frames_per_second, bool timecode_drop_frames)
Wrap increment_minutes(Time &timecode, uint32_t)
void hours_floor(Time &timecode)
std::string timecode_format_time(Timecode::Time const timecode)
std::string timecode_format_name(TimecodeFormat const t)
void sample_to_timecode(int64_t sample, Timecode::Time &timecode, bool use_offset, bool use_subframes, double timecode_frames_per_second, bool timecode_drop_frames, double sample_sample_rate, uint32_t subframes_per_frame, bool offset_is_negative, int64_t offset_samples)
Wrap increment_hours(Time &timecode, uint32_t)
Wrap decrement_subframes(Time &timecode, uint32_t)
Wrap decrement(Time &timecode, uint32_t)
Wrap increment_seconds(Time &timecode, uint32_t)
Wrap
Definition: time.h:31
@ HOURS
Definition: time.h:36
@ FRAMES
Definition: time.h:33
@ MINUTES
Definition: time.h:35
@ NONE
Definition: time.h:32
@ SECONDS
Definition: time.h:34
bool operator==(const ProcessorSelection &a, const ProcessorSelection &b)
bool drop
Whether this Time uses dropframe Timecode.
Definition: time.h:63
std::ostream & print(std::ostream &ostr) const
Definition: time.h:85
uint32_t hours
Definition: time.h:56
static double default_rate
Rate to use for default constructor.
Definition: time.h:62
bool negative
Definition: time.h:55
uint32_t minutes
Definition: time.h:57
Time(double a_rate=default_rate)
Definition: time.h:65
uint32_t seconds
Definition: time.h:58
double rate
Frame rate of this Time.
Definition: time.h:61
uint32_t subframes
Typically unused.
Definition: time.h:60
uint32_t frames
Timecode frames (not audio frames)
Definition: time.h:59
#define LIBTEMPORAL_API
std::ostream & operator<<(std::ostream &ostr, const Timecode::Time &t)