55655e9e261b5328e84d9efa3a0a0409ce76e47c
[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 unsigned char Byte;
63
64         enum IOChange {
65                 NoChange = 0,
66                 ConfigurationChanged = 0x1,
67                 ConnectionsChanged = 0x2
68         };
69
70         enum OverlapType {
71                 OverlapNone,      // no overlap
72                 OverlapInternal,  // the overlap is 100% with the object
73                 OverlapStart,     // overlap covers start, but ends within
74                 OverlapEnd,       // overlap begins within and covers end 
75                 OverlapExternal   // overlap extends to (at least) begin+end
76         };
77
78         OverlapType coverage (nframes_t start_a, nframes_t end_a,
79                               nframes_t start_b, nframes_t end_b);
80
81         /** See parameter.h
82          * XXX: I don't think/hope these hex values matter anymore.
83          */
84         enum AutomationType {
85                 NullAutomation = 0x0,
86                 GainAutomation = 0x1,
87                 PanAutomation = 0x2,
88                 PluginAutomation = 0x4,
89                 SoloAutomation = 0x8,
90                 MuteAutomation = 0x10,
91                 MidiCCAutomation = 0x20,
92                 MidiPgmChangeAutomation = 0x21,
93                 MidiPitchBenderAutomation = 0x22,
94                 MidiChannelAftertouchAutomation = 0x23,
95                 FadeInAutomation = 0x40,
96                 FadeOutAutomation = 0x80,
97                 EnvelopeAutomation = 0x100
98         };
99
100         enum AutoState {
101                 Off = 0x0,
102                 Write = 0x1,
103                 Touch = 0x2,
104                 Play = 0x4
105         };
106
107         std::string auto_state_to_string (AutoState);
108         AutoState string_to_auto_state (std::string);
109
110         enum AutoStyle {
111                 Absolute = 0x1,
112                 Trim = 0x2
113         };
114
115         std::string auto_style_to_string (AutoStyle);
116         AutoStyle string_to_auto_style (std::string);
117
118         enum AlignStyle {
119                 CaptureTime,
120                 ExistingMaterial
121         };
122
123         enum MeterPoint {
124                 MeterInput,
125                 MeterPreFader,
126                 MeterPostFader
127         };
128
129         enum TrackMode {
130                 Normal,
131                 Destructive
132         };
133         
134         enum NoteMode {
135                 Sustained,
136                 Percussive
137         };
138         
139         enum ChannelMode {
140                 AllChannels = 0, ///< Pass through all channel information unmodified
141                 FilterChannels,  ///< Ignore events on certain channels
142                 ForceChannel     ///< Force all events to a certain channel
143         };
144
145         enum EventTimeUnit {
146                 Frames,
147                 Beats
148         };
149         
150         struct BBT_Time {
151             uint32_t bars;
152             uint32_t beats;
153             uint32_t ticks;
154
155             BBT_Time() {
156                     bars = 1;
157                     beats = 1;
158                     ticks = 0;
159             }
160
161             /* we can't define arithmetic operators for BBT_Time, because
162                the results depend on a TempoMap, but we can define 
163                a useful check on the less-than condition.
164             */
165
166             bool operator< (const BBT_Time& other) const {
167                     return bars < other.bars || 
168                             (bars == other.bars && beats < other.beats) ||
169                             (bars == other.bars && beats == other.beats && ticks < other.ticks);
170             }
171
172             bool operator== (const BBT_Time& other) const {
173                     return bars == other.bars && beats == other.beats && ticks == other.ticks;
174             }
175             
176         };
177         enum SmpteFormat {
178                 smpte_23976,
179                 smpte_24,
180                 smpte_24976,
181                 smpte_25,
182                 smpte_2997,
183                 smpte_2997drop,
184                 smpte_30,
185                 smpte_30drop,
186                 smpte_5994,
187                 smpte_60
188         };
189
190         struct AnyTime {
191             enum Type {
192                     SMPTE,
193                     BBT,
194                     Frames,
195                     Seconds
196             };
197
198             Type type;
199
200             SMPTE::Time    smpte;
201             BBT_Time       bbt;
202
203             union { 
204                 nframes_t frames;
205                 double         seconds;
206             };
207
208             AnyTime() { type = Frames; frames = 0; }
209         };
210
211         struct AudioRange {
212             nframes_t start;
213             nframes_t end;
214             uint32_t id;
215             
216             AudioRange (nframes_t s, nframes_t e, uint32_t i) : start (s), end (e) , id (i) {}
217             
218             nframes_t length() { return end - start + 1; } 
219
220             bool operator== (const AudioRange& other) const {
221                     return start == other.start && end == other.end && id == other.id;
222             }
223
224             bool equal (const AudioRange& other) const {
225                     return start == other.start && end == other.end;
226             }
227
228             OverlapType coverage (nframes_t s, nframes_t e) const {
229                     return ARDOUR::coverage (start, end, s, e);
230             }
231         };
232         
233         struct MusicRange {
234             BBT_Time start;
235             BBT_Time end;
236             uint32_t id;
237             
238             MusicRange (BBT_Time& s, BBT_Time& e, uint32_t i)
239                     : start (s), end (e), id (i) {}
240
241             bool operator== (const MusicRange& other) const {
242                     return start == other.start && end == other.end && id == other.id;
243             }
244
245             bool equal (const MusicRange& other) const {
246                     return start == other.start && end == other.end;
247             }
248         };
249
250         /*
251             Slowest = 6.6dB/sec falloff at update rate of 40ms
252             Slow    = 6.8dB/sec falloff at update rate of 40ms
253         */
254
255         enum MeterFalloff {
256                 MeterFalloffOff = 0,
257                 MeterFalloffSlowest = 1,
258                 MeterFalloffSlow = 2,
259                 MeterFalloffMedium = 3,
260                 MeterFalloffFast = 4,
261                 MeterFalloffFaster = 5,
262                 MeterFalloffFastest = 6
263         };
264
265         enum MeterHold {
266                 MeterHoldOff = 0,
267                 MeterHoldShort = 40,
268                 MeterHoldMedium = 100,
269                 MeterHoldLong = 200
270         };
271
272         enum EditMode {
273                 Slide,
274                 Splice,
275                 Lock
276         };
277
278         enum RegionPoint { 
279             Start,
280             End,
281             SyncPoint
282         };
283
284         enum Change {
285                 range_guarantee = ~0
286         };
287
288
289         enum Placement {
290                 PreFader,
291                 PostFader
292         };
293
294         enum MonitorModel {
295                 HardwareMonitoring,
296                 SoftwareMonitoring,
297                 ExternalMonitoring
298         };
299
300         enum DenormalModel {
301                 DenormalNone,
302                 DenormalFTZ,
303                 DenormalDAZ,
304                 DenormalFTZDAZ
305         };
306
307         enum RemoteModel {
308                 UserOrdered,
309                 MixerOrdered,
310                 EditorOrdered
311         };
312
313         enum CrossfadeModel {
314                 FullCrossfade,
315                 ShortCrossfade
316         };
317         
318         enum LayerModel {
319                 LaterHigher,
320                 MoveAddHigher,
321                 AddHigher
322         };
323
324         enum SoloModel {
325                 InverseMute,
326                 SoloBus
327         };
328
329         enum AutoConnectOption {
330                 AutoConnectPhysical = 0x1,
331                 AutoConnectMaster = 0x2
332         };
333
334         struct InterThreadInfo {
335             volatile bool  done;
336             volatile bool  cancel;
337             volatile float progress;
338             pthread_t      thread;
339         };
340
341         enum SampleFormat {
342                 FormatFloat = 0,
343                 FormatInt24,
344                 FormatInt16
345         };
346
347
348         enum HeaderFormat {
349                 BWF,
350                 WAVE,
351                 WAVE64,
352                 CAF,
353                 AIFF,
354                 iXML,
355                 RF64
356         };
357
358         struct PeakData {
359             typedef Sample PeakDatum;
360             
361             PeakDatum min;
362             PeakDatum max;
363         };
364         
365         enum PluginType {
366                 AudioUnit,
367                 LADSPA,
368                 LV2,
369                 VST
370         };
371
372         enum SlaveSource {
373                 None = 0,
374                 MTC,
375                 JACK
376         };
377
378         enum ShuttleBehaviour {
379                 Sprung,
380                 Wheel
381         };
382
383         enum ShuttleUnits {
384                 Percentage,
385                 Semitones
386         };
387
388         typedef std::vector<boost::shared_ptr<Source> > SourceList;
389
390         enum SrcQuality {
391                 SrcBest,
392                 SrcGood,
393                 SrcQuick,
394                 SrcFast,
395                 SrcFastest
396         };
397
398         struct TimeFXRequest : public InterThreadInfo {
399                 TimeFXRequest() : time_fraction(0), pitch_fraction(0),
400                         quick_seek(false), antialias(false),  opts(0) {}
401             float time_fraction;
402             float pitch_fraction;
403             /* SoundTouch */
404             bool  quick_seek; 
405             bool  antialias;  
406             /* RubberBand */
407             int   opts; // really RubberBandStretcher::Options
408         };
409
410         typedef std::list<nframes64_t> AnalysisFeatureList;
411
412 } // namespace ARDOUR
413
414 std::istream& operator>>(std::istream& o, ARDOUR::SampleFormat& sf);
415 std::istream& operator>>(std::istream& o, ARDOUR::HeaderFormat& sf);
416 std::istream& operator>>(std::istream& o, ARDOUR::AutoConnectOption& sf);
417 std::istream& operator>>(std::istream& o, ARDOUR::EditMode& sf);
418 std::istream& operator>>(std::istream& o, ARDOUR::MonitorModel& sf);
419 std::istream& operator>>(std::istream& o, ARDOUR::RemoteModel& sf);
420 std::istream& operator>>(std::istream& o, ARDOUR::SoloModel& sf);
421 std::istream& operator>>(std::istream& o, ARDOUR::LayerModel& sf);
422 std::istream& operator>>(std::istream& o, ARDOUR::CrossfadeModel& sf);
423 std::istream& operator>>(std::istream& o, ARDOUR::SlaveSource& sf);
424 std::istream& operator>>(std::istream& o, ARDOUR::ShuttleBehaviour& sf);
425 std::istream& operator>>(std::istream& o, ARDOUR::ShuttleUnits& sf);
426 std::istream& operator>>(std::istream& o, ARDOUR::SmpteFormat& sf);
427 std::istream& operator>>(std::istream& o, ARDOUR::DenormalModel& sf);
428
429 using ARDOUR::nframes_t;
430
431 static inline nframes_t
432 session_frame_to_track_frame (nframes_t session_frame, double speed)
433 {
434         return (nframes_t)( (double)session_frame * speed );
435 }
436
437 static inline nframes_t
438 track_frame_to_session_frame (nframes_t track_frame, double speed)
439 {
440         return (nframes_t)( (double)track_frame / speed );
441 }
442
443
444 #endif /* __ardour_types_h__ */
445