fixes for various bugs including dangling ref to route in session, opening sessions...
[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         enum AutoStyle {
95                 Absolute = 0x1,
96                 Trim = 0x2
97         };
98
99         enum AlignStyle {
100                 CaptureTime,
101                 ExistingMaterial
102         };
103
104         enum MeterPoint {
105                 MeterInput,
106                 MeterPreFader,
107                 MeterPostFader
108         };
109
110         enum TrackMode {
111                 Normal,
112                 Destructive
113         };
114         
115         struct BBT_Time {
116             uint32_t bars;
117             uint32_t beats;
118             uint32_t ticks;
119
120             BBT_Time() {
121                     bars = 1;
122                     beats = 1;
123                     ticks = 0;
124             }
125
126             /* we can't define arithmetic operators for BBT_Time, because
127                the results depend on a TempoMap, but we can define 
128                a useful check on the less-than condition.
129             */
130
131             bool operator< (const BBT_Time& other) const {
132                     return bars < other.bars || 
133                             (bars == other.bars && beats < other.beats) ||
134                             (bars == other.bars && beats == other.beats && ticks < other.ticks);
135             }
136
137             bool operator== (const BBT_Time& other) const {
138                     return bars == other.bars && beats == other.beats && ticks == other.ticks;
139             }
140             
141         };
142
143         struct AnyTime {
144             enum Type {
145                     SMPTE,
146                     BBT,
147                     Frames,
148                     Seconds
149             };
150
151             Type type;
152
153             SMPTE::Time    smpte;
154             BBT_Time       bbt;
155
156             union { 
157                 nframes_t frames;
158                 double         seconds;
159             };
160
161             AnyTime() { type = Frames; frames = 0; }
162         };
163
164         struct AudioRange {
165             nframes_t start;
166             nframes_t end;
167             uint32_t id;
168             
169             AudioRange (nframes_t s, nframes_t e, uint32_t i) : start (s), end (e) , id (i) {}
170             
171             nframes_t length() { return end - start + 1; } 
172
173             bool operator== (const AudioRange& other) const {
174                     return start == other.start && end == other.end && id == other.id;
175             }
176
177             bool equal (const AudioRange& other) const {
178                     return start == other.start && end == other.end;
179             }
180
181             OverlapType coverage (nframes_t s, nframes_t e) const {
182                     return ARDOUR::coverage (start, end, s, e);
183             }
184         };
185         
186         struct MusicRange {
187             BBT_Time start;
188             BBT_Time end;
189             uint32_t id;
190             
191             MusicRange (BBT_Time& s, BBT_Time& e, uint32_t i)
192                     : start (s), end (e), id (i) {}
193
194             bool operator== (const MusicRange& other) const {
195                     return start == other.start && end == other.end && id == other.id;
196             }
197
198             bool equal (const MusicRange& other) const {
199                     return start == other.start && end == other.end;
200             }
201         };
202
203         /*
204             Slowest = 6.6dB/sec falloff at update rate of 40ms
205             Slow    = 6.8dB/sec falloff at update rate of 40ms
206         */
207
208         enum MeterFalloff {
209                 MeterFalloffOff = 0,
210                 MeterFalloffSlowest = 1,
211                 MeterFalloffSlow = 2,
212                 MeterFalloffMedium = 3,
213                 MeterFalloffFast = 4,
214                 MeterFalloffFaster = 5,
215                 MeterFalloffFastest = 6
216         };
217
218         enum MeterHold {
219                 MeterHoldOff = 0,
220                 MeterHoldShort = 40,
221                 MeterHoldMedium = 100,
222                 MeterHoldLong = 200
223         };
224
225         enum EditMode {
226                 Slide,
227                 Splice
228         };
229
230         enum RegionPoint { 
231             Start,
232             End,
233             SyncPoint
234         };
235
236         enum Change {
237                 range_guarantee = ~0
238         };
239
240
241         enum Placement {
242                 PreFader,
243                 PostFader
244         };
245
246         enum MonitorModel {
247                 HardwareMonitoring,
248                 SoftwareMonitoring,
249                 ExternalMonitoring,
250         };
251
252         enum CrossfadeModel {
253                 FullCrossfade,
254                 ShortCrossfade
255         };
256         
257         enum LayerModel {
258                 LaterHigher,
259                 MoveAddHigher,
260                 AddHigher
261         };
262
263         enum SoloModel {
264                 InverseMute,
265                 SoloBus
266         };
267
268         enum AutoConnectOption {
269                 AutoConnectPhysical = 0x1,
270                 AutoConnectMaster = 0x2
271         };
272
273         struct InterThreadInfo {
274             volatile bool  done;
275             volatile bool  cancel;
276             volatile float progress;
277             pthread_t      thread;
278         };
279
280         enum SampleFormat {
281                 FormatFloat = 0,
282                 FormatInt24
283         };
284
285
286         enum HeaderFormat {
287                 BWF,
288                 WAVE,
289                 WAVE64,
290                 CAF,
291                 AIFF,
292                 iXML,
293                 RF64
294         };
295
296         struct PeakData {
297             typedef Sample PeakDatum;
298             
299             PeakDatum min;
300             PeakDatum max;
301         };
302         
303         enum PluginType {
304                 AudioUnit,
305                 LADSPA,
306                 VST
307         };
308
309         enum SlaveSource {
310                 None = 0,
311                 MTC,
312                 JACK
313         };
314
315         enum ShuttleBehaviour {
316                 Sprung,
317                 Wheel
318         };
319
320         enum ShuttleUnits {
321                 Percentage,
322                 Semitones
323         };
324
325         typedef std::vector<boost::shared_ptr<AudioSource> > SourceList;
326
327 } // namespace ARDOUR
328
329 std::istream& operator>>(std::istream& o, ARDOUR::SampleFormat& sf);
330 std::istream& operator>>(std::istream& o, ARDOUR::HeaderFormat& sf);
331 std::istream& operator>>(std::istream& o, ARDOUR::AutoConnectOption& sf);
332 std::istream& operator>>(std::istream& o, ARDOUR::EditMode& sf);
333 std::istream& operator>>(std::istream& o, ARDOUR::MonitorModel& sf);
334 std::istream& operator>>(std::istream& o, ARDOUR::SoloModel& sf);
335 std::istream& operator>>(std::istream& o, ARDOUR::LayerModel& sf);
336 std::istream& operator>>(std::istream& o, ARDOUR::CrossfadeModel& sf);
337 std::istream& operator>>(std::istream& o, ARDOUR::SlaveSource& sf);
338 std::istream& operator>>(std::istream& o, ARDOUR::ShuttleBehaviour& sf);
339 std::istream& operator>>(std::istream& o, ARDOUR::ShuttleUnits& sf);
340
341 static inline nframes_t
342 session_frame_to_track_frame (nframes_t session_frame, double speed)
343 {
344         return (nframes_t)( (double)session_frame * speed );
345 }
346
347 static inline nframes_t
348 track_frame_to_session_frame (nframes_t track_frame, double speed)
349 {
350         return (nframes_t)( (double)track_frame / speed );
351 }
352
353
354 #endif /* __ardour_types_h__ */
355