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