Merged with trunk revision 600
[ardour.git] / libs / ardour / ardour / types.h
1 /*
2     Copyright (C) 2002 Paul Davis 
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
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18     $Id$
19 */
20
21 #ifndef __ardour_types_h__
22 #define __ardour_types_h__
23
24 #ifndef __STDC_FORMAT_MACROS
25 #define __STDC_FORMAT_MACROS /* PRI<foo>; C++ requires explicit requesting of these */
26 #endif
27
28 #include <istream>
29
30 #include <inttypes.h>
31 #include <jack/types.h>
32 #include <map>
33
34 #if __GNUC__ < 3
35
36 typedef int intptr_t;
37 #endif
38
39 namespace ARDOUR {
40
41         class Source;
42
43         typedef jack_default_audio_sample_t Sample;
44         typedef float                       pan_t;
45         typedef float                       gain_t;
46         typedef uint32_t                    layer_t;
47         typedef uint64_t                    id_t;
48
49         enum IOChange {
50                 NoChange = 0,
51                 ConfigurationChanged = 0x1,
52                 ConnectionsChanged = 0x2
53         };
54
55         enum OverlapType {
56                 OverlapNone,      // no overlap
57                 OverlapInternal,  // the overlap is 100% with the object
58                 OverlapStart,     // overlap covers start, but ends within
59                 OverlapEnd,       // overlap begins within and covers end 
60                 OverlapExternal   // overlap extends to (at least) begin+end
61         };
62
63         OverlapType coverage (jack_nframes_t start_a, jack_nframes_t end_a,
64                               jack_nframes_t start_b, jack_nframes_t end_b);
65
66         enum AutomationType {
67                 GainAutomation = 0x1,
68                 PanAutomation = 0x2,
69                 PluginAutomation = 0x4,
70                 SoloAutomation = 0x8,
71                 MuteAutomation = 0x10,
72         };
73
74         enum AutoState {
75                 Off = 0x0,
76                 Write = 0x1,
77                 Touch = 0x2,
78                 Play = 0x4
79         };
80
81         enum AutoStyle {
82                 Absolute = 0x1,
83                 Trim = 0x2
84         };
85
86         enum AlignStyle {
87                 CaptureTime,
88                 ExistingMaterial
89         };
90
91         enum MeterPoint {
92                 MeterInput,
93                 MeterPreFader,
94                 MeterPostFader
95         };
96
97         enum TrackMode {
98                 Normal,
99                 Destructive
100         };
101
102         enum smpte_wrap_t {
103                 smpte_wrap_none = 0,
104                 smpte_wrap_frames,
105                 smpte_wrap_seconds,
106                 smpte_wrap_minutes,
107                 smpte_wrap_hours
108         };
109
110         struct SMPTE_Time {
111                 bool negative;
112                 uint32_t hours;
113                 uint32_t minutes;
114                 uint32_t seconds;
115                 uint32_t frames;
116                 uint32_t subframes; // mostly not used
117
118                 SMPTE_Time() {
119                         negative = false;
120                         hours = 0;
121                         minutes = 0;
122                         seconds = 0;
123                         frames = 0;
124                         subframes = 0;
125                 }
126                 
127         };
128
129         struct BBT_Time {
130             uint32_t bars;
131             uint32_t beats;
132             uint32_t ticks;
133
134             BBT_Time() {
135                     bars = 1;
136                     beats = 1;
137                     ticks = 0;
138             }
139
140             /* we can't define arithmetic operators for BBT_Time, because
141                the results depend on a TempoMap, but we can define 
142                a useful check on the less-than condition.
143             */
144
145             bool operator< (const BBT_Time& other) const {
146                     return bars < other.bars || 
147                             (bars == other.bars && beats < other.beats) ||
148                             (bars == other.bars && beats == other.beats && ticks < other.ticks);
149             }
150
151             bool operator== (const BBT_Time& other) const {
152                     return bars == other.bars && beats == other.beats && ticks == other.ticks;
153             }
154             
155         };
156
157         struct AnyTime {
158             enum Type {
159                     SMPTE,
160                     BBT,
161                     Frames,
162                     Seconds
163             };
164
165             Type type;
166
167             SMPTE_Time     smpte;
168             BBT_Time       bbt;
169
170             union { 
171                 jack_nframes_t frames;
172                 double         seconds;
173             };
174         };
175
176         struct AudioRange {
177             jack_nframes_t start;
178             jack_nframes_t end;
179             uint32_t id;
180             
181             AudioRange (jack_nframes_t s, jack_nframes_t e, uint32_t i) : start (s), end (e) , id (i) {}
182             
183             jack_nframes_t length() { return end - start + 1; } 
184
185             bool operator== (const AudioRange& other) const {
186                     return start == other.start && end == other.end && id == other.id;
187             }
188
189             bool equal (const AudioRange& other) const {
190                     return start == other.start && end == other.end;
191             }
192
193             OverlapType coverage (jack_nframes_t s, jack_nframes_t e) const {
194                     return ARDOUR::coverage (start, end, s, e);
195             }
196         };
197         
198         struct MusicRange {
199             BBT_Time start;
200             BBT_Time end;
201             uint32_t id;
202             
203             MusicRange (BBT_Time& s, BBT_Time& e, uint32_t i)
204                     : start (s), end (e), id (i) {}
205
206             bool operator== (const MusicRange& other) const {
207                     return start == other.start && end == other.end && id == other.id;
208             }
209
210             bool equal (const MusicRange& other) const {
211                     return start == other.start && end == other.end;
212             }
213         };
214
215         enum EditMode {
216                 Slide,
217                 Splice,
218         };
219
220         enum RegionPoint { 
221             Start,
222             End,
223             SyncPoint
224         };
225
226         enum Change {
227                 range_guarantee = ~0
228         };
229
230
231         enum Placement {
232                 PreFader,
233                 PostFader
234         };
235
236         enum CrossfadeModel {
237                 FullCrossfade,
238                 ShortCrossfade
239         };
240
241         struct InterThreadInfo {
242             volatile bool  done;
243             volatile bool  cancel;
244             volatile float progress;
245             pthread_t      thread;
246         };
247
248         enum SampleFormat {
249                 FormatFloat = 0,
250                 FormatInt24
251         };
252
253
254         enum HeaderFormat {
255                 BWF,
256                 WAVE,
257                 WAVE64,
258                 CAF,
259                 AIFF,
260                 iXML,
261                 RF64
262         };
263
264         struct PeakData {
265             typedef Sample PeakDatum;
266             
267             PeakDatum min;
268             PeakDatum max;
269         };
270 };
271
272 std::istream& operator>>(std::istream& o, ARDOUR::SampleFormat& sf);
273 std::istream& operator>>(std::istream& o, ARDOUR::HeaderFormat& sf);
274
275 static inline jack_nframes_t
276 session_frame_to_track_frame (jack_nframes_t session_frame, double speed)
277 {
278         return (jack_nframes_t)( (double)session_frame * speed );
279 }
280
281
282 static inline jack_nframes_t
283 track_frame_to_session_frame (jack_nframes_t track_frame, double speed)
284 {
285         return (jack_nframes_t)( (double)track_frame / speed );
286 }
287
288
289 #endif /* __ardour_types_h__ */
290