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