352c20ae9bdf55dccc27b46f0c2a4fe04990f202
[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 <set>
27 #include <boost/shared_ptr.hpp>
28 #include <sys/types.h>
29 #include <stdint.h>
30 #include <pthread.h>
31
32 #include <inttypes.h>
33
34 #include "temporal/bbt_time.h"
35 #include "temporal/time.h"
36 #include "temporal/types.h"
37
38 #include "pbd/id.h"
39
40 #include "evoral/Range.hpp"
41
42 #include "ardour/chan_count.h"
43 #include "ardour/plugin_types.h"
44
45 #include <map>
46
47 using Temporal::max_samplepos;
48 using Temporal::max_samplecnt;
49
50 #if __GNUC__ < 3
51 typedef int intptr_t;
52 #endif
53
54 namespace ARDOUR {
55
56         class Source;
57         class AudioSource;
58         class Route;
59         class Region;
60         class Stripable;
61         class VCA;
62         class AutomationControl;
63         class SlavableAutomationControl;
64
65         typedef float    Sample;
66         typedef float    pan_t;
67         typedef float    gain_t;
68         typedef uint32_t layer_t;
69         typedef uint64_t microseconds_t;
70         typedef uint32_t pframes_t;
71
72         /* rebind Temporal position types into ARDOUR namespace */
73         typedef Temporal::samplecnt_t samplecnt_t;
74         typedef Temporal::samplepos_t samplepos_t;
75         typedef Temporal::sampleoffset_t sampleoffset_t;
76
77         static const layer_t    max_layer    = UINT32_MAX;
78
79         // a set of (time) intervals: first of pair is the offset of the start within the region, second is the offset of the end
80         typedef std::list<std::pair<sampleoffset_t, sampleoffset_t> > AudioIntervalResult;
81         // associate a set of intervals with regions (e.g. for silence detection)
82         typedef std::map<boost::shared_ptr<ARDOUR::Region>,AudioIntervalResult> AudioIntervalMap;
83
84         typedef std::list<boost::shared_ptr<Region> > RegionList;
85
86         struct IOChange {
87
88                 enum Type {
89                         NoChange = 0,
90                         ConfigurationChanged = 0x1,
91                         ConnectionsChanged = 0x2
92                 } type;
93
94                 IOChange () : type (NoChange) {}
95                 IOChange (Type t) : type (t) {}
96
97                 /** channel count of IO before a ConfigurationChanged, if appropriate */
98                 ARDOUR::ChanCount before;
99                 /** channel count of IO after a ConfigurationChanged, if appropriate */
100                 ARDOUR::ChanCount after;
101         };
102
103         /* policies for inserting/pasting material where overlaps
104            might be an issue.
105         */
106
107         enum InsertMergePolicy {
108                 InsertMergeReject,  ///< no overlaps allowed
109                 InsertMergeRelax,   ///< we just don't care about overlaps
110                 InsertMergeReplace, ///< replace old with new
111                 InsertMergeTruncateExisting, ///< shorten existing to avoid overlap
112                 InsertMergeTruncateAddition, ///< shorten new to avoid overlap
113                 InsertMergeExtend   ///< extend new (or old) to the range of old+new
114         };
115
116         /** See evoral/Parameter.hpp
117          *
118          * When you add things here, you REALLY SHOULD add a case clause to
119          * the constructor of ParameterDescriptor, unless the Controllables
120          * that the enum refers to are completely standard (0-1.0 range, 0.0 as
121          * normal, non-toggled, non-enumerated). Anything else needs to be
122          * added there so that things that try to represent them can do so
123          * with as much information as possible.
124          */
125         enum AutomationType {
126                 NullAutomation,
127                 GainAutomation,
128                 PanAzimuthAutomation,
129                 PanElevationAutomation,
130                 PanWidthAutomation,
131                 PanFrontBackAutomation,
132                 PanLFEAutomation,
133                 PluginAutomation,
134                 PluginPropertyAutomation,
135                 SoloAutomation,
136                 SoloIsolateAutomation,
137                 SoloSafeAutomation,
138                 MuteAutomation,
139                 MidiCCAutomation,
140                 MidiPgmChangeAutomation,
141                 MidiPitchBenderAutomation,
142                 MidiChannelPressureAutomation,
143                 MidiNotePressureAutomation,
144                 MidiSystemExclusiveAutomation,
145                 FadeInAutomation,
146                 FadeOutAutomation,
147                 EnvelopeAutomation,
148                 RecEnableAutomation,
149                 RecSafeAutomation,
150                 TrimAutomation,
151                 PhaseAutomation,
152                 MonitoringAutomation,
153                 BusSendLevel,
154                 BusSendEnable
155         };
156
157         enum AutoState {
158                 Off   = 0x00,
159                 Write = 0x01,
160                 Touch = 0x02,
161                 Play  = 0x04,
162                 Latch = 0x08
163         };
164
165         std::string auto_state_to_string (AutoState);
166         AutoState string_to_auto_state (std::string);
167
168         enum AlignStyle {
169                 CaptureTime,
170                 ExistingMaterial
171         };
172
173         enum AlignChoice {
174                 UseCaptureTime,
175                 UseExistingMaterial,
176                 Automatic
177         };
178
179         enum MeterPoint {
180                 MeterInput,
181                 MeterPreFader,
182                 MeterPostFader,
183                 MeterOutput,
184                 MeterCustom
185         };
186
187         enum DiskIOPoint {
188                 DiskIOPreFader,  /* after the trim control, but before other processors */
189                 DiskIOPostFader, /* before the main outs, after other processors */
190                 DiskIOCustom,   /* up to the user. Caveat Emptor! */
191         };
192
193         enum MeterType {
194                 MeterMaxSignal = 0x0001,
195                 MeterMaxPeak   = 0x0002,
196                 MeterPeak      = 0x0004,
197                 MeterKrms      = 0x0008,
198                 MeterK20       = 0x0010,
199                 MeterK14       = 0x0020,
200                 MeterIEC1DIN   = 0x0040,
201                 MeterIEC1NOR   = 0x0080,
202                 MeterIEC2BBC   = 0x0100,
203                 MeterIEC2EBU   = 0x0200,
204                 MeterVU        = 0x0400,
205                 MeterK12       = 0x0800,
206                 MeterPeak0dB   = 0x1000,
207                 MeterMCP       = 0x2000
208         };
209
210         enum TrackMode {
211                 Normal,
212                 NonLayered,
213                 Destructive
214         };
215
216         enum NoteMode {
217                 Sustained,
218                 Percussive
219         };
220
221         enum ChannelMode {
222                 AllChannels = 0, ///< Pass through all channel information unmodified
223                 FilterChannels,  ///< Ignore events on certain channels
224                 ForceChannel     ///< Force all events to a certain channel
225         };
226
227         enum ColorMode {
228                 MeterColors = 0,
229                 ChannelColors,
230                 TrackColor
231         };
232
233         enum RoundMode {
234                 RoundDownMaybe  = -2,  ///< Round down only if necessary
235                 RoundDownAlways = -1,  ///< Always round down, even if on a division
236                 RoundNearest    = 0,   ///< Round to nearest
237                 RoundUpAlways   = 1,   ///< Always round up, even if on a division
238                 RoundUpMaybe    = 2    ///< Round up only if necessary
239         };
240
241         enum SnapPref {
242                 SnapToAny    = 0,   ///< Snaps to the closest of ( snap prefs, grid quantization )
243                 SnapToGrid   = 1,   ///< Prefer snapping to the closest grid quantization, if a Grid selection is enabled
244         };
245
246         class AnyTime {
247         public:
248                 enum Type {
249                         Timecode,
250                         BBT,
251                         Samples,
252                         Seconds
253                 };
254
255                 Type type;
256
257                 Timecode::Time     timecode;
258                 Timecode::BBT_Time bbt;
259
260                 union {
261                         samplecnt_t     samples;
262                         double         seconds;
263                 };
264
265                 AnyTime() { type = Samples; samples = 0; }
266
267                 bool operator== (AnyTime const & other) const {
268                         if (type != other.type) { return false; }
269
270                         switch (type) {
271                           case Timecode:
272                                 return timecode == other.timecode;
273                           case BBT:
274                                 return bbt == other.bbt;
275                           case Samples:
276                                 return samples == other.samples;
277                           case Seconds:
278                                 return seconds == other.seconds;
279                         }
280                         return false; // get rid of warning
281                 }
282
283                 bool not_zero() const
284                 {
285                         switch (type) {
286                           case Timecode:
287                                 return timecode.hours != 0 || timecode.minutes != 0 ||
288                                        timecode.seconds != 0 || timecode.frames != 0;
289                           case BBT:
290                                 return bbt.bars != 0 || bbt.beats != 0 || bbt.ticks != 0;
291                           case Samples:
292                                 return samples != 0;
293                           case Seconds:
294                                 return seconds != 0;
295                         }
296
297                         abort(); /* NOTREACHED */
298                         return false;
299                 }
300         };
301
302         /* used for translating audio samples to an exact musical position using a note divisor.
303            an exact musical position almost never falls exactly on an audio sample, but for sub-sample
304            musical accuracy we need to derive exact musical locations from a sample position
305            the division follows TempoMap::exact_beat_at_sample().
306            division
307            -1       musical location is the bar closest to sample
308             0       musical location is the musical position of the sample
309             1       musical location is the BBT beat closest to sample
310             n       musical location is the quarter-note division n closest to sample
311         */
312         struct MusicSample {
313                 samplepos_t sample;
314                 int32_t    division;
315
316                 MusicSample (samplepos_t f, int32_t d) : sample (f), division (d) {}
317
318                 void set (samplepos_t f, int32_t d) {sample = f; division = d; }
319
320                 MusicSample operator- (MusicSample other) { return MusicSample (sample - other.sample, 0); }
321         };
322
323         /* XXX: slightly unfortunate that there is this and Evoral::Range<>,
324            but this has a uint32_t id which Evoral::Range<> does not.
325         */
326         struct AudioRange {
327                 samplepos_t start;
328                 samplepos_t end;
329                 uint32_t id;
330
331                 AudioRange (samplepos_t s, samplepos_t e, uint32_t i) : start (s), end (e) , id (i) {}
332
333                 samplecnt_t length() const { return end - start + 1; }
334
335                 bool operator== (const AudioRange& other) const {
336                         return start == other.start && end == other.end && id == other.id;
337                 }
338
339                 bool equal (const AudioRange& other) const {
340                         return start == other.start && end == other.end;
341                 }
342
343                 Evoral::OverlapType coverage (samplepos_t s, samplepos_t e) const {
344                         return Evoral::coverage (start, end, s, e);
345                 }
346         };
347
348         struct MusicRange {
349                 Timecode::BBT_Time start;
350                 Timecode::BBT_Time end;
351                 uint32_t id;
352
353                 MusicRange (Timecode::BBT_Time& s, Timecode::BBT_Time& e, uint32_t i)
354                         : start (s), end (e), id (i) {}
355
356                 bool operator== (const MusicRange& other) const {
357                         return start == other.start && end == other.end && id == other.id;
358                 }
359
360                 bool equal (const MusicRange& other) const {
361                         return start == other.start && end == other.end;
362                 }
363         };
364
365         /*
366             Slowest = 6.6dB/sec falloff at update rate of 40ms
367             Slow    = 6.8dB/sec falloff at update rate of 40ms
368         */
369
370         enum MeterFalloff {
371                 MeterFalloffOff = 0,
372                 MeterFalloffSlowest = 1,
373                 MeterFalloffSlow = 2,
374                 MeterFalloffSlowish = 3,
375                 MeterFalloffModerate = 4,
376                 MeterFalloffMedium = 5,
377                 MeterFalloffFast = 6,
378                 MeterFalloffFaster = 7,
379                 MeterFalloffFastest = 8,
380         };
381
382         enum MeterHold {
383                 MeterHoldOff = 0,
384                 MeterHoldShort = 40,
385                 MeterHoldMedium = 100,
386                 MeterHoldLong = 200
387         };
388
389         enum EditMode {
390                 Slide,
391                 Splice,
392                 Ripple,
393                 Lock
394         };
395
396         enum RegionSelectionAfterSplit {
397                 None = 0,
398                 NewlyCreatedLeft = 1,  // bit 0
399                 NewlyCreatedRight = 2, // bit 1
400                 NewlyCreatedBoth = 3,
401                 Existing = 4,          // bit 2
402                 ExistingNewlyCreatedLeft = 5,
403                 ExistingNewlyCreatedRight = 6,
404                 ExistingNewlyCreatedBoth = 7
405         };
406
407         enum RegionPoint {
408                 Start,
409                 End,
410                 SyncPoint
411         };
412
413         enum Placement {
414                 PreFader,
415                 PostFader
416         };
417
418         enum MonitorModel {
419                 HardwareMonitoring, ///< JACK does monitoring
420                 SoftwareMonitoring, ///< Ardour does monitoring
421                 ExternalMonitoring  ///< we leave monitoring to the audio hardware
422         };
423
424         enum MonitorChoice {
425                 MonitorAuto = 0,
426                 MonitorInput = 0x1,
427                 MonitorDisk = 0x2,
428                 MonitorCue = 0x4,
429         };
430
431         enum MonitorState {
432                 MonitoringSilence = 0x1,
433                 MonitoringInput = 0x2,
434                 MonitoringDisk = 0x4,
435         };
436
437         enum MeterState {
438                 MeteringInput, ///< meter the input IO, regardless of what is going through the route
439                 MeteringRoute  ///< meter what is going through the route
440         };
441
442         enum VUMeterStandard {
443                 MeteringVUfrench,   // 0VU = -2dBu
444                 MeteringVUamerican, // 0VU =  0dBu
445                 MeteringVUstandard, // 0VU = +4dBu
446                 MeteringVUeight     // 0VU = +8dBu
447         };
448
449         enum MeterLineUp {
450                 MeteringLineUp24,
451                 MeteringLineUp20,
452                 MeteringLineUp18,
453                 MeteringLineUp15
454         };
455
456         enum PFLPosition {
457                 /** PFL signals come from before pre-fader processors */
458                 PFLFromBeforeProcessors,
459                 /** PFL signals come pre-fader but after pre-fader processors */
460                 PFLFromAfterProcessors
461         };
462
463         enum AFLPosition {
464                 /** AFL signals come post-fader and before post-fader processors */
465                 AFLFromBeforeProcessors,
466                 /** AFL signals come post-fader but after post-fader processors */
467                 AFLFromAfterProcessors
468         };
469
470         enum ClockDeltaMode {
471                 NoDelta,
472                 DeltaEditPoint,
473                 DeltaOriginMarker
474         };
475
476         enum DenormalModel {
477                 DenormalNone,
478                 DenormalFTZ,
479                 DenormalDAZ,
480                 DenormalFTZDAZ
481         };
482
483         enum LayerModel {
484                 LaterHigher,
485                 Manual
486         };
487
488         enum ListenPosition {
489                 AfterFaderListen,
490                 PreFaderListen
491         };
492
493         enum AutoConnectOption {
494                 ManualConnect = 0x0,
495                 AutoConnectPhysical = 0x1,
496                 AutoConnectMaster = 0x2
497         };
498
499     enum TracksAutoNamingRule {
500         UseDefaultNames = 0x1,
501         NameAfterDriver = 0x2
502     };
503
504         enum SampleFormat {
505                 FormatFloat = 0,
506                 FormatInt24,
507                 FormatInt16
508         };
509
510         int format_data_width (ARDOUR::SampleFormat);
511
512         enum CDMarkerFormat {
513                 CDMarkerNone,
514                 CDMarkerCUE,
515                 CDMarkerTOC,
516                 MP4Chaps
517         };
518
519         enum HeaderFormat {
520                 BWF,
521                 WAVE,
522                 WAVE64,
523                 CAF,
524                 AIFF,
525                 iXML,
526                 RF64,
527                 RF64_WAV,
528                 MBWF,
529         };
530
531         struct PeakData {
532                 typedef Sample PeakDatum;
533
534                 PeakDatum min;
535                 PeakDatum max;
536         };
537
538         enum RunContext {
539                 ButlerContext = 0,
540                 TransportContext,
541                 ExportContext
542         };
543
544         enum SyncSource {
545                 /* These are "synonyms". It is important for JACK to be first
546                    both here and in enums.cc, so that the string "JACK" is
547                    correctly recognized in older session and preference files.
548                 */
549                 JACK = 0,
550                 Engine = 0,
551                 MTC,
552                 MIDIClock,
553                 LTC
554         };
555
556         enum ShuttleBehaviour {
557                 Sprung,
558                 Wheel
559         };
560
561         enum ShuttleUnits {
562                 Percentage,
563                 Semitones
564         };
565
566         typedef std::vector<boost::shared_ptr<Source> > SourceList;
567
568         enum SrcQuality {
569                 SrcBest,
570                 SrcGood,
571                 SrcQuick,
572                 SrcFast,
573                 SrcFastest
574         };
575
576         typedef std::list<samplepos_t> AnalysisFeatureList;
577
578         typedef std::list<boost::shared_ptr<Route> > RouteList;
579         typedef std::list<boost::shared_ptr<Stripable> > StripableList;
580         typedef std::list<boost::weak_ptr  <Route> > WeakRouteList;
581         typedef std::list<boost::weak_ptr  <Stripable> > WeakStripableList;
582         typedef std::list<boost::shared_ptr<AutomationControl> > ControlList;
583         typedef std::list<boost::shared_ptr<SlavableAutomationControl> > SlavableControlList;
584         typedef std::set <boost::shared_ptr<AutomationControl> > AutomationControlSet;
585
586         typedef std::list<boost::shared_ptr<VCA> > VCAList;
587
588         class Bundle;
589         typedef std::vector<boost::shared_ptr<Bundle> > BundleList;
590
591         enum WaveformScale {
592                 Linear,
593                 Logarithmic
594         };
595
596         enum WaveformShape {
597                 Traditional,
598                 Rectified
599         };
600
601         struct CleanupReport {
602                 std::vector<std::string> paths;
603                 size_t                   space;
604         };
605
606         enum PositionLockStyle {
607                 AudioTime,
608                 MusicTime
609         };
610
611         /** A struct used to describe changes to processors in a route.
612          *  This is useful because objects that respond to a change in processors
613          *  can optimise what work they do based on details of what has changed.
614         */
615         struct RouteProcessorChange {
616                 enum Type {
617                         GeneralChange = 0x0,
618                         MeterPointChange = 0x1,
619                         RealTimeChange = 0x2
620                 };
621
622                 RouteProcessorChange () : type (GeneralChange), meter_visibly_changed (true)
623                 {}
624
625                 RouteProcessorChange (Type t) : type (t), meter_visibly_changed (true)
626                 {}
627
628                 RouteProcessorChange (Type t, bool m) : type (t), meter_visibly_changed (m)
629                 {}
630
631                 /** type of change; "GeneralChange" means anything could have changed */
632                 Type type;
633                 /** true if, when a MeterPointChange has occurred, the change is visible to the user */
634                 bool meter_visibly_changed;
635         };
636
637         struct BusProfile {
638                 uint32_t master_out_channels; /* how many channels for the master bus, 0: no master bus */
639         };
640
641         enum FadeShape {
642                 FadeLinear,
643                 FadeFast,
644                 FadeSlow,
645                 FadeConstantPower,
646                 FadeSymmetric,
647         };
648
649         enum TransportState {
650                 /* these values happen to match the constants used by JACK but
651                    this equality cannot be assumed.
652                 */
653                 TransportStopped = 0,
654                 TransportRolling = 1,
655                 TransportLooping = 2,
656                 TransportStarting = 3,
657         };
658
659         enum PortFlags {
660                 /* these values happen to match the constants used by JACK but
661                    this equality cannot be assumed.
662                 */
663                 IsInput = 0x1,
664                 IsOutput = 0x2,
665                 IsPhysical = 0x4,
666                 CanMonitor = 0x8,
667                 IsTerminal = 0x10,
668
669                 /* non-JACK related flags */
670                 Hidden = 0x20,
671                 Shadow = 0x40
672         };
673
674         enum MidiPortFlags {
675                 MidiPortMusic = 0x1,
676                 MidiPortControl = 0x2,
677                 MidiPortSelection = 0x4,
678                 MidiPortVirtual = 0x8
679         };
680
681         struct LatencyRange {
682             uint32_t min; //< samples
683             uint32_t max; //< samples
684         };
685
686         enum BufferingPreset {
687                 Small,
688                 Medium,
689                 Large,
690                 Custom,
691         };
692
693         enum AutoReturnTarget {
694                 LastLocate = 0x1,
695                 RangeSelectionStart = 0x2,
696                 Loop = 0x4,
697                 RegionSelectionStart = 0x8,
698         };
699
700         enum PlaylistDisposition {
701                 CopyPlaylist,
702                 NewPlaylist,
703                 SharePlaylist
704         };
705
706         enum MidiTrackNameSource {
707                 SMFTrackNumber,
708                 SMFTrackName,
709                 SMFInstrumentName
710         };
711
712         enum MidiTempoMapDisposition {
713                 SMFTempoIgnore,
714                 SMFTempoUse,
715         };
716
717         struct CaptureInfo {
718                 samplepos_t start;
719                 samplecnt_t samples;
720         };
721
722         typedef std::vector<CaptureInfo*> CaptureInfos;
723
724 } // namespace ARDOUR
725
726 /* for now, break the rules and use "using" to make this "global" */
727
728 using ARDOUR::samplepos_t;
729
730 #endif /* __ardour_types_h__ */