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