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