xref: /haiku/headers/os/media/TimeCode.h (revision f2ced752a08ff5d2618826bcd3ae3976c9f3e92e)
1 /*****************************************************************
2 
3         File:         TimeCode.h
4 
5         Description:  Time code handling functions and class
6 
7         Copyright 1998-, Be Incorporated. All Rights Reserved.
8 
9 *****************************************************************/
10 
11 #if !defined(_TIME_CODE_H)
12 #define _TIME_CODE_H
13 
14 #include <SupportDefs.h>
15 
16 
17 /* Time code is always in the form HH:MM:SS:FF, it's the definition of FF that varies */
18 enum timecode_type {
19 	B_TIMECODE_DEFAULT,
20 	B_TIMECODE_100,
21 	B_TIMECODE_75,			/* CD */
22 	B_TIMECODE_30,			/* MIDI */
23 	B_TIMECODE_30_DROP_2,	/* NTSC */
24 	B_TIMECODE_30_DROP_4,	/* Brazil */
25 	B_TIMECODE_25,			/* PAL */
26 	B_TIMECODE_24,			/* Film */
27 	B_TIMECODE_18			/* Super8 */
28 };
29 struct timecode_info {
30 	timecode_type type;
31 	int drop_frames;
32 	int every_nth;
33 	int except_nth;
34 	int fps_div;
35 	char name[32];		/* for popup menu etc */
36 	char format[32];	/* for sprintf(fmt, h, m, s, f) */
37 	char _reserved_[64];
38 };
39 _IMPEXP_MEDIA status_t us_to_timecode(bigtime_t micros, int * hours, int * minutes, int * seconds, int * frames, const timecode_info * code = NULL);
40 _IMPEXP_MEDIA status_t timecode_to_us(int hours, int minutes, int seconds, int frames, bigtime_t * micros, const timecode_info * code = NULL);
41 _IMPEXP_MEDIA status_t frames_to_timecode(int32 l_frames, int * hours, int * minutes, int * seconds, int * frames, const timecode_info * code = NULL);
42 _IMPEXP_MEDIA status_t timecode_to_frames(int hours, int minutes, int seconds, int frames, int32 * l_frames, const timecode_info * code = NULL);
43 _IMPEXP_MEDIA status_t get_timecode_description(timecode_type type, timecode_info * out_timecode);
44 _IMPEXP_MEDIA status_t count_timecodes();
45 /* we may want a set_default_timecode, too -- but that's bad from a thread standpoint */
46 
47 
48 class BTimeCode {
49 public:
50 		BTimeCode();
51 		BTimeCode(
52 				bigtime_t us,
53 				timecode_type type = B_TIMECODE_DEFAULT);
54 		BTimeCode(
55 				const BTimeCode & clone);
56 		BTimeCode(
57 				int hours,
58 				int minutes,
59 				int seconds,
60 				int frames,
61 				timecode_type type = B_TIMECODE_DEFAULT);
62 		~BTimeCode();
63 
64 		void SetData(
65 				int hours,
66 				int minutes,
67 				int seconds,
68 				int frames);
69 		status_t SetType(
70 				timecode_type type);
71 		void SetMicroseconds(
72 				bigtime_t us);
73 		void SetLinearFrames(
74 				int32 linear_frames);
75 
76 		BTimeCode & operator=(
77 				const BTimeCode & clone);
78 		bool operator==(
79 				const BTimeCode & other) const;
80 		bool operator<(
81 				const BTimeCode & other) const;
82 
83 		BTimeCode & operator+=(
84 				const BTimeCode & other);
85 		BTimeCode & operator-=(
86 				const BTimeCode & other);
87 
88 		BTimeCode operator+(
89 				const BTimeCode & other) const;
90 		BTimeCode operator-(
91 				const BTimeCode & other) const;
92 
93 		int Hours() const;
94 		int Minutes() const;
95 		int Seconds() const;
96 		int Frames() const;
97 		timecode_type Type() const;
98 		void GetData(
99 				int * out_hours,
100 				int * out_minutes,
101 				int * out_seconds,
102 				int * out_frames,
103 				timecode_type * out_type = NULL) const;
104 
105 		bigtime_t Microseconds() const;
106 		int32 LinearFrames() const;
107 		void GetString(
108 				char * str) const;	/* at least 24 bytes */
109 
110 private:
111 		int m_hours;
112 		int m_minutes;
113 		int m_seconds;
114 		int m_frames;
115 		timecode_info m_info;
116 };
117 
118 
119 #endif /* _TIME_CODE_H */
120