/*
Copyright (C) 2006-2010 Paul Davis
-
+
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
-
+
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
-
+
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
timecode.negative = false;
return SECONDS;
}
-
+
timecode.negative = false;
wrap = decrement (timecode, subframes_per_frame);
if (!Timecode_IS_ZERO (timecode)) {
}
break;
}
-
+
if (wrap == SECONDS) {
if (timecode.seconds == 59) {
timecode.seconds = 0;
} else {
timecode.frames++;
}
-
+
return wrap;
}
decrement (Time& timecode, uint32_t subframes_per_frame)
{
Wrap wrap = NONE;
-
+
if (timecode.negative || Timecode_IS_ZERO (timecode)) {
timecode.negative = false;
wrap = increment (timecode, subframes_per_frame);
timecode.negative = true;
return SECONDS;
}
-
+
switch ((int)ceil (timecode.rate)) {
case 24:
if (timecode.frames == 0) {
timecode.frames = 29;
wrap = SECONDS;
}
-
+
} else {
if (timecode.frames == 0) {
timecode.frames = 29;
}
break;
}
-
+
if (wrap == SECONDS) {
if (timecode.seconds == 0) {
timecode.seconds = 59;
} else {
timecode.frames--;
}
-
+
if (Timecode_IS_ZERO (timecode)) {
timecode.negative = false;
}
-
+
return wrap;
}
increment_subframes (Time& timecode, uint32_t subframes_per_frame)
{
Wrap wrap = NONE;
-
+
if (timecode.negative) {
timecode.negative = false;
wrap = decrement_subframes (timecode, subframes_per_frame);
}
return wrap;
}
-
+
timecode.subframes++;
if (timecode.subframes >= subframes_per_frame) {
timecode.subframes = 0;
decrement_subframes (Time& timecode, uint32_t subframes_per_frame)
{
Wrap wrap = NONE;
-
+
if (timecode.negative) {
timecode.negative = false;
wrap = increment_subframes (timecode, subframes_per_frame);
timecode.negative = true;
return wrap;
}
-
+
if (timecode.subframes <= 0) {
timecode.subframes = 0;
if (Timecode_IS_ZERO (timecode)) {
increment_seconds (Time& timecode, uint32_t subframes_per_frame)
{
Wrap wrap = NONE;
-
+
// Clear subframes
frames_floor (timecode);
-
+
if (timecode.negative) {
// Wrap second if on second boundary
wrap = increment (timecode, subframes_per_frame);
timecode.frames = 59;
break;
}
-
+
// Increment by one frame
wrap = increment (timecode, subframes_per_frame);
}
-
+
return wrap;
}
{
// Clear subframes
frames_floor (timecode);
-
+
// Go to lowest possible frame in this second
switch ((int)ceil (timecode.rate)) {
case 24:
}
break;
}
-
+
if (Timecode_IS_ZERO (timecode)) {
timecode.negative = false;
}
increment_minutes (Time& timecode, uint32_t subframes_per_frame)
{
Wrap wrap = NONE;
-
+
// Clear subframes
frames_floor (timecode);
-
+
if (timecode.negative) {
// Wrap if on minute boundary
wrap = increment_seconds (timecode, subframes_per_frame);
// Wrap minute by incrementing second
wrap = increment_seconds (timecode, subframes_per_frame);
}
-
+
return wrap;
}
increment_hours (Time& timecode, uint32_t subframes_per_frame)
{
Wrap wrap = NONE;
-
+
// Clear subframes
frames_floor (timecode);
-
+
if (timecode.negative) {
// Wrap if on hour boundary
wrap = increment_minutes (timecode, subframes_per_frame);
timecode.minutes = 59;
wrap = increment_minutes (timecode, subframes_per_frame);
}
-
+
return wrap;
}
timecode.seconds = 0;
timecode.frames = 0;
timecode.subframes = 0;
-
+
if (Timecode_IS_ZERO (timecode)) {
timecode.negative = false;
}
frame_rate() in the non-integer Timecode rate case.
*/
- sample = (int64_t)rint((((timecode.hours * 60 * 60) + (timecode.minutes * 60) + timecode.seconds) * (rint(timecode.rate) * frames_per_timecode_frame)) + (timecode.frames * frames_per_timecode_frame));
+ sample = (int64_t) rint(
+ (
+ ((timecode.hours * 60 * 60) + (timecode.minutes * 60) + timecode.seconds)
+ *
+ (rint(timecode.rate) * frames_per_timecode_frame)
+ )
+ + (timecode.frames * frames_per_timecode_frame)
+ );
}
if (use_subframes) {
if (!use_offset) {
timecode.negative = (sample < 0);
- offset_sample = llabs(sample);
+ offset_sample = ::llabs(sample);
} else {
if (offset_is_negative) {
offset_sample = sample + offset_samples;
double timecode_frames_fraction;
int64_t timecode_frames_left;
const double frames_per_timecode_frame = sample_frame_rate / timecode_frames_per_second;
- const int64_t frames_per_hour = (int64_t)(3600 * rint(timecode_frames_per_second) * frames_per_timecode_frame);
+ const int64_t frames_per_hour = (int64_t)(3600. * rint(timecode_frames_per_second) * frames_per_timecode_frame);
timecode.hours = offset_sample / frames_per_hour;
timecode.subframes = 0;
}
- timecode.minutes = timecode_frames_left / ((int32_t) rint (timecode_frames_per_second) * 60);
- timecode_frames_left = timecode_frames_left % ((int32_t) rint (timecode_frames_per_second) * 60);
- timecode.seconds = timecode_frames_left / (int32_t) rint(timecode_frames_per_second);
- timecode.frames = timecode_frames_left % (int32_t) rint(timecode_frames_per_second);
+ timecode.minutes = timecode_frames_left / ((int32_t) lrint (timecode_frames_per_second) * 60);
+ timecode_frames_left = timecode_frames_left % ((int32_t) lrint (timecode_frames_per_second) * 60);
+ timecode.seconds = timecode_frames_left / (int32_t) lrint(timecode_frames_per_second);
+ timecode.frames = timecode_frames_left % (int32_t) lrint(timecode_frames_per_second);
}
if (!use_subframes) {
} // namespace Timecode
-std::ostream&
-operator<<(std::ostream& ostr, const Timecode::Time& t)
+std::ostream&
+operator<<(std::ostream& ostr, const Timecode::Time& t)
{
return t.print (ostr);
}