merge denormal handling work from 2.0-ongoing
[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 */
19
20 #ifndef __ardour_types_h__
21 #define __ardour_types_h__
22
23 #ifndef __STDC_FORMAT_MACROS
24 #define __STDC_FORMAT_MACROS /* PRI<foo>; C++ requires explicit requesting of these */
25 #endif
26
27 #include <istream>
28 #include <vector>
29 #include <boost/shared_ptr.hpp>
30
31 #include <inttypes.h>
32 #include <jack/types.h>
33 #include <jack/midiport.h>
34 #include <control_protocol/smpte.h>
35 #include <pbd/id.h>
36
37 #include <map>
38
39 #if __GNUC__ < 3
40
41 typedef int intptr_t;
42 #endif
43
44 /* eventually, we'd like everything (including JACK) to 
45    move to this. for now, its a dedicated type.
46 */
47
48 typedef int64_t                    nframes64_t;
49
50 namespace ARDOUR {
51
52         class Source;
53         class AudioSource;
54
55         typedef jack_default_audio_sample_t Sample;
56         typedef float                       pan_t;
57         typedef float                       gain_t;
58         typedef uint32_t                    layer_t;
59         typedef uint64_t                    microseconds_t;
60         typedef uint32_t                    nframes_t;
61
62         typedef jack_midi_event_t MidiEvent;
63         typedef unsigned char     Byte;
64
65         enum IOChange {
66                 NoChange = 0,
67                 ConfigurationChanged = 0x1,
68                 ConnectionsChanged = 0x2
69         };
70
71         enum OverlapType {
72                 OverlapNone,      // no overlap
73                 OverlapInternal,  // the overlap is 100% with the object
74                 OverlapStart,     // overlap covers start, but ends within
75                 OverlapEnd,       // overlap begins within and covers end 
76                 OverlapExternal   // overlap extends to (at least) begin+end
77         };
78
79         OverlapType coverage (nframes_t start_a, nframes_t end_a,
80                               nframes_t start_b, nframes_t end_b);
81
82         enum AutomationType {
83                 GainAutomation = 0x1,
84                 PanAutomation = 0x2,
85                 PluginAutomation = 0x4,
86                 SoloAutomation = 0x8,
87                 MuteAutomation = 0x10
88         };
89
90         enum AutoState {
91                 Off = 0x0,
92                 Write = 0x1,
93                 Touch = 0x2,
94                 Play = 0x4
95         };
96
97         std::string auto_state_to_string (AutoState);
98         AutoState string_to_auto_state (std::string);
99
100         enum AutoStyle {
101                 Absolute = 0x1,
102                 Trim = 0x2
103         };
104
105         std::string auto_style_to_string (AutoStyle);
106         AutoStyle string_to_auto_style (std::string);
107
108         enum AlignStyle {
109                 CaptureTime,
110                 ExistingMaterial
111         };
112
113         enum MeterPoint {
114                 MeterInput,
115                 MeterPreFader,
116                 MeterPostFader
117         };
118
119         enum TrackMode {
120                 Normal,
121                 Destructive
122         };
123         
124         struct BBT_Time {
125             uint32_t bars;
126             uint32_t beats;
127             uint32_t ticks;
128
129             BBT_Time() {
130                     bars = 1;
131                     beats = 1;
132                     ticks = 0;
133             }
134
135             /* we can't define arithmetic operators for BBT_Time, because
136                the results depend on a TempoMap, but we can define 
137                a useful check on the less-than condition.
138             */
139
140             bool operator< (const BBT_Time& other) const {
141                     return bars < other.bars || 
142                             (bars == other.bars && beats < other.beats) ||
143                             (bars == other.bars && beats == other.beats && ticks < other.ticks);
144             }
145
146             bool operator== (const BBT_Time& other) const {
147                     return bars == other.bars && beats == other.beats && ticks == other.ticks;
148             }
149             
150         };
151         enum SmpteFormat {
152                 smpte_23976,
153                 smpte_24,
154                 smpte_24976,
155                 smpte_25,
156                 smpte_2997,
157                 smpte_2997drop,
158                 smpte_30,
159                 smpte_30drop,
160                 smpte_5994,
161                 smpte_60
162         };
163
164         struct AnyTime {
165             enum Type {
166                     SMPTE,
167                     BBT,
168                     Frames,
169                     Seconds
170             };
171
172             Type type;
173
174             SMPTE::Time    smpte;
175             BBT_Time       bbt;
176
177             union { 
178                 nframes_t frames;
179                 double         seconds;
180             };
181
182             AnyTime() { type = Frames; frames = 0; }
183         };
184
185         struct AudioRange {
186             nframes_t start;
187             nframes_t end;
188             uint32_t id;
189             
190             AudioRange (nframes_t s, nframes_t e, uint32_t i) : start (s), end (e) , id (i) {}
191             
192             nframes_t length() { return end - start + 1; } 
193
194             bool operator== (const AudioRange& other) const {
195                     return start == other.start && end == other.end && id == other.id;
196             }
197
198             bool equal (const AudioRange& other) const {
199                     return start == other.start && end == other.end;
200             }
201
202             OverlapType coverage (nframes_t s, nframes_t e) const {
203                     return ARDOUR::coverage (start, end, s, e);
204             }
205         };
206         
207         struct MusicRange {
208             BBT_Time start;
209             BBT_Time end;
210             uint32_t id;
211             
212             MusicRange (BBT_Time& s, BBT_Time& e, uint32_t i)
213                     : start (s), end (e), id (i) {}
214
215             bool operator== (const MusicRange& other) const {
216                     return start == other.start && end == other.end && id == other.id;
217             }
218
219             bool equal (const MusicRange& other) const {
220                     return start == other.start && end == other.end;
221             }
222         };
223
224         /*
225             Slowest = 6.6dB/sec falloff at update rate of 40ms
226             Slow    = 6.8dB/sec falloff at update rate of 40ms
227         */
228
229         enum MeterFalloff {
230                 MeterFalloffOff = 0,
231                 MeterFalloffSlowest = 1,
232                 MeterFalloffSlow = 2,
233                 MeterFalloffMedium = 3,
234                 MeterFalloffFast = 4,
235                 MeterFalloffFaster = 5,
236                 MeterFalloffFastest = 6
237         };
238
239         enum MeterHold {
240                 MeterHoldOff = 0,
241                 MeterHoldShort = 40,
242                 MeterHoldMedium = 100,
243                 MeterHoldLong = 200
244         };
245
246         enum EditMode {
247                 Slide,
248                 Splice
249         };
250
251         enum RegionPoint { 
252             Start,
253             End,
254             SyncPoint
255         };
256
257         enum Change {
258                 range_guarantee = ~0
259         };
260
261
262         enum Placement {
263                 PreFader,
264                 PostFader
265         };
266
267         enum MonitorModel {
268                 HardwareMonitoring,
269                 SoftwareMonitoring,
270                 ExternalMonitoring,
271         };
272
273         enum DenormalModel {
274                 DenormalNone,
275                 DenormalFTZ,
276                 DenormalDAZ,
277                 DenormalFTZDAZ
278         };
279
280         enum RemoteModel {
281                 UserOrdered,
282                 MixerOrdered,
283                 EditorOrdered,
284         };
285
286         enum CrossfadeModel {
287                 FullCrossfade,
288                 ShortCrossfade
289         };
290         
291         enum LayerModel {
292                 LaterHigher,
293                 MoveAddHigher,
294                 AddHigher
295         };
296
297         enum SoloModel {
298                 InverseMute,
299                 SoloBus
300         };
301
302         enum AutoConnectOption {
303                 AutoConnectPhysical = 0x1,
304                 AutoConnectMaster = 0x2
305         };
306
307         struct InterThreadInfo {
308             volatile bool  done;
309             volatile bool  cancel;
310             volatile float progress;
311             pthread_t      thread;
312         };
313
314         enum SampleFormat {
315                 FormatFloat = 0,
316                 FormatInt24
317         };
318
319
320         enum HeaderFormat {
321                 BWF,
322                 WAVE,
323                 WAVE64,
324                 CAF,
325                 AIFF,
326                 iXML,
327                 RF64
328         };
329
330         struct PeakData {
331             typedef Sample PeakDatum;
332             
333             PeakDatum min;
334             PeakDatum max;
335         };
336         
337         enum PluginType {
338                 AudioUnit,
339                 LADSPA,
340                 VST
341         };
342
343         enum SlaveSource {
344                 None = 0,
345                 MTC,
346                 JACK
347         };
348
349         enum ShuttleBehaviour {
350                 Sprung,
351                 Wheel
352         };
353
354         enum ShuttleUnits {
355                 Percentage,
356                 Semitones
357         };
358
359         typedef std::vector<boost::shared_ptr<Source> > SourceList;
360 } // namespace ARDOUR
361
362 std::istream& operator>>(std::istream& o, ARDOUR::SampleFormat& sf);
363 std::istream& operator>>(std::istream& o, ARDOUR::HeaderFormat& sf);
364 std::istream& operator>>(std::istream& o, ARDOUR::AutoConnectOption& sf);
365 std::istream& operator>>(std::istream& o, ARDOUR::EditMode& sf);
366 std::istream& operator>>(std::istream& o, ARDOUR::MonitorModel& sf);
367 std::istream& operator>>(std::istream& o, ARDOUR::RemoteModel& sf);
368 std::istream& operator>>(std::istream& o, ARDOUR::SoloModel& sf);
369 std::istream& operator>>(std::istream& o, ARDOUR::LayerModel& sf);
370 std::istream& operator>>(std::istream& o, ARDOUR::CrossfadeModel& sf);
371 std::istream& operator>>(std::istream& o, ARDOUR::SlaveSource& sf);
372 std::istream& operator>>(std::istream& o, ARDOUR::ShuttleBehaviour& sf);
373 std::istream& operator>>(std::istream& o, ARDOUR::ShuttleUnits& sf);
374 std::istream& operator>>(std::istream& o, ARDOUR::SmpteFormat& sf);
375 std::istream& operator>>(std::istream& o, ARDOUR::DenormalModel& sf);
376
377 using ARDOUR::nframes_t;
378
379 static inline nframes_t
380 session_frame_to_track_frame (nframes_t session_frame, double speed)
381 {
382         return (nframes_t)( (double)session_frame * speed );
383 }
384
385 static inline nframes_t
386 track_frame_to_session_frame (nframes_t track_frame, double speed)
387 {
388         return (nframes_t)( (double)track_frame / speed );
389 }
390
391
392 #endif /* __ardour_types_h__ */
393