cff8a12fd585b977314ae376310006c980fd183d
[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 #ifndef __STDC_FORMAT_MACROS
24 #define __STDC_FORMAT_MACROS /* PRI<foo>; C++ requires explicit requesting of these */
25 #endif
26
27 #include <istream>
28 #include <vector>
29 #include <boost/shared_ptr.hpp>
30
31 #include <inttypes.h>
32 #include <jack/types.h>
33 #include <jack/midiport.h>
34 #include "control_protocol/timecode.h"
35 #include "pbd/id.h"
36
37 #include "ardour/bbt_time.h"
38
39 #include <map>
40
41 #if __GNUC__ < 3
42 typedef int intptr_t;
43 #endif
44
45 namespace ARDOUR {
46
47         class Source;
48         class AudioSource;
49         class Route;
50
51         typedef jack_default_audio_sample_t Sample;
52         typedef float                       pan_t;
53         typedef float                       gain_t;
54         typedef uint32_t                    layer_t;
55         typedef uint64_t                    microseconds_t;
56         typedef uint32_t                    nframes_t;
57         typedef int64_t                     nframes64_t;
58
59
60         /** "Session frames", frames relative to the session timeline.
61          * Everything related to transport position etc. should be of this type.
62          * We might want to make this a compile time option for 32-bitters who
63          * don't want to pay for extremely long session times they don't need...
64          */
65         typedef int64_t sframes_t;
66         typedef int64_t framepos_t;
67         /* any offset from a framepos_t, measured in audio frames */
68         typedef int64_t frameoffset_t;
69         /* any count of audio frames */
70         typedef int64_t framecnt_t;
71
72         enum IOChange {
73                 NoChange = 0,
74                 ConfigurationChanged = 0x1,
75                 ConnectionsChanged = 0x2
76         };
77
78         enum OverlapType {
79                 OverlapNone,      // no overlap
80                 OverlapInternal,  // the overlap is 100% with the object
81                 OverlapStart,     // overlap covers start, but ends within
82                 OverlapEnd,       // overlap begins within and covers end
83                 OverlapExternal   // overlap extends to (at least) begin+end
84         };
85         
86         ARDOUR::OverlapType coverage (framepos_t sa, framepos_t ea,
87                                       framepos_t sb, framepos_t eb);
88
89         /* policies for inserting/pasting material where overlaps
90            might be an issue.
91         */
92
93         enum InsertMergePolicy {
94                 InsertMergeReject,  // no overlaps allowed
95                 InsertMergeRelax,   // we just don't care about overlaps
96                 InsertMergeReplace, // replace old with new
97                 InsertMergeTruncateExisting, // shorten existing to avoid overlap
98                 InsertMergeTruncateAddition, // shorten new to avoid overlap
99                 InsertMergeExtend   // extend new (or old) to the range of old+new
100         };
101
102         /** See parameter.h
103          * XXX: I don't think/hope these hex values matter anymore.
104          */
105         enum AutomationType {
106                 NullAutomation = 0x0,
107                 GainAutomation = 0x1,
108                 PanAutomation = 0x2,
109                 PluginAutomation = 0x4,
110                 SoloAutomation = 0x8,
111                 MuteAutomation = 0x10,
112                 MidiCCAutomation = 0x20,
113                 MidiPgmChangeAutomation = 0x21,
114                 MidiPitchBenderAutomation = 0x22,
115                 MidiChannelPressureAutomation = 0x23,
116                 MidiSystemExclusiveAutomation = 0x24,
117                 FadeInAutomation = 0x40,
118                 FadeOutAutomation = 0x80,
119                 EnvelopeAutomation = 0x100
120         };
121
122         enum AutoState {
123                 Off = 0x0,
124                 Write = 0x1,
125                 Touch = 0x2,
126                 Play = 0x4
127         };
128
129         std::string auto_state_to_string (AutoState);
130         AutoState string_to_auto_state (std::string);
131
132         enum AutoStyle {
133                 Absolute = 0x1,
134                 Trim = 0x2
135         };
136
137         std::string auto_style_to_string (AutoStyle);
138         AutoStyle string_to_auto_style (std::string);
139
140         enum AlignStyle {
141                 CaptureTime,
142                 ExistingMaterial
143         };
144
145         enum MeterPoint {
146                 MeterInput,
147                 MeterPreFader,
148                 MeterPostFader,
149                 MeterCustom
150         };
151
152         enum TrackMode {
153                 Normal,
154                 NonLayered,
155                 Destructive
156         };
157
158         enum NoteMode {
159                 Sustained,
160                 Percussive
161         };
162
163         enum ChannelMode {
164                 AllChannels = 0, ///< Pass through all channel information unmodified
165                 FilterChannels,  ///< Ignore events on certain channels
166                 ForceChannel     ///< Force all events to a certain channel
167         };
168
169         enum ColorMode {
170                 MeterColors = 0,
171                 ChannelColors,
172                 TrackColor
173         };
174
175         enum TimecodeFormat {
176                 timecode_23976,
177                 timecode_24,
178                 timecode_24976,
179                 timecode_25,
180                 timecode_2997,
181                 timecode_2997drop,
182                 timecode_30,
183                 timecode_30drop,
184                 timecode_5994,
185                 timecode_60
186         };
187
188         struct AnyTime {
189                 enum Type {
190                         Timecode,
191                         BBT,
192                         Frames,
193                         Seconds
194                 };
195
196                 Type type;
197
198                 Timecode::Time    timecode;
199                 BBT_Time       bbt;
200
201                 union {
202                         nframes_t      frames;
203                         double         seconds;
204                 };
205
206                 AnyTime() { type = Frames; frames = 0; }
207         };
208
209         struct AudioRange {
210                 nframes_t start;
211                 nframes_t end;
212                 uint32_t id;
213
214                 AudioRange (nframes_t s, nframes_t e, uint32_t i) : start (s), end (e) , id (i) {}
215
216                 nframes_t length() { return end - start + 1; }
217
218                 bool operator== (const AudioRange& other) const {
219                         return start == other.start && end == other.end && id == other.id;
220                 }
221
222                 bool equal (const AudioRange& other) const {
223                         return start == other.start && end == other.end;
224                 }
225
226                 OverlapType coverage (nframes_t s, nframes_t e) const {
227                         return ARDOUR::coverage (start, end, s, e);
228                 }
229         };
230
231         struct MusicRange {
232                 BBT_Time start;
233                 BBT_Time end;
234                 uint32_t id;
235
236                 MusicRange (BBT_Time& s, BBT_Time& e, uint32_t i)
237                         : start (s), end (e), id (i) {}
238
239                 bool operator== (const MusicRange& other) const {
240                         return start == other.start && end == other.end && id == other.id;
241                 }
242
243                 bool equal (const MusicRange& other) const {
244                         return start == other.start && end == other.end;
245                 }
246         };
247
248         /*
249             Slowest = 6.6dB/sec falloff at update rate of 40ms
250             Slow    = 6.8dB/sec falloff at update rate of 40ms
251         */
252
253         enum MeterFalloff {
254                 MeterFalloffOff = 0,
255                 MeterFalloffSlowest = 1,
256                 MeterFalloffSlow = 2,
257                 MeterFalloffMedium = 3,
258                 MeterFalloffFast = 4,
259                 MeterFalloffFaster = 5,
260                 MeterFalloffFastest = 6
261         };
262
263         enum MeterHold {
264                 MeterHoldOff = 0,
265                 MeterHoldShort = 40,
266                 MeterHoldMedium = 100,
267                 MeterHoldLong = 200
268         };
269
270         enum EditMode {
271                 Slide,
272                 Splice,
273                 Lock
274         };
275
276         enum RegionPoint {
277                 Start,
278                 End,
279                 SyncPoint
280         };
281
282         enum Placement {
283                 PreFader,
284                 PostFader
285         };
286
287         enum MonitorModel {
288                 HardwareMonitoring,
289                 SoftwareMonitoring,
290                 ExternalMonitoring
291         };
292
293         enum DenormalModel {
294                 DenormalNone,
295                 DenormalFTZ,
296                 DenormalDAZ,
297                 DenormalFTZDAZ
298         };
299
300         enum RemoteModel {
301                 UserOrdered,
302                 MixerOrdered,
303                 EditorOrdered
304         };
305
306         enum CrossfadeModel {
307                 FullCrossfade,
308                 ShortCrossfade
309         };
310
311         enum LayerModel {
312                 LaterHigher,
313                 MoveAddHigher,
314                 AddHigher
315         };
316
317         enum ListenPosition {
318                 AfterFaderListen,
319                 PreFaderListen
320         };
321
322         enum AutoConnectOption {
323                 ManualConnect = 0x0,
324                 AutoConnectPhysical = 0x1,
325                 AutoConnectMaster = 0x2
326         };
327
328         struct InterThreadInfo {
329                 InterThreadInfo () : done (false), cancel (false), progress (0), thread (0) {}
330                         
331                 volatile bool  done;
332                 volatile bool  cancel;
333                 volatile float progress;
334                 pthread_t      thread;
335         };
336
337         enum SampleFormat {
338                 FormatFloat = 0,
339                 FormatInt24,
340                 FormatInt16
341         };
342
343         enum CDMarkerFormat {
344                 CDMarkerNone,
345                 CDMarkerCUE,
346                 CDMarkerTOC
347         };
348
349         enum HeaderFormat {
350                 BWF,
351                 WAVE,
352                 WAVE64,
353                 CAF,
354                 AIFF,
355                 iXML,
356                 RF64
357         };
358
359         struct PeakData {
360                 typedef Sample PeakDatum;
361
362                 PeakDatum min;
363                 PeakDatum max;
364         };
365
366         enum PluginType {
367                 AudioUnit,
368                 LADSPA,
369                 LV2,
370                 VST
371         };
372
373         enum RunContext {
374                 ButlerContext = 0,
375                 TransportContext,
376                 ExportContext
377         };
378
379         enum SyncSource {
380                 JACK,
381                 MTC,
382                 MIDIClock
383         };
384
385         enum ShuttleBehaviour {
386                 Sprung,
387                 Wheel
388         };
389
390         enum ShuttleUnits {
391                 Percentage,
392                 Semitones
393         };
394
395         typedef std::vector<boost::shared_ptr<Source> > SourceList;
396
397         enum SrcQuality {
398                 SrcBest,
399                 SrcGood,
400                 SrcQuick,
401                 SrcFast,
402                 SrcFastest
403         };
404
405         struct TimeFXRequest : public InterThreadInfo {
406                 TimeFXRequest()
407                         : time_fraction(0), pitch_fraction(0),
408                         quick_seek(false), antialias(false),  opts(0) {}
409                 float time_fraction;
410                 float pitch_fraction;
411                 /* SoundTouch */
412                 bool  quick_seek;
413                 bool  antialias;
414                 /* RubberBand */
415                 int   opts; // really RubberBandStretcher::Options
416         };
417
418         typedef std::list<nframes64_t> AnalysisFeatureList;
419
420         typedef std::list<boost::shared_ptr<Route> >      RouteList;
421
422         class Bundle;
423         typedef std::vector<boost::shared_ptr<Bundle> > BundleList;
424
425         enum WaveformScale {
426                 Linear,
427                 Logarithmic
428         };
429
430         enum WaveformShape {
431                 Traditional,
432                 Rectified
433         };
434
435         enum QuantizeType {
436                 Plain,
437                 Legato,
438                 Groove
439         };
440
441         struct CleanupReport {
442                 std::vector<std::string> paths;
443                 int64_t                  space;
444         };
445
446         enum PositionLockStyle {
447                 AudioTime,
448                 MusicTime
449         };
450
451         /** A struct used to describe changes to processors in a route.
452          *  This is useful because objects that respond to a change in processors
453          *  can optimise what work they do based on details of what has changed.
454         */
455         struct RouteProcessorChange {
456                 enum Type {
457                         GeneralChange = 0x0,
458                         MeterPointChange = 0x1
459                 };
460
461                 RouteProcessorChange () : type (GeneralChange), meter_visibly_changed (true)
462                 {}
463
464                 RouteProcessorChange (Type t) : type (t), meter_visibly_changed (true)
465                 {}
466
467                 RouteProcessorChange (Type t, bool m) : type (t), meter_visibly_changed (m)
468                 {}
469
470                 /** type of change; "GeneralChange" means anything could have changed */
471                 Type type;
472                 /** true if, when a MeterPointChange has occurred, the change is visible to the user */
473                 bool meter_visibly_changed;
474         };
475
476         struct BusProfile {
477             AutoConnectOption input_ac;      /* override the RC config for input auto-connection */
478             AutoConnectOption output_ac;     /* override the RC config for output auto-connection */
479             uint32_t master_out_channels;    /* how many channels for the master bus */
480             uint32_t requested_physical_in;  /* now many of the available physical inputs to consider usable */
481             uint32_t requested_physical_out; /* now many of the available physical inputs to consider usable */
482         };
483
484 } // namespace ARDOUR
485
486
487 /* these cover types declared above in this header. See enums.cc
488    for the definitions.
489 */
490
491 std::istream& operator>>(std::istream& o, ARDOUR::SampleFormat& sf);
492 std::istream& operator>>(std::istream& o, ARDOUR::HeaderFormat& sf);
493 std::istream& operator>>(std::istream& o, ARDOUR::AutoConnectOption& sf);
494 std::istream& operator>>(std::istream& o, ARDOUR::EditMode& sf);
495 std::istream& operator>>(std::istream& o, ARDOUR::MonitorModel& sf);
496 std::istream& operator>>(std::istream& o, ARDOUR::RemoteModel& sf);
497 std::istream& operator>>(std::istream& o, ARDOUR::ListenPosition& sf);
498 std::istream& operator>>(std::istream& o, ARDOUR::LayerModel& sf);
499 std::istream& operator>>(std::istream& o, ARDOUR::InsertMergePolicy& sf);
500 std::istream& operator>>(std::istream& o, ARDOUR::CrossfadeModel& sf);
501 std::istream& operator>>(std::istream& o, ARDOUR::SyncSource& sf);
502 std::istream& operator>>(std::istream& o, ARDOUR::ShuttleBehaviour& sf);
503 std::istream& operator>>(std::istream& o, ARDOUR::ShuttleUnits& sf);
504 std::istream& operator>>(std::istream& o, ARDOUR::TimecodeFormat& sf);
505 std::istream& operator>>(std::istream& o, ARDOUR::DenormalModel& sf);
506 std::istream& operator>>(std::istream& o, ARDOUR::WaveformScale& sf);
507 std::istream& operator>>(std::istream& o, ARDOUR::WaveformShape& sf);
508 std::istream& operator>>(std::istream& o, ARDOUR::PositionLockStyle& sf);
509
510 std::ostream& operator<<(std::ostream& o, const ARDOUR::SampleFormat& sf);
511 std::ostream& operator<<(std::ostream& o, const ARDOUR::HeaderFormat& sf);
512 std::ostream& operator<<(std::ostream& o, const ARDOUR::AutoConnectOption& sf);
513 std::ostream& operator<<(std::ostream& o, const ARDOUR::EditMode& sf);
514 std::ostream& operator<<(std::ostream& o, const ARDOUR::MonitorModel& sf);
515 std::ostream& operator<<(std::ostream& o, const ARDOUR::RemoteModel& sf);
516 std::ostream& operator<<(std::ostream& o, const ARDOUR::ListenPosition& sf);
517 std::ostream& operator<<(std::ostream& o, const ARDOUR::LayerModel& sf);
518 std::ostream& operator<<(std::ostream& o, const ARDOUR::InsertMergePolicy& sf);
519 std::ostream& operator<<(std::ostream& o, const ARDOUR::CrossfadeModel& sf);
520 std::ostream& operator<<(std::ostream& o, const ARDOUR::SyncSource& sf);
521 std::ostream& operator<<(std::ostream& o, const ARDOUR::ShuttleBehaviour& sf);
522 std::ostream& operator<<(std::ostream& o, const ARDOUR::ShuttleUnits& sf);
523 std::ostream& operator<<(std::ostream& o, const ARDOUR::TimecodeFormat& sf);
524 std::ostream& operator<<(std::ostream& o, const ARDOUR::DenormalModel& sf);
525 std::ostream& operator<<(std::ostream& o, const ARDOUR::WaveformScale& sf);
526 std::ostream& operator<<(std::ostream& o, const ARDOUR::WaveformShape& sf);
527 std::ostream& operator<<(std::ostream& o, const ARDOUR::PositionLockStyle& sf);
528
529 static inline ARDOUR::nframes64_t
530 session_frame_to_track_frame (ARDOUR::nframes64_t session_frame, double speed)
531 {
532         return (ARDOUR::nframes64_t)( (double)session_frame * speed );
533 }
534
535 static inline ARDOUR::nframes64_t
536 track_frame_to_session_frame (ARDOUR::nframes64_t track_frame, double speed)
537 {
538         return (ARDOUR::nframes64_t)( (double)track_frame / speed );
539 }
540
541 /* for now, break the rules and use "using" to make these "global" */
542
543 using ARDOUR::nframes_t;
544 using ARDOUR::nframes64_t;
545
546
547 #endif /* __ardour_types_h__ */
548