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