Ardour  9.0-pre0-384-ga76afae0e9
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 #pragma once
20 
21 #include <cmath>
22 #include <inttypes.h>
23 #include <ostream>
24 
25 #include "temporal/visibility.h"
26 
27 namespace Timecode
28 {
29 
30 enum Wrap {
31  NONE = 0,
35  HOURS
36 };
37 
51 };
52 
54  bool negative;
55  uint32_t hours;
56  uint32_t minutes;
57  uint32_t seconds;
58  uint32_t frames;
59  uint32_t subframes;
60  double rate;
61  static double default_rate;
62  bool drop;
63 
64  Time (double a_rate = default_rate)
65  {
66  negative = false;
67  hours = 0;
68  minutes = 0;
69  seconds = 0;
70  frames = 0;
71  subframes = 0;
72  rate = a_rate;
73  drop = (lrintf (100.f * (float)a_rate) == (long)2997);
74  }
75 
76  bool operator== (const Time& other) const
77  {
78  return negative == other.negative && hours == other.hours &&
79  minutes == other.minutes && seconds == other.seconds &&
80  frames == other.frames && subframes == other.subframes &&
81  rate == other.rate && drop == other.drop;
82  }
83 
84  std::ostream& print (std::ostream& ostr) const
85  {
86  if (negative) {
87  ostr << '-';
88  }
89  ostr << hours << ':' << minutes << ':' << seconds << ':'
90  << frames << '.' << subframes
91  << " @" << rate << (drop ? " drop" : " nondrop");
92  return ostr;
93  }
94 };
95 
96 Wrap LIBTEMPORAL_API increment (Time& timecode, uint32_t);
97 Wrap LIBTEMPORAL_API decrement (Time& timecode, uint32_t);
102 Wrap LIBTEMPORAL_API increment_hours (Time& timecode, uint32_t);
107 
110 
113 
115 
116 std::string LIBTEMPORAL_API
118  int64_t sample,
119  double sample_sample_rate,
120  double timecode_frames_per_second, bool timecode_drop_frames);
121 
133 void LIBTEMPORAL_API
135  Timecode::Time const& timecode, int64_t& sample,
136  bool use_offset, bool use_subframes,
137  double sample_sample_rate,
138  uint32_t subframes_per_frame,
139  bool offset_is_negative, int64_t offset_samples);
140 
154 void LIBTEMPORAL_API
156  int64_t sample, Timecode::Time& timecode,
157  bool use_offset, bool use_subframes,
158  double timecode_frames_per_second,
159  bool timecode_drop_frames,
160  double sample_sample_rate,
161  uint32_t subframes_per_frame,
162  bool offset_is_negative, int64_t offset_samples);
163 
164 } // namespace Timecode
165 
166 extern LIBTEMPORAL_API std::ostream& operator<< (std::ostream& ostr, const Timecode::Time& t);
167 
Definition: time.h:28
TimecodeFormat
Definition: time.h:38
@ timecode_60
Definition: time.h:50
@ timecode_25
Definition: time.h:42
@ timecode_23976
Definition: time.h:39
@ timecode_2997
Definition: time.h:43
@ timecode_24976
Definition: time.h:41
@ timecode_2997drop
Definition: time.h:44
@ timecode_30drop
Definition: time.h:48
@ timecode_2997000
Definition: time.h:45
@ timecode_24
Definition: time.h:40
@ timecode_5994
Definition: time.h:49
@ timecode_2997000drop
Definition: time.h:46
@ timecode_30
Definition: time.h:47
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:30
@ HOURS
Definition: time.h:35
@ FRAMES
Definition: time.h:32
@ MINUTES
Definition: time.h:34
@ NONE
Definition: time.h:31
@ SECONDS
Definition: time.h:33
bool operator==(const ProcessorSelection &a, const ProcessorSelection &b)
bool drop
Whether this Time uses dropframe Timecode.
Definition: time.h:62
std::ostream & print(std::ostream &ostr) const
Definition: time.h:84
uint32_t hours
Definition: time.h:55
static double default_rate
Rate to use for default constructor.
Definition: time.h:61
bool negative
Definition: time.h:54
uint32_t minutes
Definition: time.h:56
Time(double a_rate=default_rate)
Definition: time.h:64
uint32_t seconds
Definition: time.h:57
double rate
Frame rate of this Time.
Definition: time.h:60
uint32_t subframes
Typically unused.
Definition: time.h:59
uint32_t frames
Timecode frames (not audio frames)
Definition: time.h:58
#define LIBTEMPORAL_API
std::ostream & operator<<(std::ostream &ostr, const Timecode::Time &t)