27ff8e93da90c19fa063f8a0e10a68d36a37b701
[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 #include <vector>
30 #include <boost/shared_ptr.hpp>
31
32 #include <inttypes.h>
33 #include <jack/types.h>
34 #include <control_protocol/smpte.h>
35 #include <pbd/id.h>
36
37 #include <map>
38
39 #if __GNUC__ < 3
40
41 typedef int intptr_t;
42 #endif
43
44 /* at some point move this into the ARDOUR namespace,
45    but for now its outside because it replaces the
46    old global "jack_nframes_t"
47 */
48
49 typedef uint32_t                    nframes_t;
50
51 namespace ARDOUR {
52
53         class Source;
54         class AudioSource;
55
56         typedef jack_default_audio_sample_t Sample;
57         typedef float                       pan_t;
58         typedef float                       gain_t;
59         typedef uint32_t                    layer_t;
60         typedef uint64_t                    microseconds_t;
61
62         enum IOChange {
63                 NoChange = 0,
64                 ConfigurationChanged = 0x1,
65                 ConnectionsChanged = 0x2
66         };
67
68         enum OverlapType {
69                 OverlapNone,      // no overlap
70                 OverlapInternal,  // the overlap is 100% with the object
71                 OverlapStart,     // overlap covers start, but ends within
72                 OverlapEnd,       // overlap begins within and covers end 
73                 OverlapExternal   // overlap extends to (at least) begin+end
74         };
75
76         OverlapType coverage (nframes_t start_a, nframes_t end_a,
77                               nframes_t start_b, nframes_t end_b);
78
79         enum AutomationType {
80                 GainAutomation = 0x1,
81                 PanAutomation = 0x2,
82                 PluginAutomation = 0x4,
83                 SoloAutomation = 0x8,
84                 MuteAutomation = 0x10
85         };
86
87         enum AutoState {
88                 Off = 0x0,
89                 Write = 0x1,
90                 Touch = 0x2,
91                 Play = 0x4
92         };
93
94         std::string auto_state_to_string (AutoState);
95         AutoState string_to_auto_state (std::string);
96
97         enum AutoStyle {
98                 Absolute = 0x1,
99                 Trim = 0x2
100         };
101
102         std::string auto_style_to_string (AutoStyle);
103         AutoStyle string_to_auto_style (std::string);
104
105         enum AlignStyle {
106                 CaptureTime,
107                 ExistingMaterial
108         };
109
110         enum MeterPoint {
111                 MeterInput,
112                 MeterPreFader,
113                 MeterPostFader
114         };
115
116         enum TrackMode {
117                 Normal,
118                 Destructive
119         };
120         
121         struct BBT_Time {
122             uint32_t bars;
123             uint32_t beats;
124             uint32_t ticks;
125
126             BBT_Time() {
127                     bars = 1;
128                     beats = 1;
129                     ticks = 0;
130             }
131
132             /* we can't define arithmetic operators for BBT_Time, because
133                the results depend on a TempoMap, but we can define 
134                a useful check on the less-than condition.
135             */
136
137             bool operator< (const BBT_Time& other) const {
138                     return bars < other.bars || 
139                             (bars == other.bars && beats < other.beats) ||
140                             (bars == other.bars && beats == other.beats && ticks < other.ticks);
141             }
142
143             bool operator== (const BBT_Time& other) const {
144                     return bars == other.bars && beats == other.beats && ticks == other.ticks;
145             }
146             
147         };
148
149         struct AnyTime {
150             enum Type {
151                     SMPTE,
152                     BBT,
153                     Frames,
154                     Seconds
155             };
156
157             Type type;
158
159             SMPTE::Time    smpte;
160             BBT_Time       bbt;
161
162             union { 
163                 nframes_t frames;
164                 double         seconds;
165             };
166
167             AnyTime() { type = Frames; frames = 0; }
168         };
169
170         struct AudioRange {
171             nframes_t start;
172             nframes_t end;
173             uint32_t id;
174             
175             AudioRange (nframes_t s, nframes_t e, uint32_t i) : start (s), end (e) , id (i) {}
176             
177             nframes_t length() { return end - start + 1; } 
178
179             bool operator== (const AudioRange& other) const {
180                     return start == other.start && end == other.end && id == other.id;
181             }
182
183             bool equal (const AudioRange& other) const {
184                     return start == other.start && end == other.end;
185             }
186
187             OverlapType coverage (nframes_t s, nframes_t e) const {
188                     return ARDOUR::coverage (start, end, s, e);
189             }
190         };
191         
192         struct MusicRange {
193             BBT_Time start;
194             BBT_Time end;
195             uint32_t id;
196             
197             MusicRange (BBT_Time& s, BBT_Time& e, uint32_t i)
198                     : start (s), end (e), id (i) {}
199
200             bool operator== (const MusicRange& other) const {
201                     return start == other.start && end == other.end && id == other.id;
202             }
203
204             bool equal (const MusicRange& other) const {
205                     return start == other.start && end == other.end;
206             }
207         };
208
209         /*
210             Slowest = 6.6dB/sec falloff at update rate of 40ms
211             Slow    = 6.8dB/sec falloff at update rate of 40ms
212         */
213
214         enum MeterFalloff {
215                 MeterFalloffOff = 0,
216                 MeterFalloffSlowest = 1,
217                 MeterFalloffSlow = 2,
218                 MeterFalloffMedium = 3,
219                 MeterFalloffFast = 4,
220                 MeterFalloffFaster = 5,
221                 MeterFalloffFastest = 6
222         };
223
224         enum MeterHold {
225                 MeterHoldOff = 0,
226                 MeterHoldShort = 40,
227                 MeterHoldMedium = 100,
228                 MeterHoldLong = 200
229         };
230
231         enum EditMode {
232                 Slide,
233                 Splice
234         };
235
236         enum RegionPoint { 
237             Start,
238             End,
239             SyncPoint
240         };
241
242         enum Change {
243                 range_guarantee = ~0
244         };
245
246
247         enum Placement {
248                 PreFader,
249                 PostFader
250         };
251
252         enum MonitorModel {
253                 HardwareMonitoring,
254                 SoftwareMonitoring,
255                 ExternalMonitoring,
256         };
257
258         enum CrossfadeModel {
259                 FullCrossfade,
260                 ShortCrossfade
261         };
262         
263         enum LayerModel {
264                 LaterHigher,
265                 MoveAddHigher,
266                 AddHigher
267         };
268
269         enum SoloModel {
270                 InverseMute,
271                 SoloBus
272         };
273
274         enum AutoConnectOption {
275                 AutoConnectPhysical = 0x1,
276                 AutoConnectMaster = 0x2
277         };
278
279         struct InterThreadInfo {
280             volatile bool  done;
281             volatile bool  cancel;
282             volatile float progress;
283             pthread_t      thread;
284         };
285
286         enum SampleFormat {
287                 FormatFloat = 0,
288                 FormatInt24
289         };
290
291
292         enum HeaderFormat {
293                 BWF,
294                 WAVE,
295                 WAVE64,
296                 CAF,
297                 AIFF,
298                 iXML,
299                 RF64
300         };
301
302         struct PeakData {
303             typedef Sample PeakDatum;
304             
305             PeakDatum min;
306             PeakDatum max;
307         };
308         
309         enum PluginType {
310                 AudioUnit,
311                 LADSPA,
312                 VST
313         };
314
315         enum SlaveSource {
316                 None = 0,
317                 MTC,
318                 JACK
319         };
320
321         enum ShuttleBehaviour {
322                 Sprung,
323                 Wheel
324         };
325
326         enum ShuttleUnits {
327                 Percentage,
328                 Semitones
329         };
330
331         typedef std::vector<boost::shared_ptr<AudioSource> > SourceList;
332
333 } // namespace ARDOUR
334
335 std::istream& operator>>(std::istream& o, ARDOUR::SampleFormat& sf);
336 std::istream& operator>>(std::istream& o, ARDOUR::HeaderFormat& sf);
337 std::istream& operator>>(std::istream& o, ARDOUR::AutoConnectOption& sf);
338 std::istream& operator>>(std::istream& o, ARDOUR::EditMode& sf);
339 std::istream& operator>>(std::istream& o, ARDOUR::MonitorModel& sf);
340 std::istream& operator>>(std::istream& o, ARDOUR::SoloModel& sf);
341 std::istream& operator>>(std::istream& o, ARDOUR::LayerModel& sf);
342 std::istream& operator>>(std::istream& o, ARDOUR::CrossfadeModel& sf);
343 std::istream& operator>>(std::istream& o, ARDOUR::SlaveSource& sf);
344 std::istream& operator>>(std::istream& o, ARDOUR::ShuttleBehaviour& sf);
345 std::istream& operator>>(std::istream& o, ARDOUR::ShuttleUnits& sf);
346
347 static inline nframes_t
348 session_frame_to_track_frame (nframes_t session_frame, double speed)
349 {
350         return (nframes_t)( (double)session_frame * speed );
351 }
352
353 static inline nframes_t
354 track_frame_to_session_frame (nframes_t track_frame, double speed)
355 {
356         return (nframes_t)( (double)track_frame / speed );
357 }
358
359
360 #endif /* __ardour_types_h__ */
361