MIDI region forking, plus Playlist::regions_to_read() fix forward ported from 2.X...
[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         OverlapType coverage (nframes_t start_a, nframes_t end_a,
87                               nframes_t start_b, nframes_t end_b);
88
89         /** See parameter.h
90          * XXX: I don't think/hope these hex values matter anymore.
91          */
92         enum AutomationType {
93                 NullAutomation = 0x0,
94                 GainAutomation = 0x1,
95                 PanAutomation = 0x2,
96                 PluginAutomation = 0x4,
97                 SoloAutomation = 0x8,
98                 MuteAutomation = 0x10,
99                 MidiCCAutomation = 0x20,
100                 MidiPgmChangeAutomation = 0x21,
101                 MidiPitchBenderAutomation = 0x22,
102                 MidiChannelPressureAutomation = 0x23,
103                 MidiSystemExclusiveAutomation = 0x24,
104                 FadeInAutomation = 0x40,
105                 FadeOutAutomation = 0x80,
106                 EnvelopeAutomation = 0x100
107         };
108
109         enum AutoState {
110                 Off = 0x0,
111                 Write = 0x1,
112                 Touch = 0x2,
113                 Play = 0x4
114         };
115
116         std::string auto_state_to_string (AutoState);
117         AutoState string_to_auto_state (std::string);
118
119         enum AutoStyle {
120                 Absolute = 0x1,
121                 Trim = 0x2
122         };
123
124         std::string auto_style_to_string (AutoStyle);
125         AutoStyle string_to_auto_style (std::string);
126
127         enum AlignStyle {
128                 CaptureTime,
129                 ExistingMaterial
130         };
131
132         enum MeterPoint {
133                 MeterInput,
134                 MeterPreFader,
135                 MeterPostFader,
136                 MeterCustom
137         };
138
139         enum TrackMode {
140                 Normal,
141                 NonLayered,
142                 Destructive
143         };
144
145         enum NoteMode {
146                 Sustained,
147                 Percussive
148         };
149
150         enum ChannelMode {
151                 AllChannels = 0, ///< Pass through all channel information unmodified
152                 FilterChannels,  ///< Ignore events on certain channels
153                 ForceChannel     ///< Force all events to a certain channel
154         };
155
156         enum ColorMode {
157                 MeterColors = 0,
158                 ChannelColors,
159                 TrackColor
160         };
161
162         enum TimecodeFormat {
163                 timecode_23976,
164                 timecode_24,
165                 timecode_24976,
166                 timecode_25,
167                 timecode_2997,
168                 timecode_2997drop,
169                 timecode_30,
170                 timecode_30drop,
171                 timecode_5994,
172                 timecode_60
173         };
174
175         struct AnyTime {
176                 enum Type {
177                         Timecode,
178                         BBT,
179                         Frames,
180                         Seconds
181                 };
182
183                 Type type;
184
185                 Timecode::Time    timecode;
186                 BBT_Time       bbt;
187
188                 union {
189                         nframes_t      frames;
190                         double         seconds;
191                 };
192
193                 AnyTime() { type = Frames; frames = 0; }
194         };
195
196         struct AudioRange {
197                 nframes_t start;
198                 nframes_t end;
199                 uint32_t id;
200
201                 AudioRange (nframes_t s, nframes_t e, uint32_t i) : start (s), end (e) , id (i) {}
202
203                 nframes_t length() { return end - start + 1; }
204
205                 bool operator== (const AudioRange& other) const {
206                         return start == other.start && end == other.end && id == other.id;
207                 }
208
209                 bool equal (const AudioRange& other) const {
210                         return start == other.start && end == other.end;
211                 }
212
213                 OverlapType coverage (nframes_t s, nframes_t e) const {
214                         return ARDOUR::coverage (start, end, s, e);
215                 }
216         };
217
218         struct MusicRange {
219                 BBT_Time start;
220                 BBT_Time end;
221                 uint32_t id;
222
223                 MusicRange (BBT_Time& s, BBT_Time& e, uint32_t i)
224                         : start (s), end (e), id (i) {}
225
226                 bool operator== (const MusicRange& other) const {
227                         return start == other.start && end == other.end && id == other.id;
228                 }
229
230                 bool equal (const MusicRange& other) const {
231                         return start == other.start && end == other.end;
232                 }
233         };
234
235         /*
236             Slowest = 6.6dB/sec falloff at update rate of 40ms
237             Slow    = 6.8dB/sec falloff at update rate of 40ms
238         */
239
240         enum MeterFalloff {
241                 MeterFalloffOff = 0,
242                 MeterFalloffSlowest = 1,
243                 MeterFalloffSlow = 2,
244                 MeterFalloffMedium = 3,
245                 MeterFalloffFast = 4,
246                 MeterFalloffFaster = 5,
247                 MeterFalloffFastest = 6
248         };
249
250         enum MeterHold {
251                 MeterHoldOff = 0,
252                 MeterHoldShort = 40,
253                 MeterHoldMedium = 100,
254                 MeterHoldLong = 200
255         };
256
257         enum EditMode {
258                 Slide,
259                 Splice,
260                 Lock
261         };
262
263         enum RegionPoint {
264                 Start,
265                 End,
266                 SyncPoint
267         };
268
269         enum Placement {
270                 PreFader,
271                 PostFader
272         };
273
274         enum MonitorModel {
275                 HardwareMonitoring,
276                 SoftwareMonitoring,
277                 ExternalMonitoring
278         };
279
280         enum DenormalModel {
281                 DenormalNone,
282                 DenormalFTZ,
283                 DenormalDAZ,
284                 DenormalFTZDAZ
285         };
286
287         enum RemoteModel {
288                 UserOrdered,
289                 MixerOrdered,
290                 EditorOrdered
291         };
292
293         enum CrossfadeModel {
294                 FullCrossfade,
295                 ShortCrossfade
296         };
297
298         enum LayerModel {
299                 LaterHigher,
300                 MoveAddHigher,
301                 AddHigher
302         };
303
304         enum ListenPosition {
305                 AfterFaderListen,
306                 PreFaderListen
307         };
308
309         enum AutoConnectOption {
310                 ManualConnect = 0x0,
311                 AutoConnectPhysical = 0x1,
312                 AutoConnectMaster = 0x2
313         };
314
315         struct InterThreadInfo {
316                 InterThreadInfo () : done (false), cancel (false), progress (0), thread (0) {}
317                         
318                 volatile bool  done;
319                 volatile bool  cancel;
320                 volatile float progress;
321                 pthread_t      thread;
322         };
323
324         enum SampleFormat {
325                 FormatFloat = 0,
326                 FormatInt24,
327                 FormatInt16
328         };
329
330         enum CDMarkerFormat {
331                 CDMarkerNone,
332                 CDMarkerCUE,
333                 CDMarkerTOC
334         };
335
336         enum HeaderFormat {
337                 BWF,
338                 WAVE,
339                 WAVE64,
340                 CAF,
341                 AIFF,
342                 iXML,
343                 RF64
344         };
345
346         struct PeakData {
347                 typedef Sample PeakDatum;
348
349                 PeakDatum min;
350                 PeakDatum max;
351         };
352
353         enum PluginType {
354                 AudioUnit,
355                 LADSPA,
356                 LV2,
357                 VST
358         };
359
360         enum RunContext {
361                 ButlerContext = 0,
362                 TransportContext,
363                 ExportContext
364         };
365
366         enum SyncSource {
367                 JACK,
368                 MTC,
369                 MIDIClock
370         };
371
372         enum ShuttleBehaviour {
373                 Sprung,
374                 Wheel
375         };
376
377         enum ShuttleUnits {
378                 Percentage,
379                 Semitones
380         };
381
382         typedef std::vector<boost::shared_ptr<Source> > SourceList;
383
384         enum SrcQuality {
385                 SrcBest,
386                 SrcGood,
387                 SrcQuick,
388                 SrcFast,
389                 SrcFastest
390         };
391
392         struct TimeFXRequest : public InterThreadInfo {
393                 TimeFXRequest()
394                         : time_fraction(0), pitch_fraction(0),
395                         quick_seek(false), antialias(false),  opts(0) {}
396                 float time_fraction;
397                 float pitch_fraction;
398                 /* SoundTouch */
399                 bool  quick_seek;
400                 bool  antialias;
401                 /* RubberBand */
402                 int   opts; // really RubberBandStretcher::Options
403         };
404
405         typedef std::list<nframes64_t> AnalysisFeatureList;
406
407         typedef std::list<boost::shared_ptr<Route> >      RouteList;
408
409         class Bundle;
410         typedef std::vector<boost::shared_ptr<Bundle> > BundleList;
411
412         enum WaveformScale {
413                 Linear,
414                 Logarithmic
415         };
416
417         enum WaveformShape {
418                 Traditional,
419                 Rectified
420         };
421
422         enum QuantizeType {
423                 Plain,
424                 Legato,
425                 Groove
426         };
427
428         struct CleanupReport {
429                 std::vector<std::string> paths;
430                 int64_t                  space;
431         };
432
433         /** A struct used to describe changes to processors in a route.
434          *  This is useful because objects that respond to a change in processors
435          *  can optimise what work they do based on details of what has changed.
436         */
437         struct RouteProcessorChange {
438                 enum Type {
439                         GeneralChange = 0x0,
440                         MeterPointChange = 0x1
441                 };
442
443                 RouteProcessorChange () : type (GeneralChange), meter_visibly_changed (true)
444                 {}
445
446                 RouteProcessorChange (Type t) : type (t), meter_visibly_changed (true)
447                 {}
448
449                 RouteProcessorChange (Type t, bool m) : type (t), meter_visibly_changed (m)
450                 {}
451
452                 /** type of change; "GeneralChange" means anything could have changed */
453                 Type type;
454                 /** true if, when a MeterPointChange has occurred, the change is visible to the user */
455                 bool meter_visibly_changed;
456         };
457
458         struct BusProfile {
459             AutoConnectOption input_ac;      /* override the RC config for input auto-connection */
460             AutoConnectOption output_ac;     /* override the RC config for output auto-connection */
461             uint32_t master_out_channels;    /* how many channels for the master bus */
462             uint32_t requested_physical_in;  /* now many of the available physical inputs to consider usable */
463             uint32_t requested_physical_out; /* now many of the available physical inputs to consider usable */
464         };
465
466 } // namespace ARDOUR
467
468
469 /* these cover types declared above in this header. See enums.cc
470    for the definitions.
471 */
472
473 std::istream& operator>>(std::istream& o, ARDOUR::SampleFormat& sf);
474 std::istream& operator>>(std::istream& o, ARDOUR::HeaderFormat& sf);
475 std::istream& operator>>(std::istream& o, ARDOUR::AutoConnectOption& sf);
476 std::istream& operator>>(std::istream& o, ARDOUR::EditMode& sf);
477 std::istream& operator>>(std::istream& o, ARDOUR::MonitorModel& sf);
478 std::istream& operator>>(std::istream& o, ARDOUR::RemoteModel& sf);
479 std::istream& operator>>(std::istream& o, ARDOUR::ListenPosition& sf);
480 std::istream& operator>>(std::istream& o, ARDOUR::LayerModel& sf);
481 std::istream& operator>>(std::istream& o, ARDOUR::CrossfadeModel& sf);
482 std::istream& operator>>(std::istream& o, ARDOUR::SyncSource& sf);
483 std::istream& operator>>(std::istream& o, ARDOUR::ShuttleBehaviour& sf);
484 std::istream& operator>>(std::istream& o, ARDOUR::ShuttleUnits& sf);
485 std::istream& operator>>(std::istream& o, ARDOUR::TimecodeFormat& sf);
486 std::istream& operator>>(std::istream& o, ARDOUR::DenormalModel& sf);
487 std::istream& operator>>(std::istream& o, ARDOUR::WaveformScale& sf);
488 std::istream& operator>>(std::istream& o, ARDOUR::WaveformShape& sf);
489
490 std::ostream& operator<<(std::ostream& o, const ARDOUR::SampleFormat& sf);
491 std::ostream& operator<<(std::ostream& o, const ARDOUR::HeaderFormat& sf);
492 std::ostream& operator<<(std::ostream& o, const ARDOUR::AutoConnectOption& sf);
493 std::ostream& operator<<(std::ostream& o, const ARDOUR::EditMode& sf);
494 std::ostream& operator<<(std::ostream& o, const ARDOUR::MonitorModel& sf);
495 std::ostream& operator<<(std::ostream& o, const ARDOUR::RemoteModel& sf);
496 std::ostream& operator<<(std::ostream& o, const ARDOUR::ListenPosition& sf);
497 std::ostream& operator<<(std::ostream& o, const ARDOUR::LayerModel& sf);
498 std::ostream& operator<<(std::ostream& o, const ARDOUR::CrossfadeModel& sf);
499 std::ostream& operator<<(std::ostream& o, const ARDOUR::SyncSource& sf);
500 std::ostream& operator<<(std::ostream& o, const ARDOUR::ShuttleBehaviour& sf);
501 std::ostream& operator<<(std::ostream& o, const ARDOUR::ShuttleUnits& sf);
502 std::ostream& operator<<(std::ostream& o, const ARDOUR::TimecodeFormat& sf);
503 std::ostream& operator<<(std::ostream& o, const ARDOUR::DenormalModel& sf);
504 std::ostream& operator<<(std::ostream& o, const ARDOUR::WaveformScale& sf);
505 std::ostream& operator<<(std::ostream& o, const ARDOUR::WaveformShape& sf);
506
507 static inline ARDOUR::nframes64_t
508 session_frame_to_track_frame (ARDOUR::nframes64_t session_frame, double speed)
509 {
510         return (ARDOUR::nframes64_t)( (double)session_frame * speed );
511 }
512
513 static inline ARDOUR::nframes64_t
514 track_frame_to_session_frame (ARDOUR::nframes64_t track_frame, double speed)
515 {
516         return (ARDOUR::nframes64_t)( (double)track_frame / speed );
517 }
518
519 /* for now, break the rules and use "using" to make these "global" */
520
521 using ARDOUR::nframes_t;
522 using ARDOUR::nframes64_t;
523
524
525 #endif /* __ardour_types_h__ */
526