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