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