Add support for Latch Automation
[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   = 0x00,
167                 Write = 0x01,
168                 Touch = 0x02,
169                 Play  = 0x04,
170                 Latch = 0x08
171         };
172
173         std::string auto_state_to_string (AutoState);
174         AutoState string_to_auto_state (std::string);
175
176         enum AlignStyle {
177                 CaptureTime,
178                 ExistingMaterial
179         };
180
181         enum AlignChoice {
182                 UseCaptureTime,
183                 UseExistingMaterial,
184                 Automatic
185         };
186
187         enum MeterPoint {
188                 MeterInput,
189                 MeterPreFader,
190                 MeterPostFader,
191                 MeterOutput,
192                 MeterCustom
193         };
194
195         enum MeterType {
196                 MeterMaxSignal = 0x0001,
197                 MeterMaxPeak   = 0x0002,
198                 MeterPeak      = 0x0004,
199                 MeterKrms      = 0x0008,
200                 MeterK20       = 0x0010,
201                 MeterK14       = 0x0020,
202                 MeterIEC1DIN   = 0x0040,
203                 MeterIEC1NOR   = 0x0080,
204                 MeterIEC2BBC   = 0x0100,
205                 MeterIEC2EBU   = 0x0200,
206                 MeterVU        = 0x0400,
207                 MeterK12       = 0x0800,
208                 MeterPeak0dB   = 0x1000,
209                 MeterMCP       = 0x2000
210         };
211
212         enum TrackMode {
213                 Normal,
214                 NonLayered,
215                 Destructive
216         };
217
218         enum NoteMode {
219                 Sustained,
220                 Percussive
221         };
222
223         enum ChannelMode {
224                 AllChannels = 0, ///< Pass through all channel information unmodified
225                 FilterChannels,  ///< Ignore events on certain channels
226                 ForceChannel     ///< Force all events to a certain channel
227         };
228
229         enum ColorMode {
230                 MeterColors = 0,
231                 ChannelColors,
232                 TrackColor
233         };
234
235         enum RoundMode {
236                 RoundDownMaybe  = -2,  ///< Round down only if necessary
237                 RoundDownAlways = -1,  ///< Always round down, even if on a division
238                 RoundNearest    = 0,   ///< Round to nearest
239                 RoundUpAlways   = 1,   ///< Always round up, even if on a division
240                 RoundUpMaybe    = 2    ///< Round up only if necessary
241         };
242
243         class AnyTime {
244         public:
245                 enum Type {
246                         Timecode,
247                         BBT,
248                         Frames,
249                         Seconds
250                 };
251
252                 Type type;
253
254                 Timecode::Time     timecode;
255                 Timecode::BBT_Time bbt;
256
257                 union {
258                         framecnt_t     frames;
259                         double         seconds;
260                 };
261
262                 AnyTime() { type = Frames; frames = 0; }
263
264                 bool operator== (AnyTime const & other) const {
265                         if (type != other.type) { return false; }
266
267                         switch (type) {
268                           case Timecode:
269                                 return timecode == other.timecode;
270                           case BBT:
271                                 return bbt == other.bbt;
272                           case Frames:
273                                 return frames == other.frames;
274                           case Seconds:
275                                 return seconds == other.seconds;
276                         }
277                         return false; // get rid of warning
278                 }
279
280                 bool not_zero() const
281                 {
282                         switch (type) {
283                           case Timecode:
284                                 return timecode.hours != 0 || timecode.minutes != 0 ||
285                                        timecode.seconds != 0 || timecode.frames != 0;
286                           case BBT:
287                                 return bbt.bars != 0 || bbt.beats != 0 || bbt.ticks != 0;
288                           case Frames:
289                                 return frames != 0;
290                           case Seconds:
291                                 return seconds != 0;
292                         }
293
294                         abort(); /* NOTREACHED */
295                         return false;
296                 }
297         };
298
299         /* used for translating audio frames to an exact musical position using a note divisor.
300            an exact musical position almost never falls exactly on an audio frame, but for sub-sample
301            musical accuracy we need to derive exact musical locations from a frame position
302            the division follows TempoMap::exact_beat_at_frame().
303            division
304            -1       musical location is the bar closest to frame
305             0       musical location is the musical position of the frame
306             1       musical location is the BBT beat closest to frame
307             n       musical location is the quarter-note division n closest to frame
308         */
309         struct MusicFrame {
310                 framepos_t frame;
311                 int32_t    division;
312
313                 MusicFrame (framepos_t f, int32_t d) : frame (f), division (d) {}
314
315                 void set (framepos_t f, int32_t d) {frame = f; division = d; }
316
317                 MusicFrame operator- (MusicFrame other) { return MusicFrame (frame - other.frame, 0); }
318         };
319
320         /* XXX: slightly unfortunate that there is this and Evoral::Range<>,
321            but this has a uint32_t id which Evoral::Range<> does not.
322         */
323         struct AudioRange {
324                 framepos_t start;
325                 framepos_t end;
326                 uint32_t id;
327
328                 AudioRange (framepos_t s, framepos_t e, uint32_t i) : start (s), end (e) , id (i) {}
329
330                 framecnt_t length() const { return end - start + 1; }
331
332                 bool operator== (const AudioRange& other) const {
333                         return start == other.start && end == other.end && id == other.id;
334                 }
335
336                 bool equal (const AudioRange& other) const {
337                         return start == other.start && end == other.end;
338                 }
339
340                 Evoral::OverlapType coverage (framepos_t s, framepos_t e) const {
341                         return Evoral::coverage (start, end, s, e);
342                 }
343         };
344
345         struct MusicRange {
346                 Timecode::BBT_Time start;
347                 Timecode::BBT_Time end;
348                 uint32_t id;
349
350                 MusicRange (Timecode::BBT_Time& s, Timecode::BBT_Time& e, uint32_t i)
351                         : start (s), end (e), id (i) {}
352
353                 bool operator== (const MusicRange& other) const {
354                         return start == other.start && end == other.end && id == other.id;
355                 }
356
357                 bool equal (const MusicRange& other) const {
358                         return start == other.start && end == other.end;
359                 }
360         };
361
362         /*
363             Slowest = 6.6dB/sec falloff at update rate of 40ms
364             Slow    = 6.8dB/sec falloff at update rate of 40ms
365         */
366
367         enum MeterFalloff {
368                 MeterFalloffOff = 0,
369                 MeterFalloffSlowest = 1,
370                 MeterFalloffSlow = 2,
371                 MeterFalloffSlowish = 3,
372                 MeterFalloffModerate = 4,
373                 MeterFalloffMedium = 5,
374                 MeterFalloffFast = 6,
375                 MeterFalloffFaster = 7,
376                 MeterFalloffFastest = 8,
377         };
378
379         enum MeterHold {
380                 MeterHoldOff = 0,
381                 MeterHoldShort = 40,
382                 MeterHoldMedium = 100,
383                 MeterHoldLong = 200
384         };
385
386         enum EditMode {
387                 Slide,
388                 Splice,
389                 Ripple,
390                 Lock
391         };
392
393         enum RegionSelectionAfterSplit {
394                 None = 0,
395                 NewlyCreatedLeft = 1,  // bit 0
396                 NewlyCreatedRight = 2, // bit 1
397                 NewlyCreatedBoth = 3,
398                 Existing = 4,          // bit 2
399                 ExistingNewlyCreatedLeft = 5,
400                 ExistingNewlyCreatedRight = 6,
401                 ExistingNewlyCreatedBoth = 7
402         };
403
404         enum RegionPoint {
405                 Start,
406                 End,
407                 SyncPoint
408         };
409
410         enum Placement {
411                 PreFader,
412                 PostFader
413         };
414
415         enum MonitorModel {
416                 HardwareMonitoring, ///< JACK does monitoring
417                 SoftwareMonitoring, ///< Ardour does monitoring
418                 ExternalMonitoring  ///< we leave monitoring to the audio hardware
419         };
420
421         enum MonitorChoice {
422                 MonitorAuto = 0,
423                 MonitorInput = 0x1,
424                 MonitorDisk = 0x2,
425                 MonitorCue = 0x4,
426         };
427
428         enum MonitorState {
429                 MonitoringSilence = 0x1,
430                 MonitoringInput = 0x2,
431                 MonitoringDisk = 0x4,
432         };
433
434         enum MeterState {
435                 MeteringInput, ///< meter the input IO, regardless of what is going through the route
436                 MeteringRoute  ///< meter what is going through the route
437         };
438
439         enum VUMeterStandard {
440                 MeteringVUfrench,   // 0VU = -2dBu
441                 MeteringVUamerican, // 0VU =  0dBu
442                 MeteringVUstandard, // 0VU = +4dBu
443                 MeteringVUeight     // 0VU = +8dBu
444         };
445
446         enum MeterLineUp {
447                 MeteringLineUp24,
448                 MeteringLineUp20,
449                 MeteringLineUp18,
450                 MeteringLineUp15
451         };
452
453         enum PFLPosition {
454                 /** PFL signals come from before pre-fader processors */
455                 PFLFromBeforeProcessors,
456                 /** PFL signals come pre-fader but after pre-fader processors */
457                 PFLFromAfterProcessors
458         };
459
460         enum AFLPosition {
461                 /** AFL signals come post-fader and before post-fader processors */
462                 AFLFromBeforeProcessors,
463                 /** AFL signals come post-fader but after post-fader processors */
464                 AFLFromAfterProcessors
465         };
466
467         enum DenormalModel {
468                 DenormalNone,
469                 DenormalFTZ,
470                 DenormalDAZ,
471                 DenormalFTZDAZ
472         };
473
474         enum LayerModel {
475                 LaterHigher,
476                 Manual
477         };
478
479         enum ListenPosition {
480                 AfterFaderListen,
481                 PreFaderListen
482         };
483
484         enum AutoConnectOption {
485                 ManualConnect = 0x0,
486                 AutoConnectPhysical = 0x1,
487                 AutoConnectMaster = 0x2
488         };
489
490     enum TracksAutoNamingRule {
491         UseDefaultNames = 0x1,
492         NameAfterDriver = 0x2
493     };
494
495         enum SampleFormat {
496                 FormatFloat = 0,
497                 FormatInt24,
498                 FormatInt16
499         };
500
501         int format_data_width (ARDOUR::SampleFormat);
502
503         enum CDMarkerFormat {
504                 CDMarkerNone,
505                 CDMarkerCUE,
506                 CDMarkerTOC,
507                 MP4Chaps
508         };
509
510         enum HeaderFormat {
511                 BWF,
512                 WAVE,
513                 WAVE64,
514                 CAF,
515                 AIFF,
516                 iXML,
517                 RF64,
518                 RF64_WAV,
519                 MBWF,
520         };
521
522         struct PeakData {
523                 typedef Sample PeakDatum;
524
525                 PeakDatum min;
526                 PeakDatum max;
527         };
528
529         enum RunContext {
530                 ButlerContext = 0,
531                 TransportContext,
532                 ExportContext
533         };
534
535         enum SyncSource {
536                 /* These are "synonyms". It is important for JACK to be first
537                    both here and in enums.cc, so that the string "JACK" is
538                    correctly recognized in older session and preference files.
539                 */
540                 JACK = 0,
541                 Engine = 0,
542                 MTC,
543                 MIDIClock,
544                 LTC
545         };
546
547         enum ShuttleBehaviour {
548                 Sprung,
549                 Wheel
550         };
551
552         enum ShuttleUnits {
553                 Percentage,
554                 Semitones
555         };
556
557         typedef std::vector<boost::shared_ptr<Source> > SourceList;
558
559         enum SrcQuality {
560                 SrcBest,
561                 SrcGood,
562                 SrcQuick,
563                 SrcFast,
564                 SrcFastest
565         };
566
567         typedef std::list<framepos_t> AnalysisFeatureList;
568
569         typedef std::list<boost::shared_ptr<Route> > RouteList;
570         typedef std::list<boost::shared_ptr<Stripable> > StripableList;
571         typedef std::list<boost::weak_ptr  <Route> > WeakRouteList;
572         typedef std::list<boost::weak_ptr  <Stripable> > WeakStripableList;
573         typedef std::list<boost::shared_ptr<AutomationControl> > ControlList;
574         typedef std::list<boost::shared_ptr<SlavableAutomationControl> > SlavableControlList;
575         typedef std::set <boost::shared_ptr<AutomationControl> > AutomationControlSet;
576
577         typedef std::list<boost::shared_ptr<VCA> > VCAList;
578
579         class Bundle;
580         typedef std::vector<boost::shared_ptr<Bundle> > BundleList;
581
582         enum WaveformScale {
583                 Linear,
584                 Logarithmic
585         };
586
587         enum WaveformShape {
588                 Traditional,
589                 Rectified
590         };
591
592         struct CleanupReport {
593                 std::vector<std::string> paths;
594                 size_t                   space;
595         };
596
597         enum PositionLockStyle {
598                 AudioTime,
599                 MusicTime
600         };
601
602         /** A struct used to describe changes to processors in a route.
603          *  This is useful because objects that respond to a change in processors
604          *  can optimise what work they do based on details of what has changed.
605         */
606         struct RouteProcessorChange {
607                 enum Type {
608                         GeneralChange = 0x0,
609                         MeterPointChange = 0x1,
610                         RealTimeChange = 0x2
611                 };
612
613                 RouteProcessorChange () : type (GeneralChange), meter_visibly_changed (true)
614                 {}
615
616                 RouteProcessorChange (Type t) : type (t), meter_visibly_changed (true)
617                 {}
618
619                 RouteProcessorChange (Type t, bool m) : type (t), meter_visibly_changed (m)
620                 {}
621
622                 /** type of change; "GeneralChange" means anything could have changed */
623                 Type type;
624                 /** true if, when a MeterPointChange has occurred, the change is visible to the user */
625                 bool meter_visibly_changed;
626         };
627
628         struct BusProfile {
629                 uint32_t master_out_channels; /* how many channels for the master bus, 0: no master bus */
630         };
631
632         enum FadeShape {
633                 FadeLinear,
634                 FadeFast,
635                 FadeSlow,
636                 FadeConstantPower,
637                 FadeSymmetric,
638         };
639
640         enum TransportState {
641                 /* these values happen to match the constants used by JACK but
642                    this equality cannot be assumed.
643                 */
644                 TransportStopped = 0,
645                 TransportRolling = 1,
646                 TransportLooping = 2,
647                 TransportStarting = 3,
648         };
649
650         enum PortFlags {
651                 /* these values happen to match the constants used by JACK but
652                    this equality cannot be assumed.
653                 */
654                 IsInput = 0x1,
655                 IsOutput = 0x2,
656                 IsPhysical = 0x4,
657                 CanMonitor = 0x8,
658                 IsTerminal = 0x10,
659
660                 /* non-JACK related flags */
661                 Hidden = 0x20,
662                 Shadow = 0x40
663         };
664
665         enum MidiPortFlags {
666                 MidiPortMusic = 0x1,
667                 MidiPortControl = 0x2,
668                 MidiPortSelection = 0x4,
669                 MidiPortVirtual = 0x8
670         };
671
672         struct LatencyRange {
673             uint32_t min; //< samples
674             uint32_t max; //< samples
675         };
676
677         enum BufferingPreset {
678                 Small,
679                 Medium,
680                 Large,
681                 Custom,
682         };
683
684         enum AutoReturnTarget {
685                 LastLocate = 0x1,
686                 RangeSelectionStart = 0x2,
687                 Loop = 0x4,
688                 RegionSelectionStart = 0x8,
689         };
690
691         enum PlaylistDisposition {
692                 CopyPlaylist,
693                 NewPlaylist,
694                 SharePlaylist
695         };
696
697         enum MidiTrackNameSource {
698                 SMFTrackNumber,
699                 SMFTrackName,
700                 SMFInstrumentName
701         };
702
703         enum MidiTempoMapDisposition {
704                 SMFTempoIgnore,
705                 SMFTempoUse,
706         };
707
708 } // namespace ARDOUR
709
710 static inline ARDOUR::framepos_t
711 session_frame_to_track_frame (ARDOUR::framepos_t session_frame, double speed)
712 {
713         long double result = (long double) session_frame * (long double) speed;
714
715         if (result >= (long double) ARDOUR::max_framepos) {
716                 return ARDOUR::max_framepos;
717         } else if (result <= (long double) (ARDOUR::max_framepos) * (ARDOUR::framepos_t)(-1)) {
718                 return (ARDOUR::max_framepos * (ARDOUR::framepos_t)(-1));
719         } else {
720                 return result;
721         }
722 }
723
724 static inline ARDOUR::framepos_t
725 track_frame_to_session_frame (ARDOUR::framepos_t track_frame, double speed)
726 {
727         /* NB - do we need a check for speed == 0 ??? */
728         long double result = (long double) track_frame / (long double) speed;
729
730         if (result >= (long double) ARDOUR::max_framepos) {
731                 return ARDOUR::max_framepos;
732         } else if (result <= (long double) (ARDOUR::max_framepos) * (ARDOUR::framepos_t)(-1)) {
733                 return (ARDOUR::max_framepos * (ARDOUR::framepos_t)(-1));
734         } else {
735                 return result;
736         }
737 }
738
739 /* for now, break the rules and use "using" to make this "global" */
740
741 using ARDOUR::framepos_t;
742
743
744 #endif /* __ardour_types_h__ */