00833f65475ea6d1ceacdc61db76a0ee8f020db3
[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
30 #include <inttypes.h>
31 #include <jack/types.h>
32 #include <jack/midiport.h>
33 #include <control_protocol/smpte.h>
34 #include <pbd/id.h>
35
36 #include <map>
37
38 #if __GNUC__ < 3
39
40 typedef int intptr_t;
41 #endif
42
43 namespace ARDOUR {
44
45         class Source;
46
47         typedef jack_default_audio_sample_t Sample;
48         typedef float                       pan_t;
49         typedef float                       gain_t;
50         typedef uint32_t                    layer_t;
51         typedef uint64_t                    microseconds_t;
52
53         typedef jack_midi_event_t RawMidi;
54
55         enum IOChange {
56                 NoChange = 0,
57                 ConfigurationChanged = 0x1,
58                 ConnectionsChanged = 0x2
59         };
60
61         enum OverlapType {
62                 OverlapNone,      // no overlap
63                 OverlapInternal,  // the overlap is 100% with the object
64                 OverlapStart,     // overlap covers start, but ends within
65                 OverlapEnd,       // overlap begins within and covers end 
66                 OverlapExternal   // overlap extends to (at least) begin+end
67         };
68
69         OverlapType coverage (jack_nframes_t start_a, jack_nframes_t end_a,
70                               jack_nframes_t start_b, jack_nframes_t end_b);
71
72         enum AutomationType {
73                 GainAutomation = 0x1,
74                 PanAutomation = 0x2,
75                 PluginAutomation = 0x4,
76                 SoloAutomation = 0x8,
77                 MuteAutomation = 0x10
78         };
79
80         enum AutoState {
81                 Off = 0x0,
82                 Write = 0x1,
83                 Touch = 0x2,
84                 Play = 0x4
85         };
86
87         enum AutoStyle {
88                 Absolute = 0x1,
89                 Trim = 0x2
90         };
91
92         enum AlignStyle {
93                 CaptureTime,
94                 ExistingMaterial
95         };
96
97         enum MeterPoint {
98                 MeterInput,
99                 MeterPreFader,
100                 MeterPostFader
101         };
102
103         enum TrackMode {
104                 Normal,
105                 Destructive
106         };
107         
108         struct BBT_Time {
109             uint32_t bars;
110             uint32_t beats;
111             uint32_t ticks;
112
113             BBT_Time() {
114                     bars = 1;
115                     beats = 1;
116                     ticks = 0;
117             }
118
119             /* we can't define arithmetic operators for BBT_Time, because
120                the results depend on a TempoMap, but we can define 
121                a useful check on the less-than condition.
122             */
123
124             bool operator< (const BBT_Time& other) const {
125                     return bars < other.bars || 
126                             (bars == other.bars && beats < other.beats) ||
127                             (bars == other.bars && beats == other.beats && ticks < other.ticks);
128             }
129
130             bool operator== (const BBT_Time& other) const {
131                     return bars == other.bars && beats == other.beats && ticks == other.ticks;
132             }
133             
134         };
135
136         struct AnyTime {
137             enum Type {
138                     SMPTE,
139                     BBT,
140                     Frames,
141                     Seconds
142             };
143
144             Type type;
145
146             SMPTE::Time    smpte;
147             BBT_Time       bbt;
148
149             union { 
150                 jack_nframes_t frames;
151                 double         seconds;
152             };
153         };
154
155         struct AudioRange {
156             jack_nframes_t start;
157             jack_nframes_t end;
158             uint32_t id;
159             
160             AudioRange (jack_nframes_t s, jack_nframes_t e, uint32_t i) : start (s), end (e) , id (i) {}
161             
162             jack_nframes_t length() { return end - start + 1; } 
163
164             bool operator== (const AudioRange& other) const {
165                     return start == other.start && end == other.end && id == other.id;
166             }
167
168             bool equal (const AudioRange& other) const {
169                     return start == other.start && end == other.end;
170             }
171
172             OverlapType coverage (jack_nframes_t s, jack_nframes_t e) const {
173                     return ARDOUR::coverage (start, end, s, e);
174             }
175         };
176         
177         struct MusicRange {
178             BBT_Time start;
179             BBT_Time end;
180             uint32_t id;
181             
182             MusicRange (BBT_Time& s, BBT_Time& e, uint32_t i)
183                     : start (s), end (e), id (i) {}
184
185             bool operator== (const MusicRange& other) const {
186                     return start == other.start && end == other.end && id == other.id;
187             }
188
189             bool equal (const MusicRange& other) const {
190                     return start == other.start && end == other.end;
191             }
192         };
193
194         enum EditMode {
195                 Slide,
196                 Splice
197         };
198
199         enum RegionPoint { 
200             Start,
201             End,
202             SyncPoint
203         };
204
205         enum Change {
206                 range_guarantee = ~0
207         };
208
209
210         enum Placement {
211                 PreFader,
212                 PostFader
213         };
214
215         enum CrossfadeModel {
216                 FullCrossfade,
217                 ShortCrossfade
218         };
219
220         struct InterThreadInfo {
221             volatile bool  done;
222             volatile bool  cancel;
223             volatile float progress;
224             pthread_t      thread;
225         };
226
227         enum SampleFormat {
228                 FormatFloat = 0,
229                 FormatInt24
230         };
231
232
233         enum HeaderFormat {
234                 BWF,
235                 WAVE,
236                 WAVE64,
237                 CAF,
238                 AIFF,
239                 iXML,
240                 RF64
241         };
242
243         struct PeakData {
244             typedef Sample PeakDatum;
245             
246             PeakDatum min;
247             PeakDatum max;
248         };
249         
250         enum PluginType {
251                 AudioUnit,
252                 LADSPA,
253                 VST
254         };
255         
256 } // namespace ARDOUR
257
258 std::istream& operator>>(std::istream& o, ARDOUR::SampleFormat& sf);
259 std::istream& operator>>(std::istream& o, ARDOUR::HeaderFormat& sf);
260
261 static inline jack_nframes_t
262 session_frame_to_track_frame (jack_nframes_t session_frame, double speed)
263 {
264         return (jack_nframes_t)( (double)session_frame * speed );
265 }
266
267 static inline jack_nframes_t
268 track_frame_to_session_frame (jack_nframes_t track_frame, double speed)
269 {
270         return (jack_nframes_t)( (double)track_frame / speed );
271 }
272
273
274 #endif /* __ardour_types_h__ */
275