add AudioBackendNativeThread to serve the same role as jack_native_thread_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 */
19
20 #ifndef __ardour_types_h__
21 #define __ardour_types_h__
22
23 #include <istream>
24 #include <vector>
25 #include <map>
26 #include <boost/shared_ptr.hpp>
27 #include <sys/types.h>
28 #include <stdint.h>
29 #include <pthread.h>
30
31 #include <inttypes.h>
32
33 #include "timecode/bbt_time.h"
34 #include "timecode/time.h"
35
36 #include "pbd/id.h"
37
38 #include "evoral/Range.hpp"
39
40 #include "ardour/chan_count.h"
41
42 #include <map>
43
44 #if __GNUC__ < 3
45 typedef int intptr_t;
46 #endif
47
48 namespace ARDOUR {
49
50         class Source;
51         class AudioSource;
52         class Route;
53         class Region;
54
55         typedef float    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 pframes_t;
61
62         /* Any position measured in audio frames.
63            Assumed to be non-negative but not enforced.
64         */
65         typedef int64_t framepos_t;
66
67         /* Any distance from a given framepos_t.
68            Maybe positive or negative.
69         */
70         typedef int64_t frameoffset_t;
71
72         /* Any count of audio frames.
73            Assumed to be positive but not enforced.
74         */
75         typedef int64_t framecnt_t;
76
77         static const framepos_t max_framepos = INT64_MAX;
78         static const framecnt_t max_framecnt = INT64_MAX;
79         static const layer_t    max_layer    = UINT32_MAX;
80
81         // a set of (time) intervals: first of pair is the offset of the start within the region, second is the offset of the end
82         typedef std::list<std::pair<frameoffset_t, frameoffset_t> > AudioIntervalResult;
83         // associate a set of intervals with regions (e.g. for silence detection)
84         typedef std::map<boost::shared_ptr<ARDOUR::Region>,AudioIntervalResult> AudioIntervalMap;
85
86         typedef std::list<boost::shared_ptr<Region> > RegionList;
87
88         struct IOChange {
89
90                 enum Type {
91                         NoChange = 0,
92                         ConfigurationChanged = 0x1,
93                         ConnectionsChanged = 0x2
94                 } type;
95
96                 IOChange () : type (NoChange) {}
97                 IOChange (Type t) : type (t) {}
98
99                 /** channel count of IO before a ConfigurationChanged, if appropriate */
100                 ARDOUR::ChanCount before;
101                 /** channel count of IO after a ConfigurationChanged, if appropriate */
102                 ARDOUR::ChanCount after;
103         };
104
105         /* policies for inserting/pasting material where overlaps
106            might be an issue.
107         */
108
109         enum InsertMergePolicy {
110                 InsertMergeReject,  // no overlaps allowed
111                 InsertMergeRelax,   // we just don't care about overlaps
112                 InsertMergeReplace, // replace old with new
113                 InsertMergeTruncateExisting, // shorten existing to avoid overlap
114                 InsertMergeTruncateAddition, // shorten new to avoid overlap
115                 InsertMergeExtend   // extend new (or old) to the range of old+new
116         };
117
118         /** See evoral/Parameter.hpp
119          */
120         enum AutomationType {
121                 NullAutomation,
122                 GainAutomation,
123                 PanAzimuthAutomation,
124                 PanElevationAutomation,
125                 PanWidthAutomation,
126                 PanFrontBackAutomation,
127                 PanLFEAutomation,
128                 PluginAutomation,
129                 SoloAutomation,
130                 MuteAutomation,
131                 MidiCCAutomation,
132                 MidiPgmChangeAutomation,
133                 MidiPitchBenderAutomation,
134                 MidiChannelPressureAutomation,
135                 MidiSystemExclusiveAutomation,
136                 FadeInAutomation,
137                 FadeOutAutomation,
138                 EnvelopeAutomation,
139                 RecEnableAutomation
140         };
141
142         enum AutoState {
143                 Off = 0x0,
144                 Write = 0x1,
145                 Touch = 0x2,
146                 Play = 0x4
147         };
148
149         std::string auto_state_to_string (AutoState);
150         AutoState string_to_auto_state (std::string);
151
152         enum AutoStyle {
153                 Absolute = 0x1,
154                 Trim = 0x2
155         };
156
157         std::string auto_style_to_string (AutoStyle);
158         AutoStyle string_to_auto_style (std::string);
159
160         enum AlignStyle {
161                 CaptureTime,
162                 ExistingMaterial
163         };
164
165         enum AlignChoice {
166                 UseCaptureTime,
167                 UseExistingMaterial,
168                 Automatic
169         };
170
171         enum MeterPoint {
172                 MeterInput,
173                 MeterPreFader,
174                 MeterPostFader,
175                 MeterOutput,
176                 MeterCustom
177         };
178
179         enum MeterType {
180                 MeterMaxSignal = 0x001,
181                 MeterMaxPeak   = 0x002,
182                 MeterPeak      = 0x004,
183                 MeterKrms      = 0x008,
184                 MeterK20       = 0x010,
185                 MeterK14       = 0x020,
186                 MeterIEC1DIN   = 0x040,
187                 MeterIEC1NOR   = 0x080,
188                 MeterIEC2BBC   = 0x100,
189                 MeterIEC2EBU   = 0x200,
190                 MeterVU        = 0x400
191         };
192
193         enum TrackMode {
194                 Normal,
195                 NonLayered,
196                 Destructive
197         };
198
199         enum NoteMode {
200                 Sustained,
201                 Percussive
202         };
203
204         enum ChannelMode {
205                 AllChannels = 0, ///< Pass through all channel information unmodified
206                 FilterChannels,  ///< Ignore events on certain channels
207                 ForceChannel     ///< Force all events to a certain channel
208         };
209
210         enum ColorMode {
211                 MeterColors = 0,
212                 ChannelColors,
213                 TrackColor
214         };
215
216         class AnyTime {
217         public:
218                 enum Type {
219                         Timecode,
220                         BBT,
221                         Frames,
222                         Seconds
223                 };
224
225                 Type type;
226
227                 Timecode::Time     timecode;
228                 Timecode::BBT_Time bbt;
229
230                 union {
231                         framecnt_t     frames;
232                         double         seconds;
233                 };
234
235                 AnyTime() { type = Frames; frames = 0; }
236
237                 bool operator== (AnyTime const & other) const {
238                         if (type != other.type) { return false; }
239
240                         switch (type) {
241                           case Timecode:
242                                 return timecode == other.timecode;
243                           case BBT:
244                                 return bbt == other.bbt;
245                           case Frames:
246                                 return frames == other.frames;
247                           case Seconds:
248                                 return seconds == other.seconds;
249                         }
250                         return false; // get rid of warning
251                 }
252
253                 bool not_zero() const
254                 {
255                         switch (type) {
256                           case Timecode:
257                                 return timecode.hours != 0 || timecode.minutes != 0 ||
258                                        timecode.seconds != 0 || timecode.frames != 0;
259                           case BBT:
260                                 return bbt.bars != 0 || bbt.beats != 0 || bbt.ticks != 0;
261                           case Frames:
262                                 return frames != 0;
263                           case Seconds:
264                                 return seconds != 0;
265                         }
266
267                         /* NOTREACHED */
268                         assert (false);
269                         return false;
270                 }
271         };
272
273         /* XXX: slightly unfortunate that there is this and Evoral::Range<>,
274            but this has a uint32_t id which Evoral::Range<> does not.
275         */
276         struct AudioRange {
277                 framepos_t start;
278                 framepos_t end;
279                 uint32_t id;
280
281                 AudioRange (framepos_t s, framepos_t e, uint32_t i) : start (s), end (e) , id (i) {}
282
283                 framecnt_t length() { return end - start + 1; }
284
285                 bool operator== (const AudioRange& other) const {
286                         return start == other.start && end == other.end && id == other.id;
287                 }
288
289                 bool equal (const AudioRange& other) const {
290                         return start == other.start && end == other.end;
291                 }
292
293                 Evoral::OverlapType coverage (framepos_t s, framepos_t e) const {
294                         return Evoral::coverage (start, end, s, e);
295                 }
296         };
297
298         struct MusicRange {
299                 Timecode::BBT_Time start;
300                 Timecode::BBT_Time end;
301                 uint32_t id;
302
303                 MusicRange (Timecode::BBT_Time& s, Timecode::BBT_Time& e, uint32_t i)
304                         : start (s), end (e), id (i) {}
305
306                 bool operator== (const MusicRange& other) const {
307                         return start == other.start && end == other.end && id == other.id;
308                 }
309
310                 bool equal (const MusicRange& other) const {
311                         return start == other.start && end == other.end;
312                 }
313         };
314
315         /*
316             Slowest = 6.6dB/sec falloff at update rate of 40ms
317             Slow    = 6.8dB/sec falloff at update rate of 40ms
318         */
319
320         enum MeterFalloff {
321                 MeterFalloffOff = 0,
322                 MeterFalloffSlowest = 1,
323                 MeterFalloffSlow = 2,
324                 MeterFalloffSlowish = 3,
325                 MeterFalloffModerate = 4,
326                 MeterFalloffMedium = 5,
327                 MeterFalloffFast = 6,
328                 MeterFalloffFaster = 7,
329                 MeterFalloffFastest = 8,
330         };
331
332         enum MeterHold {
333                 MeterHoldOff = 0,
334                 MeterHoldShort = 40,
335                 MeterHoldMedium = 100,
336                 MeterHoldLong = 200
337         };
338
339         enum EditMode {
340                 Slide,
341                 Splice,
342                 Lock
343         };
344
345         enum RegionPoint {
346                 Start,
347                 End,
348                 SyncPoint
349         };
350
351         enum Placement {
352                 PreFader,
353                 PostFader
354         };
355
356         enum RouteSortOrderKey { 
357                 EditorSort,
358                 MixerSort
359         };
360             
361         enum MonitorModel {
362                 HardwareMonitoring, ///< JACK does monitoring
363                 SoftwareMonitoring, ///< Ardour does monitoring
364                 ExternalMonitoring  ///< we leave monitoring to the audio hardware
365         };
366
367         enum MonitorChoice {
368                 MonitorAuto = 0,
369                 MonitorInput = 0x1,
370                 MonitorDisk = 0x2,
371                 MonitorCue = 0x4,
372         };
373
374         enum MonitorState {
375                 MonitoringSilence = 0x1,
376                 MonitoringInput = 0x2,
377                 MonitoringDisk = 0x4,
378         };
379
380         enum MeterState {
381                 MeteringInput, ///< meter the input IO, regardless of what is going through the route
382                 MeteringRoute  ///< meter what is going through the route
383         };
384
385         enum VUMeterStandard {
386                 MeteringVUfrench,   // 0VU = -2dBu
387                 MeteringVUamerican, // 0VU =  0dBu
388                 MeteringVUstandard, // 0VU = +4dBu
389                 MeteringVUeight     // 0VU = +8dBu
390         };
391
392         enum MeterLineUp {
393                 MeteringLineUp24,
394                 MeteringLineUp20,
395                 MeteringLineUp18,
396                 MeteringLineUp15
397         };
398
399         enum PFLPosition {
400                 /** PFL signals come from before pre-fader processors */
401                 PFLFromBeforeProcessors,
402                 /** PFL signals come pre-fader but after pre-fader processors */
403                 PFLFromAfterProcessors
404         };
405
406         enum AFLPosition {
407                 /** AFL signals come post-fader and before post-fader processors */
408                 AFLFromBeforeProcessors,
409                 /** AFL signals come post-fader but after post-fader processors */
410                 AFLFromAfterProcessors
411         };
412
413         enum DenormalModel {
414                 DenormalNone,
415                 DenormalFTZ,
416                 DenormalDAZ,
417                 DenormalFTZDAZ
418         };
419
420         enum RemoteModel {
421                 UserOrdered,
422                 MixerOrdered,
423                 EditorOrdered
424         };
425
426         enum CrossfadeModel {
427                 FullCrossfade,
428                 ShortCrossfade
429         };
430
431         enum CrossfadeChoice {
432                 RegionFades,
433                 ConstantPowerMinus3dB,
434                 ConstantPowerMinus6dB,
435         };
436
437         enum ListenPosition {
438                 AfterFaderListen,
439                 PreFaderListen
440         };
441
442         enum AutoConnectOption {
443                 ManualConnect = 0x0,
444                 AutoConnectPhysical = 0x1,
445                 AutoConnectMaster = 0x2
446         };
447
448         enum SampleFormat {
449                 FormatFloat = 0,
450                 FormatInt24,
451                 FormatInt16
452         };
453
454         enum CDMarkerFormat {
455                 CDMarkerNone,
456                 CDMarkerCUE,
457                 CDMarkerTOC
458         };
459
460         enum HeaderFormat {
461                 BWF,
462                 WAVE,
463                 WAVE64,
464                 CAF,
465                 AIFF,
466                 iXML,
467                 RF64
468         };
469
470         struct PeakData {
471                 typedef Sample PeakDatum;
472
473                 PeakDatum min;
474                 PeakDatum max;
475         };
476
477         enum PluginType {
478                 AudioUnit,
479                 LADSPA,
480                 LV2,
481                 Windows_VST,
482                 LXVST,
483         };
484
485         enum RunContext {
486                 ButlerContext = 0,
487                 TransportContext,
488                 ExportContext
489         };
490
491         enum SyncSource {
492                 JACK,
493                 MTC,
494                 MIDIClock,
495                 LTC
496         };
497
498         enum ShuttleBehaviour {
499                 Sprung,
500                 Wheel
501         };
502
503         enum ShuttleUnits {
504                 Percentage,
505                 Semitones
506         };
507
508         typedef std::vector<boost::shared_ptr<Source> > SourceList;
509
510         enum SrcQuality {
511                 SrcBest,
512                 SrcGood,
513                 SrcQuick,
514                 SrcFast,
515                 SrcFastest
516         };
517
518         typedef std::list<framepos_t> AnalysisFeatureList;
519
520         typedef std::list<boost::shared_ptr<Route> > RouteList;
521         typedef std::list<boost::weak_ptr  <Route> > WeakRouteList;
522
523         class Bundle;
524         typedef std::vector<boost::shared_ptr<Bundle> > BundleList;
525
526         enum WaveformScale {
527                 Linear,
528                 Logarithmic
529         };
530
531         enum WaveformShape {
532                 Traditional,
533                 Rectified
534         };
535
536         struct CleanupReport {
537                 std::vector<std::string> paths;
538                 size_t                   space;
539         };
540
541         enum PositionLockStyle {
542                 AudioTime,
543                 MusicTime
544         };
545
546         /** A struct used to describe changes to processors in a route.
547          *  This is useful because objects that respond to a change in processors
548          *  can optimise what work they do based on details of what has changed.
549         */
550         struct RouteProcessorChange {
551                 enum Type {
552                         GeneralChange = 0x0,
553                         MeterPointChange = 0x1
554                 };
555
556                 RouteProcessorChange () : type (GeneralChange), meter_visibly_changed (true)
557                 {}
558
559                 RouteProcessorChange (Type t) : type (t), meter_visibly_changed (true)
560                 {}
561
562                 RouteProcessorChange (Type t, bool m) : type (t), meter_visibly_changed (m)
563                 {}
564
565                 /** type of change; "GeneralChange" means anything could have changed */
566                 Type type;
567                 /** true if, when a MeterPointChange has occurred, the change is visible to the user */
568                 bool meter_visibly_changed;
569         };
570
571         struct BusProfile {
572                 AutoConnectOption input_ac;      /* override the RC config for input auto-connection */
573                 AutoConnectOption output_ac;     /* override the RC config for output auto-connection */
574                 uint32_t master_out_channels;    /* how many channels for the master bus */
575                 uint32_t requested_physical_in;  /* now many of the available physical inputs to consider usable */
576                 uint32_t requested_physical_out; /* now many of the available physical inputs to consider usable */
577         };
578
579         enum FadeShape {
580                 FadeLinear,
581                 FadeFast,
582                 FadeSlow,
583                 FadeConstantPower,
584                 FadeSymmetric,
585         };
586
587         enum TransportState {
588                 /* these values happen to match the constants used by JACK but
589                    this equality cannot be assumed.
590                 */
591                 TransportStopped = 0,
592                 TransportRolling = 1, 
593                 TransportLooping = 2, 
594                 TransportStarting = 3,
595         };
596
597         enum PortFlags {
598                 /* these values happen to match the constants used by JACK but
599                    this equality cannot be assumed.
600                 */
601                 IsInput = 0x1, 
602                 IsOutput = 0x2,
603                 IsPhysical = 0x4,
604                 CanMonitor = 0x8,
605                 IsTerminal = 0x10
606         };
607
608         struct LatencyRange {
609             uint32_t min; //< samples
610             uint32_t max; //< samples
611         };
612
613 /* PLATFORM SPECIFIC #ifdef's here */
614
615         /** Define the native thread type used on the platform */
616         typedef pthread_t AudioBackendNativeThread;
617         static inline bool self_thread_equal (AudioBackendNativeThread thr) {
618                 return pthread_equal (thr, pthread_self());
619         }
620
621 /* PLATFORM SPECIFIC #endif's here */
622
623 } // namespace ARDOUR
624
625
626 /* these cover types declared above in this header. See enums.cc
627    for the definitions.
628 */
629
630 std::istream& operator>>(std::istream& o, ARDOUR::SampleFormat& sf);
631 std::istream& operator>>(std::istream& o, ARDOUR::HeaderFormat& sf);
632 std::istream& operator>>(std::istream& o, ARDOUR::AutoConnectOption& sf);
633 std::istream& operator>>(std::istream& o, ARDOUR::EditMode& sf);
634 std::istream& operator>>(std::istream& o, ARDOUR::MonitorModel& sf);
635 std::istream& operator>>(std::istream& o, ARDOUR::VUMeterStandard& sf);
636 std::istream& operator>>(std::istream& o, ARDOUR::MeterLineUp& sf);
637 std::istream& operator>>(std::istream& o, ARDOUR::PFLPosition& sf);
638 std::istream& operator>>(std::istream& o, ARDOUR::AFLPosition& sf);
639 std::istream& operator>>(std::istream& o, ARDOUR::RemoteModel& sf);
640 std::istream& operator>>(std::istream& o, ARDOUR::ListenPosition& sf);
641 std::istream& operator>>(std::istream& o, ARDOUR::InsertMergePolicy& sf);
642 std::istream& operator>>(std::istream& o, ARDOUR::CrossfadeModel& sf);
643 std::istream& operator>>(std::istream& o, ARDOUR::CrossfadeChoice& sf);
644 std::istream& operator>>(std::istream& o, ARDOUR::SyncSource& sf);
645 std::istream& operator>>(std::istream& o, ARDOUR::ShuttleBehaviour& sf);
646 std::istream& operator>>(std::istream& o, ARDOUR::ShuttleUnits& sf);
647 std::istream& operator>>(std::istream& o, Timecode::TimecodeFormat& sf);
648 std::istream& operator>>(std::istream& o, ARDOUR::DenormalModel& sf);
649 std::istream& operator>>(std::istream& o, ARDOUR::WaveformScale& sf);
650 std::istream& operator>>(std::istream& o, ARDOUR::WaveformShape& sf);
651 std::istream& operator>>(std::istream& o, ARDOUR::PositionLockStyle& sf);
652
653 std::ostream& operator<<(std::ostream& o, const ARDOUR::SampleFormat& sf);
654 std::ostream& operator<<(std::ostream& o, const ARDOUR::HeaderFormat& sf);
655 std::ostream& operator<<(std::ostream& o, const ARDOUR::AutoConnectOption& sf);
656 std::ostream& operator<<(std::ostream& o, const ARDOUR::EditMode& sf);
657 std::ostream& operator<<(std::ostream& o, const ARDOUR::MonitorModel& sf);
658 std::ostream& operator<<(std::ostream& o, const ARDOUR::VUMeterStandard& sf);
659 std::ostream& operator<<(std::ostream& o, const ARDOUR::MeterLineUp& sf);
660 std::ostream& operator<<(std::ostream& o, const ARDOUR::PFLPosition& sf);
661 std::ostream& operator<<(std::ostream& o, const ARDOUR::AFLPosition& sf);
662 std::ostream& operator<<(std::ostream& o, const ARDOUR::RemoteModel& sf);
663 std::ostream& operator<<(std::ostream& o, const ARDOUR::ListenPosition& sf);
664 std::ostream& operator<<(std::ostream& o, const ARDOUR::InsertMergePolicy& sf);
665 std::ostream& operator<<(std::ostream& o, const ARDOUR::CrossfadeModel& sf);
666 std::ostream& operator<<(std::ostream& o, const ARDOUR::CrossfadeChoice& sf);
667 std::ostream& operator<<(std::ostream& o, const ARDOUR::SyncSource& sf);
668 std::ostream& operator<<(std::ostream& o, const ARDOUR::ShuttleBehaviour& sf);
669 std::ostream& operator<<(std::ostream& o, const ARDOUR::ShuttleUnits& sf);
670 std::ostream& operator<<(std::ostream& o, const Timecode::TimecodeFormat& sf);
671 std::ostream& operator<<(std::ostream& o, const ARDOUR::DenormalModel& sf);
672 std::ostream& operator<<(std::ostream& o, const ARDOUR::WaveformScale& sf);
673 std::ostream& operator<<(std::ostream& o, const ARDOUR::WaveformShape& sf);
674 std::ostream& operator<<(std::ostream& o, const ARDOUR::PositionLockStyle& sf);
675
676 static inline ARDOUR::framepos_t
677 session_frame_to_track_frame (ARDOUR::framepos_t session_frame, double speed)
678 {
679         return (ARDOUR::framepos_t) ((long double) session_frame * (long double) speed);
680 }
681
682 static inline ARDOUR::framepos_t
683 track_frame_to_session_frame (ARDOUR::framepos_t track_frame, double speed)
684 {
685         return (ARDOUR::framepos_t) ((long double) track_frame / (long double) speed);
686 }
687
688 /* for now, break the rules and use "using" to make this "global" */
689
690 using ARDOUR::framepos_t;
691
692
693 #endif /* __ardour_types_h__ */
694