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