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