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