General SMPTE fixes mostly relating to non-integer frame rates. Please Test. Fix...
[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         enum SmpteFormat {
149                 smpte_23976,
150                 smpte_24,
151                 smpte_24976,
152                 smpte_25,
153                 smpte_2997,
154                 smpte_2997drop,
155                 smpte_30,
156                 smpte_30drop,
157                 smpte_5994,
158                 smpte_60
159         };
160
161         struct AnyTime {
162             enum Type {
163                     SMPTE,
164                     BBT,
165                     Frames,
166                     Seconds
167             };
168
169             Type type;
170
171             SMPTE::Time    smpte;
172             BBT_Time       bbt;
173
174             union { 
175                 nframes_t frames;
176                 double         seconds;
177             };
178
179             AnyTime() { type = Frames; frames = 0; }
180         };
181
182         struct AudioRange {
183             nframes_t start;
184             nframes_t end;
185             uint32_t id;
186             
187             AudioRange (nframes_t s, nframes_t e, uint32_t i) : start (s), end (e) , id (i) {}
188             
189             nframes_t length() { return end - start + 1; } 
190
191             bool operator== (const AudioRange& other) const {
192                     return start == other.start && end == other.end && id == other.id;
193             }
194
195             bool equal (const AudioRange& other) const {
196                     return start == other.start && end == other.end;
197             }
198
199             OverlapType coverage (nframes_t s, nframes_t e) const {
200                     return ARDOUR::coverage (start, end, s, e);
201             }
202         };
203         
204         struct MusicRange {
205             BBT_Time start;
206             BBT_Time end;
207             uint32_t id;
208             
209             MusicRange (BBT_Time& s, BBT_Time& e, uint32_t i)
210                     : start (s), end (e), id (i) {}
211
212             bool operator== (const MusicRange& other) const {
213                     return start == other.start && end == other.end && id == other.id;
214             }
215
216             bool equal (const MusicRange& other) const {
217                     return start == other.start && end == other.end;
218             }
219         };
220
221         /*
222             Slowest = 6.6dB/sec falloff at update rate of 40ms
223             Slow    = 6.8dB/sec falloff at update rate of 40ms
224         */
225
226         enum MeterFalloff {
227                 MeterFalloffOff = 0,
228                 MeterFalloffSlowest = 1,
229                 MeterFalloffSlow = 2,
230                 MeterFalloffMedium = 3,
231                 MeterFalloffFast = 4,
232                 MeterFalloffFaster = 5,
233                 MeterFalloffFastest = 6
234         };
235
236         enum MeterHold {
237                 MeterHoldOff = 0,
238                 MeterHoldShort = 40,
239                 MeterHoldMedium = 100,
240                 MeterHoldLong = 200
241         };
242
243         enum EditMode {
244                 Slide,
245                 Splice
246         };
247
248         enum RegionPoint { 
249             Start,
250             End,
251             SyncPoint
252         };
253
254         enum Change {
255                 range_guarantee = ~0
256         };
257
258
259         enum Placement {
260                 PreFader,
261                 PostFader
262         };
263
264         enum MonitorModel {
265                 HardwareMonitoring,
266                 SoftwareMonitoring,
267                 ExternalMonitoring,
268         };
269
270         enum CrossfadeModel {
271                 FullCrossfade,
272                 ShortCrossfade
273         };
274         
275         enum LayerModel {
276                 LaterHigher,
277                 MoveAddHigher,
278                 AddHigher
279         };
280
281         enum SoloModel {
282                 InverseMute,
283                 SoloBus
284         };
285
286         enum AutoConnectOption {
287                 AutoConnectPhysical = 0x1,
288                 AutoConnectMaster = 0x2
289         };
290
291         struct InterThreadInfo {
292             volatile bool  done;
293             volatile bool  cancel;
294             volatile float progress;
295             pthread_t      thread;
296         };
297
298         enum SampleFormat {
299                 FormatFloat = 0,
300                 FormatInt24
301         };
302
303
304         enum HeaderFormat {
305                 BWF,
306                 WAVE,
307                 WAVE64,
308                 CAF,
309                 AIFF,
310                 iXML,
311                 RF64
312         };
313
314         struct PeakData {
315             typedef Sample PeakDatum;
316             
317             PeakDatum min;
318             PeakDatum max;
319         };
320         
321         enum PluginType {
322                 AudioUnit,
323                 LADSPA,
324                 VST
325         };
326
327         enum SlaveSource {
328                 None = 0,
329                 MTC,
330                 JACK
331         };
332
333         enum ShuttleBehaviour {
334                 Sprung,
335                 Wheel
336         };
337
338         enum ShuttleUnits {
339                 Percentage,
340                 Semitones
341         };
342
343         typedef std::vector<boost::shared_ptr<AudioSource> > SourceList;
344
345 } // namespace ARDOUR
346
347 std::istream& operator>>(std::istream& o, ARDOUR::SampleFormat& sf);
348 std::istream& operator>>(std::istream& o, ARDOUR::HeaderFormat& sf);
349 std::istream& operator>>(std::istream& o, ARDOUR::AutoConnectOption& sf);
350 std::istream& operator>>(std::istream& o, ARDOUR::EditMode& sf);
351 std::istream& operator>>(std::istream& o, ARDOUR::MonitorModel& sf);
352 std::istream& operator>>(std::istream& o, ARDOUR::SoloModel& sf);
353 std::istream& operator>>(std::istream& o, ARDOUR::LayerModel& sf);
354 std::istream& operator>>(std::istream& o, ARDOUR::CrossfadeModel& sf);
355 std::istream& operator>>(std::istream& o, ARDOUR::SlaveSource& sf);
356 std::istream& operator>>(std::istream& o, ARDOUR::ShuttleBehaviour& sf);
357 std::istream& operator>>(std::istream& o, ARDOUR::ShuttleUnits& sf);
358 std::istream& operator>>(std::istream& o, ARDOUR::SmpteFormat& sf);
359
360 static inline nframes_t
361 session_frame_to_track_frame (nframes_t session_frame, double speed)
362 {
363         return (nframes_t)( (double)session_frame * speed );
364 }
365
366 static inline nframes_t
367 track_frame_to_session_frame (nframes_t track_frame, double speed)
368 {
369         return (nframes_t)( (double)track_frame / speed );
370 }
371
372
373 #endif /* __ardour_types_h__ */
374