b5e5d89cc1f9c2d81314961245b37c507db19fbe
[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
30 #include <inttypes.h>
31 #include <jack/types.h>
32 #include <jack/midiport.h>
33
34 #include "timecode/bbt_time.h"
35 #include "timecode/time.h"
36
37 #include "pbd/id.h"
38
39 #include "ardour/chan_count.h"
40
41 #include <map>
42
43 #if __GNUC__ < 3
44 typedef int intptr_t;
45 #endif
46
47 namespace ARDOUR {
48
49         class Source;
50         class AudioSource;
51         class Route;
52         class Region;
53
54         typedef jack_default_audio_sample_t Sample;
55         typedef float                       pan_t;
56         typedef float                       gain_t;
57         typedef uint32_t                    layer_t;
58         typedef uint64_t                    microseconds_t;
59         typedef jack_nframes_t              pframes_t;
60
61         /* Any position measured in audio frames.
62            Assumed to be non-negative but not enforced.
63         */
64         typedef int64_t framepos_t;
65
66         /* Any distance from a given framepos_t.
67            Maybe positive or negative.
68         */
69         typedef int64_t frameoffset_t;
70
71         /* Any count of audio frames.
72            Assumed to be positive but not enforced.
73         */
74         typedef int64_t framecnt_t;
75
76         static const framepos_t max_framepos = INT64_MAX;
77         static const framecnt_t max_framecnt = INT64_MAX;
78         static const layer_t    max_layer    = UINT32_MAX;
79
80         // a set of (time) intervals: first of pair is the offset of the start within the region, second is the offset of the end
81         typedef std::list<std::pair<frameoffset_t, frameoffset_t> > AudioIntervalResult;
82         // associate a set of intervals with regions (e.g. for silence detection)
83         typedef std::map<boost::shared_ptr<ARDOUR::Region>,AudioIntervalResult> AudioIntervalMap;
84
85         struct IOChange {
86
87                 enum Type {
88                         NoChange = 0,
89                         ConfigurationChanged = 0x1,
90                         ConnectionsChanged = 0x2
91                 } type;
92
93                 IOChange () : type (NoChange) {}
94                 IOChange (Type t) : type (t) {}
95
96                 /** channel count of IO before a ConfigurationChanged, if appropriate */
97                 ARDOUR::ChanCount before;
98                 /** channel count of IO after a ConfigurationChanged, if appropriate */
99                 ARDOUR::ChanCount after;
100         };
101
102         enum OverlapType {
103                 OverlapNone,      // no overlap
104                 OverlapInternal,  // the overlap is 100% with the object
105                 OverlapStart,     // overlap covers start, but ends within
106                 OverlapEnd,       // overlap begins within and covers end
107                 OverlapExternal   // overlap extends to (at least) begin+end
108         };
109
110         ARDOUR::OverlapType coverage (framepos_t sa, framepos_t ea,
111                                       framepos_t sb, framepos_t eb);
112
113         /* policies for inserting/pasting material where overlaps
114            might be an issue.
115         */
116
117         enum InsertMergePolicy {
118                 InsertMergeReject,  // no overlaps allowed
119                 InsertMergeRelax,   // we just don't care about overlaps
120                 InsertMergeReplace, // replace old with new
121                 InsertMergeTruncateExisting, // shorten existing to avoid overlap
122                 InsertMergeTruncateAddition, // shorten new to avoid overlap
123                 InsertMergeExtend   // extend new (or old) to the range of old+new
124         };
125
126         /** See evoral/Parameter.hpp
127          */
128         enum AutomationType {
129                 NullAutomation,
130                 GainAutomation,
131                 PanAzimuthAutomation,
132                 PanElevationAutomation,
133                 PanWidthAutomation,
134                 PanFrontBackAutomation,
135                 PanLFEAutomation,
136                 PluginAutomation,
137                 SoloAutomation,
138                 MuteAutomation,
139                 MidiCCAutomation,
140                 MidiPgmChangeAutomation,
141                 MidiPitchBenderAutomation,
142                 MidiChannelPressureAutomation,
143                 MidiSystemExclusiveAutomation,
144                 FadeInAutomation,
145                 FadeOutAutomation,
146                 EnvelopeAutomation
147         };
148
149         enum AutoState {
150                 Off = 0x0,
151                 Write = 0x1,
152                 Touch = 0x2,
153                 Play = 0x4
154         };
155
156         std::string auto_state_to_string (AutoState);
157         AutoState string_to_auto_state (std::string);
158
159         enum AutoStyle {
160                 Absolute = 0x1,
161                 Trim = 0x2
162         };
163
164         std::string auto_style_to_string (AutoStyle);
165         AutoStyle string_to_auto_style (std::string);
166
167         enum AlignStyle {
168                 CaptureTime,
169                 ExistingMaterial
170         };
171
172         enum AlignChoice {
173                 UseCaptureTime,
174                 UseExistingMaterial,
175                 Automatic
176         };
177
178         enum MeterPoint {
179                 MeterInput,
180                 MeterPreFader,
181                 MeterPostFader,
182                 MeterOutput,
183                 MeterCustom
184         };
185
186         enum TrackMode {
187                 Normal,
188                 NonLayered,
189                 Destructive
190         };
191
192         enum NoteMode {
193                 Sustained,
194                 Percussive
195         };
196
197         enum ChannelMode {
198                 AllChannels = 0, ///< Pass through all channel information unmodified
199                 FilterChannels,  ///< Ignore events on certain channels
200                 ForceChannel     ///< Force all events to a certain channel
201         };
202
203         enum ColorMode {
204                 MeterColors = 0,
205                 ChannelColors,
206                 TrackColor
207         };
208
209         enum TimecodeFormat {
210                 timecode_23976,
211                 timecode_24,
212                 timecode_24976,
213                 timecode_25,
214                 timecode_2997,
215                 timecode_2997drop,
216                 timecode_30,
217                 timecode_30drop,
218                 timecode_5994,
219                 timecode_60
220         };
221
222         struct AnyTime {
223                 enum Type {
224                         Timecode,
225                         BBT,
226                         Frames,
227                         Seconds
228                 };
229
230                 Type type;
231
232                 Timecode::Time     timecode;
233                 Timecode::BBT_Time bbt;
234
235                 union {
236                         framecnt_t     frames;
237                         double         seconds;
238                 };
239
240                 AnyTime() { type = Frames; frames = 0; }
241
242                 bool operator== (AnyTime const & other) const {
243                         if (type != other.type) { return false; }
244
245                         switch (type) {
246                           case Timecode:
247                                 return timecode == other.timecode;
248                           case BBT:
249                                 return bbt == other.bbt;
250                           case Frames:
251                                 return frames == other.frames;
252                           case Seconds:
253                                 return seconds == other.seconds;
254                         }
255                         return false; // get rid of warning
256                 }
257
258                 bool not_zero() const
259                 {
260                         switch (type) {
261                           case Timecode:
262                                 return timecode.hours != 0 || timecode.minutes != 0 ||
263                                        timecode.seconds != 0 || timecode.frames != 0;
264                           case BBT:
265                                 return bbt.bars != 0 || bbt.beats != 0 || bbt.ticks != 0;
266                           case Frames:
267                                 return frames != 0;
268                           case Seconds:
269                                 return seconds != 0;
270                         }
271
272                         /* NOTREACHED */
273                         assert (false);
274                         return false;
275                 }
276         };
277
278         struct AudioRange {
279                 framepos_t start;
280                 framepos_t end;
281                 uint32_t id;
282
283                 AudioRange (framepos_t s, framepos_t e, uint32_t i) : start (s), end (e) , id (i) {}
284
285                 framecnt_t length() { return end - start + 1; }
286
287                 bool operator== (const AudioRange& other) const {
288                         return start == other.start && end == other.end && id == other.id;
289                 }
290
291                 bool equal (const AudioRange& other) const {
292                         return start == other.start && end == other.end;
293                 }
294
295                 OverlapType coverage (framepos_t s, framepos_t e) const {
296                         return ARDOUR::coverage (start, end, s, e);
297                 }
298         };
299
300         struct MusicRange {
301                 Timecode::BBT_Time start;
302                 Timecode::BBT_Time end;
303                 uint32_t id;
304
305                 MusicRange (Timecode::BBT_Time& s, Timecode::BBT_Time& e, uint32_t i)
306                         : start (s), end (e), id (i) {}
307
308                 bool operator== (const MusicRange& other) const {
309                         return start == other.start && end == other.end && id == other.id;
310                 }
311
312                 bool equal (const MusicRange& other) const {
313                         return start == other.start && end == other.end;
314                 }
315         };
316
317         /*
318             Slowest = 6.6dB/sec falloff at update rate of 40ms
319             Slow    = 6.8dB/sec falloff at update rate of 40ms
320         */
321
322         enum MeterFalloff {
323                 MeterFalloffOff = 0,
324                 MeterFalloffSlowest = 1,
325                 MeterFalloffSlow = 2,
326                 MeterFalloffMedium = 3,
327                 MeterFalloffFast = 4,
328                 MeterFalloffFaster = 5,
329                 MeterFalloffFastest = 6
330         };
331
332         enum MeterHold {
333                 MeterHoldOff = 0,
334                 MeterHoldShort = 40,
335                 MeterHoldMedium = 100,
336                 MeterHoldLong = 200
337         };
338
339         enum EditMode {
340                 Slide,
341                 Splice,
342                 Lock
343         };
344
345         enum RegionPoint {
346                 Start,
347                 End,
348                 SyncPoint
349         };
350
351         enum Placement {
352                 PreFader,
353                 PostFader
354         };
355
356         enum MonitorModel {
357                 HardwareMonitoring, ///< JACK does monitoring
358                 SoftwareMonitoring, ///< Ardour does monitoring
359                 ExternalMonitoring  ///< we leave monitoring to the audio hardware
360         };
361
362         enum MonitorChoice {
363                 MonitorAuto = 0,
364                 MonitorInput = 0x1,
365                 MonitorDisk = 0x2,
366                 MonitorCue = 0x4,
367         };
368
369         enum MonitorState {
370                 MonitoringSilence = 0x1,
371                 MonitoringInput = 0x2,
372                 MonitoringDisk = 0x4,
373         };
374
375         enum MeterState {
376                 MeteringInput, ///< meter the input IO, regardless of what is going through the route
377                 MeteringRoute  ///< meter what is going through the route
378         };
379
380         enum PFLPosition {
381                 /** PFL signals come from before pre-fader processors */
382                 PFLFromBeforeProcessors,
383                 /** PFL signals come pre-fader but after pre-fader processors */
384                 PFLFromAfterProcessors
385         };
386
387         enum AFLPosition {
388                 /** AFL signals come post-fader and before post-fader processors */
389                 AFLFromBeforeProcessors,
390                 /** AFL signals come post-fader but after post-fader processors */
391                 AFLFromAfterProcessors
392         };
393
394         enum DenormalModel {
395                 DenormalNone,
396                 DenormalFTZ,
397                 DenormalDAZ,
398                 DenormalFTZDAZ
399         };
400
401         enum RemoteModel {
402                 UserOrdered,
403                 MixerOrdered,
404                 EditorOrdered
405         };
406
407         enum CrossfadeModel {
408                 FullCrossfade,
409                 ShortCrossfade
410         };
411
412         enum LayerModel {
413                 LaterHigher,
414                 AddOrBoundsChangeHigher,
415                 AddHigher
416         };
417
418         enum ListenPosition {
419                 AfterFaderListen,
420                 PreFaderListen
421         };
422
423         enum AutoConnectOption {
424                 ManualConnect = 0x0,
425                 AutoConnectPhysical = 0x1,
426                 AutoConnectMaster = 0x2
427         };
428
429         struct InterThreadInfo {
430                 InterThreadInfo () : done (false), cancel (false), progress (0), thread (0) {}
431
432                 volatile bool  done;
433                 volatile bool  cancel;
434                 volatile float progress;
435                 pthread_t      thread;
436         };
437
438         enum SampleFormat {
439                 FormatFloat = 0,
440                 FormatInt24,
441                 FormatInt16
442         };
443
444         enum CDMarkerFormat {
445                 CDMarkerNone,
446                 CDMarkerCUE,
447                 CDMarkerTOC
448         };
449
450         enum HeaderFormat {
451                 BWF,
452                 WAVE,
453                 WAVE64,
454                 CAF,
455                 AIFF,
456                 iXML,
457                 RF64
458         };
459
460         struct PeakData {
461                 typedef Sample PeakDatum;
462
463                 PeakDatum min;
464                 PeakDatum max;
465         };
466
467         enum PluginType {
468                 AudioUnit,
469                 LADSPA,
470                 LV2,
471                 Windows_VST,
472                 LXVST,
473         };
474
475         enum RunContext {
476                 ButlerContext = 0,
477                 TransportContext,
478                 ExportContext
479         };
480
481         enum SyncSource {
482                 JACK,
483                 MTC,
484                 MIDIClock
485         };
486
487         enum ShuttleBehaviour {
488                 Sprung,
489                 Wheel
490         };
491
492         enum ShuttleUnits {
493                 Percentage,
494                 Semitones
495         };
496
497         typedef std::vector<boost::shared_ptr<Source> > SourceList;
498
499         enum SrcQuality {
500                 SrcBest,
501                 SrcGood,
502                 SrcQuick,
503                 SrcFast,
504                 SrcFastest
505         };
506
507         struct TimeFXRequest : public InterThreadInfo {
508                 TimeFXRequest()
509                         : time_fraction(0), pitch_fraction(0),
510                         quick_seek(false), antialias(false),  opts(0) {}
511                 float time_fraction;
512                 float pitch_fraction;
513                 /* SoundTouch */
514                 bool  quick_seek;
515                 bool  antialias;
516                 /* RubberBand */
517                 int   opts; // really RubberBandStretcher::Options
518         };
519
520         typedef std::list<framepos_t> AnalysisFeatureList;
521
522         typedef std::list<boost::shared_ptr<Route> > RouteList;
523         typedef std::list<boost::weak_ptr  <Route> > WeakRouteList;
524
525         class Bundle;
526         typedef std::vector<boost::shared_ptr<Bundle> > BundleList;
527
528         enum WaveformScale {
529                 Linear,
530                 Logarithmic
531         };
532
533         enum WaveformShape {
534                 Traditional,
535                 Rectified
536         };
537
538         enum QuantizeType {
539                 Plain,
540                 Legato,
541                 Groove
542         };
543
544         struct CleanupReport {
545                 std::vector<std::string> paths;
546                 size_t                   space;
547         };
548
549         enum PositionLockStyle {
550                 AudioTime,
551                 MusicTime
552         };
553
554         /** A struct used to describe changes to processors in a route.
555          *  This is useful because objects that respond to a change in processors
556          *  can optimise what work they do based on details of what has changed.
557         */
558         struct RouteProcessorChange {
559                 enum Type {
560                         GeneralChange = 0x0,
561                         MeterPointChange = 0x1
562                 };
563
564                 RouteProcessorChange () : type (GeneralChange), meter_visibly_changed (true)
565                 {}
566
567                 RouteProcessorChange (Type t) : type (t), meter_visibly_changed (true)
568                 {}
569
570                 RouteProcessorChange (Type t, bool m) : type (t), meter_visibly_changed (m)
571                 {}
572
573                 /** type of change; "GeneralChange" means anything could have changed */
574                 Type type;
575                 /** true if, when a MeterPointChange has occurred, the change is visible to the user */
576                 bool meter_visibly_changed;
577         };
578
579         struct BusProfile {
580                 AutoConnectOption input_ac;      /* override the RC config for input auto-connection */
581                 AutoConnectOption output_ac;     /* override the RC config for output auto-connection */
582                 uint32_t master_out_channels;    /* how many channels for the master bus */
583                 uint32_t requested_physical_in;  /* now many of the available physical inputs to consider usable */
584                 uint32_t requested_physical_out; /* now many of the available physical inputs to consider usable */
585         };
586
587         enum FadeShape {
588                 FadeLinear,
589                 FadeFast,
590                 FadeSlow,
591                 FadeLogA,
592                 FadeLogB
593         };
594
595         enum LayerOp {
596                 LayerOpAdd,
597                 LayerOpBoundsChange
598         };
599
600 } // namespace ARDOUR
601
602
603 /* these cover types declared above in this header. See enums.cc
604    for the definitions.
605 */
606
607 std::istream& operator>>(std::istream& o, ARDOUR::SampleFormat& sf);
608 std::istream& operator>>(std::istream& o, ARDOUR::HeaderFormat& sf);
609 std::istream& operator>>(std::istream& o, ARDOUR::AutoConnectOption& sf);
610 std::istream& operator>>(std::istream& o, ARDOUR::EditMode& sf);
611 std::istream& operator>>(std::istream& o, ARDOUR::MonitorModel& sf);
612 std::istream& operator>>(std::istream& o, ARDOUR::PFLPosition& sf);
613 std::istream& operator>>(std::istream& o, ARDOUR::AFLPosition& sf);
614 std::istream& operator>>(std::istream& o, ARDOUR::RemoteModel& sf);
615 std::istream& operator>>(std::istream& o, ARDOUR::ListenPosition& sf);
616 std::istream& operator>>(std::istream& o, ARDOUR::LayerModel& sf);
617 std::istream& operator>>(std::istream& o, ARDOUR::InsertMergePolicy& sf);
618 std::istream& operator>>(std::istream& o, ARDOUR::CrossfadeModel& sf);
619 std::istream& operator>>(std::istream& o, ARDOUR::SyncSource& sf);
620 std::istream& operator>>(std::istream& o, ARDOUR::ShuttleBehaviour& sf);
621 std::istream& operator>>(std::istream& o, ARDOUR::ShuttleUnits& sf);
622 std::istream& operator>>(std::istream& o, ARDOUR::TimecodeFormat& sf);
623 std::istream& operator>>(std::istream& o, ARDOUR::DenormalModel& sf);
624 std::istream& operator>>(std::istream& o, ARDOUR::WaveformScale& sf);
625 std::istream& operator>>(std::istream& o, ARDOUR::WaveformShape& sf);
626 std::istream& operator>>(std::istream& o, ARDOUR::PositionLockStyle& sf);
627
628 std::ostream& operator<<(std::ostream& o, const ARDOUR::SampleFormat& sf);
629 std::ostream& operator<<(std::ostream& o, const ARDOUR::HeaderFormat& sf);
630 std::ostream& operator<<(std::ostream& o, const ARDOUR::AutoConnectOption& sf);
631 std::ostream& operator<<(std::ostream& o, const ARDOUR::EditMode& sf);
632 std::ostream& operator<<(std::ostream& o, const ARDOUR::MonitorModel& sf);
633 std::ostream& operator<<(std::ostream& o, const ARDOUR::PFLPosition& sf);
634 std::ostream& operator<<(std::ostream& o, const ARDOUR::AFLPosition& sf);
635 std::ostream& operator<<(std::ostream& o, const ARDOUR::RemoteModel& sf);
636 std::ostream& operator<<(std::ostream& o, const ARDOUR::ListenPosition& sf);
637 std::ostream& operator<<(std::ostream& o, const ARDOUR::LayerModel& sf);
638 std::ostream& operator<<(std::ostream& o, const ARDOUR::InsertMergePolicy& sf);
639 std::ostream& operator<<(std::ostream& o, const ARDOUR::CrossfadeModel& sf);
640 std::ostream& operator<<(std::ostream& o, const ARDOUR::SyncSource& sf);
641 std::ostream& operator<<(std::ostream& o, const ARDOUR::ShuttleBehaviour& sf);
642 std::ostream& operator<<(std::ostream& o, const ARDOUR::ShuttleUnits& sf);
643 std::ostream& operator<<(std::ostream& o, const ARDOUR::TimecodeFormat& sf);
644 std::ostream& operator<<(std::ostream& o, const ARDOUR::DenormalModel& sf);
645 std::ostream& operator<<(std::ostream& o, const ARDOUR::WaveformScale& sf);
646 std::ostream& operator<<(std::ostream& o, const ARDOUR::WaveformShape& sf);
647 std::ostream& operator<<(std::ostream& o, const ARDOUR::PositionLockStyle& sf);
648
649 static inline ARDOUR::framepos_t
650 session_frame_to_track_frame (ARDOUR::framepos_t session_frame, double speed)
651 {
652         return (ARDOUR::framepos_t) ((long double) session_frame * (long double) speed);
653 }
654
655 static inline ARDOUR::framepos_t
656 track_frame_to_session_frame (ARDOUR::framepos_t track_frame, double speed)
657 {
658         return (ARDOUR::framepos_t) ((long double) track_frame / (long double) speed);
659 }
660
661 /* for now, break the rules and use "using" to make this "global" */
662
663 using ARDOUR::framepos_t;
664
665
666 #endif /* __ardour_types_h__ */
667