1/*
2 * Copyright 2009, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _TIME_CODE_H
6#define _TIME_CODE_H
7
8
9#include <SupportDefs.h>
10
11
12// Time code is always in the form HH:MM:SS:FF, it's the definition of "FF"
13// that varies
14enum timecode_type {
15	B_TIMECODE_DEFAULT,
16	B_TIMECODE_100,
17	B_TIMECODE_75,			// CD
18	B_TIMECODE_30,			// MIDI
19	B_TIMECODE_30_DROP_2,	// NTSC
20	B_TIMECODE_30_DROP_4,	// Brazil
21	B_TIMECODE_25,			// PAL
22	B_TIMECODE_24,			// Film
23	B_TIMECODE_18			// Super8
24};
25
26
27struct timecode_info {
28	timecode_type	type;
29	int				drop_frames;
30	int				every_nth;
31	int				except_nth;
32	int				fps_div;
33	char			name[32];		// For popup menus and such
34	char			format[32];		// For sprintf(fmt, h, m, s, f)
35
36	char			_reserved_[64];
37};
38
39
40status_t us_to_timecode(bigtime_t micros, int* hours, int* minutes,
41	int* seconds, int* frames, const timecode_info* code = NULL);
42
43status_t timecode_to_us(int hours, int minutes, int seconds, int frames,
44	bigtime_t* micros, const timecode_info* code = NULL);
45
46status_t frames_to_timecode(int32 l_frames, int* hours, int* minutes,
47	int* seconds, int* frames, const timecode_info* code = NULL);
48
49status_t timecode_to_frames(int hours, int minutes, int seconds, int frames,
50	int32* lFrames, const timecode_info* code = NULL);
51
52status_t get_timecode_description(timecode_type type,
53	timecode_info* _timecode);
54
55status_t count_timecodes();
56
57
58class BTimeCode {
59public:
60								BTimeCode();
61								BTimeCode(bigtime_t microSeconds,
62									timecode_type type = B_TIMECODE_DEFAULT);
63								BTimeCode(const BTimeCode& other);
64								BTimeCode(int hours, int minutes, int seconds,
65									int frames,
66									timecode_type type = B_TIMECODE_DEFAULT);
67								~BTimeCode();
68
69			void				SetData(int hours, int minutes, int seconds,
70									int frames);
71			status_t			SetType(timecode_type type);
72			void				SetMicroseconds(bigtime_t microSeconds);
73			void				SetLinearFrames(int32 linearFrames);
74
75			BTimeCode&			operator=(const BTimeCode& other);
76			bool				operator==(const BTimeCode& other) const;
77			bool				operator<(const BTimeCode& other) const;
78
79			BTimeCode&			operator+=(const BTimeCode& other);
80			BTimeCode&			operator-=(const BTimeCode& other);
81
82			BTimeCode			operator+(const BTimeCode& other) const;
83			BTimeCode			operator-(const BTimeCode& other) const;
84
85			int					Hours() const;
86			int					Minutes() const;
87			int					Seconds() const;
88			int					Frames() const;
89			timecode_type		Type() const;
90			void				GetData(int* _hours, int* _minutes,
91									int* _seconds, int* _frames,
92									timecode_type* _type = NULL) const;
93
94			bigtime_t			Microseconds() const;
95			int32				LinearFrames() const;
96
97			// Make sure the passed buffer is at least 24 bytes large.
98			void				GetString(char* string) const;
99
100private:
101			int					fHours;
102			int					fMinutes;
103			int					fSeconds;
104			int					fFrames;
105			timecode_info		fInfo;
106};
107
108#endif // _TIME_CODE_H
109