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