Merged with trunk R861
[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
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 (jack_nframes_t start_a, jack_nframes_t end_a,
74                               jack_nframes_t start_b, jack_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         enum AutoStyle {
92                 Absolute = 0x1,
93                 Trim = 0x2
94         };
95
96         enum AlignStyle {
97                 CaptureTime,
98                 ExistingMaterial
99         };
100
101         enum MeterPoint {
102                 MeterInput,
103                 MeterPreFader,
104                 MeterPostFader
105         };
106
107         enum TrackMode {
108                 Normal,
109                 Destructive
110         };
111         
112         struct BBT_Time {
113             uint32_t bars;
114             uint32_t beats;
115             uint32_t ticks;
116
117             BBT_Time() {
118                     bars = 1;
119                     beats = 1;
120                     ticks = 0;
121             }
122
123             /* we can't define arithmetic operators for BBT_Time, because
124                the results depend on a TempoMap, but we can define 
125                a useful check on the less-than condition.
126             */
127
128             bool operator< (const BBT_Time& other) const {
129                     return bars < other.bars || 
130                             (bars == other.bars && beats < other.beats) ||
131                             (bars == other.bars && beats == other.beats && ticks < other.ticks);
132             }
133
134             bool operator== (const BBT_Time& other) const {
135                     return bars == other.bars && beats == other.beats && ticks == other.ticks;
136             }
137             
138         };
139
140         struct AnyTime {
141             enum Type {
142                     SMPTE,
143                     BBT,
144                     Frames,
145                     Seconds
146             };
147
148             Type type;
149
150             SMPTE::Time    smpte;
151             BBT_Time       bbt;
152
153             union { 
154                 jack_nframes_t frames;
155                 double         seconds;
156             };
157         };
158
159         struct AudioRange {
160             jack_nframes_t start;
161             jack_nframes_t end;
162             uint32_t id;
163             
164             AudioRange (jack_nframes_t s, jack_nframes_t e, uint32_t i) : start (s), end (e) , id (i) {}
165             
166             jack_nframes_t length() { return end - start + 1; } 
167
168             bool operator== (const AudioRange& other) const {
169                     return start == other.start && end == other.end && id == other.id;
170             }
171
172             bool equal (const AudioRange& other) const {
173                     return start == other.start && end == other.end;
174             }
175
176             OverlapType coverage (jack_nframes_t s, jack_nframes_t e) const {
177                     return ARDOUR::coverage (start, end, s, e);
178             }
179         };
180         
181         struct MusicRange {
182             BBT_Time start;
183             BBT_Time end;
184             uint32_t id;
185             
186             MusicRange (BBT_Time& s, BBT_Time& e, uint32_t i)
187                     : start (s), end (e), id (i) {}
188
189             bool operator== (const MusicRange& other) const {
190                     return start == other.start && end == other.end && id == other.id;
191             }
192
193             bool equal (const MusicRange& other) const {
194                     return start == other.start && end == other.end;
195             }
196         };
197
198         enum EditMode {
199                 Slide,
200                 Splice
201         };
202
203         enum RegionPoint { 
204             Start,
205             End,
206             SyncPoint
207         };
208
209         enum Change {
210                 range_guarantee = ~0
211         };
212
213
214         enum Placement {
215                 PreFader,
216                 PostFader
217         };
218
219         enum CrossfadeModel {
220                 FullCrossfade,
221                 ShortCrossfade
222         };
223
224         struct InterThreadInfo {
225             volatile bool  done;
226             volatile bool  cancel;
227             volatile float progress;
228             pthread_t      thread;
229         };
230
231         enum SampleFormat {
232                 FormatFloat = 0,
233                 FormatInt24
234         };
235
236
237         enum HeaderFormat {
238                 BWF,
239                 WAVE,
240                 WAVE64,
241                 CAF,
242                 AIFF,
243                 iXML,
244                 RF64
245         };
246
247         struct PeakData {
248             typedef Sample PeakDatum;
249             
250             PeakDatum min;
251             PeakDatum max;
252         };
253         
254         enum PluginType {
255                 AudioUnit,
256                 LADSPA,
257                 VST
258         };
259         
260         typedef std::vector<boost::shared_ptr<Source> > SourceList;
261 } // namespace ARDOUR
262
263 std::istream& operator>>(std::istream& o, ARDOUR::SampleFormat& sf);
264 std::istream& operator>>(std::istream& o, ARDOUR::HeaderFormat& sf);
265
266 static inline jack_nframes_t
267 session_frame_to_track_frame (jack_nframes_t session_frame, double speed)
268 {
269         return (jack_nframes_t)( (double)session_frame * speed );
270 }
271
272 static inline jack_nframes_t
273 track_frame_to_session_frame (jack_nframes_t track_frame, double speed)
274 {
275         return (jack_nframes_t)( (double)track_frame / speed );
276 }
277
278
279 #endif /* __ardour_types_h__ */
280