2008-06-19 00:57:47 +02:00
|
|
|
/*
|
|
|
|
|
time.h - Utilities for handling time
|
|
|
|
|
|
|
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2008, Christian Thaeter <ct@pipapo.org>
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
2010-12-17 23:28:49 +01:00
|
|
|
published by the Free Software Foundation; either version 2 of
|
|
|
|
|
the License, or (at your option) any later version.
|
2008-06-19 00:57:47 +02:00
|
|
|
|
|
|
|
|
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 General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
2011-01-09 02:13:58 +01:00
|
|
|
/** @file time.h
|
|
|
|
|
** Common functions for handling of time values.
|
|
|
|
|
** Working with time values in sexagesimal format, quantising time and converting
|
|
|
|
|
** to/from common timecode formats can be tricky to get right. Thus the goal is
|
|
|
|
|
** to concentrate the actual bits of math for these operations into a small number
|
|
|
|
|
** of library functions, which are easy to test thoroughly in isolation.
|
|
|
|
|
**
|
|
|
|
|
** Built on top of that, the actual time handling in the GUI and within the Lumiera
|
|
|
|
|
** session is mostly confined to use the opaque lib::time::Time wrapper objects.
|
|
|
|
|
** When time values actually need to be \em quantised (aligned to a frame grid),
|
|
|
|
|
** this is expressed at the API through using the lib::time::QuTime type, which
|
|
|
|
|
** then in turn can be materialised into a number of \em timecode formats.
|
|
|
|
|
** These definitions ensure that whenever an actual quantisation (rounding)
|
|
|
|
|
** operation is performed, the link to the appropriate time grid is available,
|
|
|
|
|
** so that multiple output or rendering operations can use differing time origins
|
|
|
|
|
** and frame rates simultaneously on the same model.
|
|
|
|
|
**
|
|
|
|
|
** The Lumiera backend functions mostly operate on raw frame counts, which in this
|
|
|
|
|
** model are defined to be a special kind of timecode, and thus dependent on a
|
|
|
|
|
** preceding time quantisation.
|
|
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** @see lib::time::Time
|
|
|
|
|
** @see timequant.hpp
|
|
|
|
|
** @see TimeValue_test
|
|
|
|
|
**
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2008-06-19 00:57:47 +02:00
|
|
|
#ifndef LUMIERA_TIME_H
|
|
|
|
|
#define LUMIERA_TIME_H
|
|
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
#include <gavl/gavl.h>
|
|
|
|
|
|
2011-01-09 02:13:58 +01:00
|
|
|
#ifdef __cplusplus /*=================== C++ facilities ===================== */
|
|
|
|
|
#include "lib/time/timevalue.hpp"
|
|
|
|
|
|
|
|
|
|
|
2008-06-19 00:57:47 +02:00
|
|
|
/**
|
2011-01-09 02:13:58 +01:00
|
|
|
* Converts a fraction of seconds to Lumiera's internal opaque time scale.
|
|
|
|
|
* @param fractionalSeconds given as rational number
|
|
|
|
|
*/
|
|
|
|
|
inline gavl_time_t
|
|
|
|
|
lumiera_rational_to_time (lib::time::FSecs const& fractionalSeconds)
|
|
|
|
|
{
|
|
|
|
|
return boost::rational_cast<gavl_time_t> (GAVL_TIME_SCALE * fractionalSeconds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extern "C" { /* ===================== C interface ======================== */
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Formats a time value in H:MM:SS.mmm format into a temporary buffer.
|
|
|
|
|
* @return safeclib temporary buffer containing formatted time string
|
2008-06-19 00:57:47 +02:00
|
|
|
*/
|
|
|
|
|
char*
|
|
|
|
|
lumiera_tmpbuf_print_time (gavl_time_t time);
|
|
|
|
|
|
2011-01-06 13:30:27 +01:00
|
|
|
/**
|
|
|
|
|
* Quantise the given time into a fixed grid, relative to the origin.
|
|
|
|
|
* The time grid used for quantisation is comprised of equally spaced intervals,
|
|
|
|
|
* rooted at the given origin. The interval starting with the origin is numbered
|
|
|
|
|
* as zero. Each interval includes its lower bound, but excludes its upper bound.
|
|
|
|
|
* @param grid spacing of the grid intervals, measured in GAVL_TIME_SCALE
|
|
|
|
|
* @return number of the grid interval containing the given time.
|
2011-01-09 02:13:58 +01:00
|
|
|
* @warning the resulting value is limited to (Time::Min, Time::MAX)
|
2011-01-06 13:30:27 +01:00
|
|
|
*/
|
|
|
|
|
int64_t
|
|
|
|
|
lumiera_quantise_frames (gavl_time_t time, double grid, gavl_time_t origin);
|
|
|
|
|
|
|
|
|
|
/**
|
2011-01-09 02:13:58 +01:00
|
|
|
* Similar to #lumiera_quantise_frames, but returns a grid aligned \em time value
|
2011-01-06 13:30:27 +01:00
|
|
|
* @return time of start of the grid interval containing the given time,
|
|
|
|
|
* but measured relative to the origin
|
|
|
|
|
* @warning because the resulting value needs to be limited to fit into a 64bit long,
|
|
|
|
|
* the addressable time range can be considerably reduced. For example, if
|
2011-01-09 02:13:58 +01:00
|
|
|
* origin = Time::MIN, then all original time values above zero will be
|
|
|
|
|
* clipped, because the result, relative to origin, needs to be <= Time::MAX
|
2011-01-06 13:30:27 +01:00
|
|
|
*/
|
|
|
|
|
gavl_time_t
|
|
|
|
|
lumiera_quantise_time (gavl_time_t time, double grid, gavl_time_t origin);
|
|
|
|
|
|
2009-07-12 22:51:04 +02:00
|
|
|
/**
|
|
|
|
|
* Builds a time value by summing up the given components.
|
|
|
|
|
*/
|
|
|
|
|
gavl_time_t
|
|
|
|
|
lumiera_build_time (long millis, uint secs, uint mins, uint hours);
|
|
|
|
|
|
2010-12-06 16:18:54 +01:00
|
|
|
/**
|
2011-01-09 02:13:58 +01:00
|
|
|
* Extract the hour part of given time.
|
2010-12-06 16:18:54 +01:00
|
|
|
*/
|
|
|
|
|
int lumiera_time_hours(gavl_time_t time);
|
|
|
|
|
|
|
|
|
|
/**
|
2011-01-09 02:13:58 +01:00
|
|
|
* Extract the minute part of given time.
|
2010-12-06 16:18:54 +01:00
|
|
|
*/
|
|
|
|
|
int lumiera_time_minutes(gavl_time_t time);
|
|
|
|
|
|
|
|
|
|
/**
|
2011-01-09 02:13:58 +01:00
|
|
|
* Extract the seconds part of given time.
|
2010-12-06 16:18:54 +01:00
|
|
|
*/
|
|
|
|
|
int lumiera_time_seconds(gavl_time_t time);
|
|
|
|
|
|
|
|
|
|
/**
|
2011-01-09 02:13:58 +01:00
|
|
|
* Extract the milliseconds part of given time.
|
2010-12-06 16:18:54 +01:00
|
|
|
*/
|
|
|
|
|
int lumiera_time_millis(gavl_time_t time);
|
|
|
|
|
|
2008-06-19 00:57:47 +02:00
|
|
|
|
2011-01-09 02:13:58 +01:00
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}//extern "C"
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|