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