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