0d32d35c7d8ab5afb8e329336b8f3cd89f038f4e
[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 <jack/midiport.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 /* eventually, we'd like everything (including JACK) to 
45    move to this. for now, its a dedicated type.
46 */
47
48 typedef int64_t                    nframes64_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         typedef uint32_t                    nframes_t;
61
62         typedef unsigned char Byte;
63
64         enum IOChange {
65                 NoChange = 0,
66                 ConfigurationChanged = 0x1,
67                 ConnectionsChanged = 0x2
68         };
69
70         enum OverlapType {
71                 OverlapNone,      // no overlap
72                 OverlapInternal,  // the overlap is 100% with the object
73                 OverlapStart,     // overlap covers start, but ends within
74                 OverlapEnd,       // overlap begins within and covers end 
75                 OverlapExternal   // overlap extends to (at least) begin+end
76         };
77
78         OverlapType coverage (nframes_t start_a, nframes_t end_a,
79                               nframes_t start_b, nframes_t end_b);
80
81         /** See parameter.h
82          * XXX: I don't think/hope these hex values matter anymore.
83          */
84         enum AutomationType {
85                 NullAutomation = 0x0,
86                 GainAutomation = 0x1,
87                 PanAutomation = 0x2,
88                 PluginAutomation = 0x4,
89                 SoloAutomation = 0x8,
90                 MuteAutomation = 0x10,
91                 MidiCCAutomation = 0x20,
92                 FadeInAutomation = 0x40,
93                 FadeOutAutomation = 0x80,
94                 EnvelopeAutomation = 0x100
95         };
96
97         enum AutoState {
98                 Off = 0x0,
99                 Write = 0x1,
100                 Touch = 0x2,
101                 Play = 0x4
102         };
103
104         std::string auto_state_to_string (AutoState);
105         AutoState string_to_auto_state (std::string);
106
107         enum AutoStyle {
108                 Absolute = 0x1,
109                 Trim = 0x2
110         };
111
112         std::string auto_style_to_string (AutoStyle);
113         AutoStyle string_to_auto_style (std::string);
114
115         enum AlignStyle {
116                 CaptureTime,
117                 ExistingMaterial
118         };
119
120         enum MeterPoint {
121                 MeterInput,
122                 MeterPreFader,
123                 MeterPostFader
124         };
125
126         enum TrackMode {
127                 Normal,
128                 Destructive
129         };
130         
131         enum NoteMode {
132                 Sustained,
133                 Percussive
134         };
135         
136         struct BBT_Time {
137             uint32_t bars;
138             uint32_t beats;
139             uint32_t ticks;
140
141             BBT_Time() {
142                     bars = 1;
143                     beats = 1;
144                     ticks = 0;
145             }
146
147             /* we can't define arithmetic operators for BBT_Time, because
148                the results depend on a TempoMap, but we can define 
149                a useful check on the less-than condition.
150             */
151
152             bool operator< (const BBT_Time& other) const {
153                     return bars < other.bars || 
154                             (bars == other.bars && beats < other.beats) ||
155                             (bars == other.bars && beats == other.beats && ticks < other.ticks);
156             }
157
158             bool operator== (const BBT_Time& other) const {
159                     return bars == other.bars && beats == other.beats && ticks == other.ticks;
160             }
161             
162         };
163         enum SmpteFormat {
164                 smpte_23976,
165                 smpte_24,
166                 smpte_24976,
167                 smpte_25,
168                 smpte_2997,
169                 smpte_2997drop,
170                 smpte_30,
171                 smpte_30drop,
172                 smpte_5994,
173                 smpte_60
174         };
175
176         struct AnyTime {
177             enum Type {
178                     SMPTE,
179                     BBT,
180                     Frames,
181                     Seconds
182             };
183
184             Type type;
185
186             SMPTE::Time    smpte;
187             BBT_Time       bbt;
188
189             union { 
190                 nframes_t frames;
191                 double         seconds;
192             };
193
194             AnyTime() { type = Frames; frames = 0; }
195         };
196
197         struct AudioRange {
198             nframes_t start;
199             nframes_t end;
200             uint32_t id;
201             
202             AudioRange (nframes_t s, nframes_t e, uint32_t i) : start (s), end (e) , id (i) {}
203             
204             nframes_t length() { return end - start + 1; } 
205
206             bool operator== (const AudioRange& other) const {
207                     return start == other.start && end == other.end && id == other.id;
208             }
209
210             bool equal (const AudioRange& other) const {
211                     return start == other.start && end == other.end;
212             }
213
214             OverlapType coverage (nframes_t s, nframes_t e) const {
215                     return ARDOUR::coverage (start, end, s, e);
216             }
217         };
218         
219         struct MusicRange {
220             BBT_Time start;
221             BBT_Time end;
222             uint32_t id;
223             
224             MusicRange (BBT_Time& s, BBT_Time& e, uint32_t i)
225                     : start (s), end (e), id (i) {}
226
227             bool operator== (const MusicRange& other) const {
228                     return start == other.start && end == other.end && id == other.id;
229             }
230
231             bool equal (const MusicRange& other) const {
232                     return start == other.start && end == other.end;
233             }
234         };
235
236         /*
237             Slowest = 6.6dB/sec falloff at update rate of 40ms
238             Slow    = 6.8dB/sec falloff at update rate of 40ms
239         */
240
241         enum MeterFalloff {
242                 MeterFalloffOff = 0,
243                 MeterFalloffSlowest = 1,
244                 MeterFalloffSlow = 2,
245                 MeterFalloffMedium = 3,
246                 MeterFalloffFast = 4,
247                 MeterFalloffFaster = 5,
248                 MeterFalloffFastest = 6
249         };
250
251         enum MeterHold {
252                 MeterHoldOff = 0,
253                 MeterHoldShort = 40,
254                 MeterHoldMedium = 100,
255                 MeterHoldLong = 200
256         };
257
258         enum EditMode {
259                 Slide,
260                 Splice
261         };
262
263         enum RegionPoint { 
264             Start,
265             End,
266             SyncPoint
267         };
268
269         enum Change {
270                 range_guarantee = ~0
271         };
272
273
274         enum Placement {
275                 PreFader,
276                 PostFader
277         };
278
279         enum MonitorModel {
280                 HardwareMonitoring,
281                 SoftwareMonitoring,
282                 ExternalMonitoring
283         };
284
285         enum DenormalModel {
286                 DenormalNone,
287                 DenormalFTZ,
288                 DenormalDAZ,
289                 DenormalFTZDAZ
290         };
291
292         enum RemoteModel {
293                 UserOrdered,
294                 MixerOrdered,
295                 EditorOrdered
296         };
297
298         enum CrossfadeModel {
299                 FullCrossfade,
300                 ShortCrossfade
301         };
302         
303         enum LayerModel {
304                 LaterHigher,
305                 MoveAddHigher,
306                 AddHigher
307         };
308
309         enum SoloModel {
310                 InverseMute,
311                 SoloBus
312         };
313
314         enum AutoConnectOption {
315                 AutoConnectPhysical = 0x1,
316                 AutoConnectMaster = 0x2
317         };
318
319         struct InterThreadInfo {
320             volatile bool  done;
321             volatile bool  cancel;
322             volatile float progress;
323             pthread_t      thread;
324         };
325
326         enum SampleFormat {
327                 FormatFloat = 0,
328                 FormatInt24,
329                 FormatInt16
330         };
331
332
333         enum HeaderFormat {
334                 BWF,
335                 WAVE,
336                 WAVE64,
337                 CAF,
338                 AIFF,
339                 iXML,
340                 RF64
341         };
342
343         struct PeakData {
344             typedef Sample PeakDatum;
345             
346             PeakDatum min;
347             PeakDatum max;
348         };
349         
350         enum PluginType {
351                 AudioUnit,
352                 LADSPA,
353                 VST
354         };
355
356         enum SlaveSource {
357                 None = 0,
358                 MTC,
359                 JACK
360         };
361
362         enum ShuttleBehaviour {
363                 Sprung,
364                 Wheel
365         };
366
367         enum ShuttleUnits {
368                 Percentage,
369                 Semitones
370         };
371
372         typedef std::vector<boost::shared_ptr<Source> > SourceList;
373
374         enum SrcQuality {
375                 SrcBest,
376                 SrcGood,
377                 SrcQuick,
378                 SrcFast,
379                 SrcFastest
380         };
381
382 } // namespace ARDOUR
383
384 std::istream& operator>>(std::istream& o, ARDOUR::SampleFormat& sf);
385 std::istream& operator>>(std::istream& o, ARDOUR::HeaderFormat& sf);
386 std::istream& operator>>(std::istream& o, ARDOUR::AutoConnectOption& sf);
387 std::istream& operator>>(std::istream& o, ARDOUR::EditMode& sf);
388 std::istream& operator>>(std::istream& o, ARDOUR::MonitorModel& sf);
389 std::istream& operator>>(std::istream& o, ARDOUR::RemoteModel& sf);
390 std::istream& operator>>(std::istream& o, ARDOUR::SoloModel& sf);
391 std::istream& operator>>(std::istream& o, ARDOUR::LayerModel& sf);
392 std::istream& operator>>(std::istream& o, ARDOUR::CrossfadeModel& sf);
393 std::istream& operator>>(std::istream& o, ARDOUR::SlaveSource& sf);
394 std::istream& operator>>(std::istream& o, ARDOUR::ShuttleBehaviour& sf);
395 std::istream& operator>>(std::istream& o, ARDOUR::ShuttleUnits& sf);
396 std::istream& operator>>(std::istream& o, ARDOUR::SmpteFormat& sf);
397 std::istream& operator>>(std::istream& o, ARDOUR::DenormalModel& sf);
398
399 using ARDOUR::nframes_t;
400
401 static inline nframes_t
402 session_frame_to_track_frame (nframes_t session_frame, double speed)
403 {
404         return (nframes_t)( (double)session_frame * speed );
405 }
406
407 static inline nframes_t
408 track_frame_to_session_frame (nframes_t track_frame, double speed)
409 {
410         return (nframes_t)( (double)track_frame / speed );
411 }
412
413
414 #endif /* __ardour_types_h__ */
415