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