Fix sketchy casts.
[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/smpte.h"
35 #include "pbd/id.h"
36
37 #include <map>
38
39 #if __GNUC__ < 3
40
41 typedef int intptr_t;
42 #endif
43
44 /* eventually, we'd like everything (including JACK) to
45    move to this. for now, its a dedicated type.
46 */
47
48 typedef int64_t                    nframes64_t;
49
50 namespace ARDOUR {
51
52         class Source;
53         class AudioSource;
54         class Route;
55
56         typedef jack_default_audio_sample_t Sample;
57         typedef float                       pan_t;
58         typedef float                       gain_t;
59         typedef uint32_t                    layer_t;
60         typedef uint64_t                    microseconds_t;
61         typedef uint32_t                    nframes_t;
62
63         /** "Session frames", frames relative to the session timeline.
64          * Everything related to transport position etc. should be of this type.
65          * We might want to make this a compile time option for 32-bitters who
66          * don't want to pay for extremely long session times they don't need...
67          */
68         typedef int64_t sframes_t;
69
70         enum IOChange {
71                 NoChange = 0,
72                 ConfigurationChanged = 0x1,
73                 ConnectionsChanged = 0x2
74         };
75
76         enum OverlapType {
77                 OverlapNone,      // no overlap
78                 OverlapInternal,  // the overlap is 100% with the object
79                 OverlapStart,     // overlap covers start, but ends within
80                 OverlapEnd,       // overlap begins within and covers end
81                 OverlapExternal   // overlap extends to (at least) begin+end
82         };
83
84         OverlapType coverage (nframes_t start_a, nframes_t end_a,
85                               nframes_t start_b, nframes_t end_b);
86
87         /** See parameter.h
88          * XXX: I don't think/hope these hex values matter anymore.
89          */
90         enum AutomationType {
91                 NullAutomation = 0x0,
92                 GainAutomation = 0x1,
93                 PanAutomation = 0x2,
94                 PluginAutomation = 0x4,
95                 SoloAutomation = 0x8,
96                 MuteAutomation = 0x10,
97                 MidiCCAutomation = 0x20,
98                 MidiPgmChangeAutomation = 0x21,
99                 MidiPitchBenderAutomation = 0x22,
100                 MidiChannelPressureAutomation = 0x23,
101                 MidiSystemExclusiveAutomation = 0x24,
102                 FadeInAutomation = 0x40,
103                 FadeOutAutomation = 0x80,
104                 EnvelopeAutomation = 0x100
105         };
106
107         enum AutoState {
108                 Off = 0x0,
109                 Write = 0x1,
110                 Touch = 0x2,
111                 Play = 0x4
112         };
113
114         std::string auto_state_to_string (AutoState);
115         AutoState string_to_auto_state (std::string);
116
117         enum AutoStyle {
118                 Absolute = 0x1,
119                 Trim = 0x2
120         };
121
122         std::string auto_style_to_string (AutoStyle);
123         AutoStyle string_to_auto_style (std::string);
124
125         enum AlignStyle {
126                 CaptureTime,
127                 ExistingMaterial
128         };
129
130         enum MeterPoint {
131                 MeterInput,
132                 MeterPreFader,
133                 MeterPostFader
134         };
135
136         enum TrackMode {
137                 Normal,
138                 NonLayered,
139                 Destructive
140         };
141
142         enum NoteMode {
143                 Sustained,
144                 Percussive
145         };
146
147         enum ChannelMode {
148                 AllChannels = 0, ///< Pass through all channel information unmodified
149                 FilterChannels,  ///< Ignore events on certain channels
150                 ForceChannel     ///< Force all events to a certain channel
151         };
152
153         enum ColorMode {
154                 MeterColors = 0,
155                 ChannelColors,
156                 TrackColor
157         };
158
159         struct BBT_Time {
160                 uint32_t bars;
161                 uint32_t beats;
162                 uint32_t ticks;
163
164                 BBT_Time() {
165                         bars = 1;
166                         beats = 1;
167                         ticks = 0;
168                 }
169
170                 /* we can't define arithmetic operators for BBT_Time, because
171                    the results depend on a TempoMap, but we can define
172                    a useful check on the less-than condition.
173                    */
174
175                 bool operator< (const BBT_Time& other) const {
176                         return bars < other.bars ||
177                                 (bars == other.bars && beats < other.beats) ||
178                                 (bars == other.bars && beats == other.beats && ticks < other.ticks);
179                 }
180
181                 bool operator== (const BBT_Time& other) const {
182                         return bars == other.bars && beats == other.beats && ticks == other.ticks;
183                 }
184
185         };
186         enum SmpteFormat {
187                 smpte_23976,
188                 smpte_24,
189                 smpte_24976,
190                 smpte_25,
191                 smpte_2997,
192                 smpte_2997drop,
193                 smpte_30,
194                 smpte_30drop,
195                 smpte_5994,
196                 smpte_60
197         };
198
199         struct AnyTime {
200                 enum Type {
201                         SMPTE,
202                         BBT,
203                         Frames,
204                         Seconds
205                 };
206
207                 Type type;
208
209                 SMPTE::Time    smpte;
210                 BBT_Time       bbt;
211
212                 union {
213                         nframes_t      frames;
214                         double         seconds;
215                 };
216
217                 AnyTime() { type = Frames; frames = 0; }
218         };
219
220         struct AudioRange {
221                 nframes_t start;
222                 nframes_t end;
223                 uint32_t id;
224
225                 AudioRange (nframes_t s, nframes_t e, uint32_t i) : start (s), end (e) , id (i) {}
226
227                 nframes_t length() { return end - start + 1; }
228
229                 bool operator== (const AudioRange& other) const {
230                         return start == other.start && end == other.end && id == other.id;
231                 }
232
233                 bool equal (const AudioRange& other) const {
234                         return start == other.start && end == other.end;
235                 }
236
237                 OverlapType coverage (nframes_t s, nframes_t e) const {
238                         return ARDOUR::coverage (start, end, s, e);
239                 }
240         };
241
242         struct MusicRange {
243                 BBT_Time start;
244                 BBT_Time end;
245                 uint32_t id;
246
247                 MusicRange (BBT_Time& s, BBT_Time& e, uint32_t i)
248                         : start (s), end (e), id (i) {}
249
250                 bool operator== (const MusicRange& other) const {
251                         return start == other.start && end == other.end && id == other.id;
252                 }
253
254                 bool equal (const MusicRange& other) const {
255                         return start == other.start && end == other.end;
256                 }
257         };
258
259         /*
260             Slowest = 6.6dB/sec falloff at update rate of 40ms
261             Slow    = 6.8dB/sec falloff at update rate of 40ms
262         */
263
264         enum MeterFalloff {
265                 MeterFalloffOff = 0,
266                 MeterFalloffSlowest = 1,
267                 MeterFalloffSlow = 2,
268                 MeterFalloffMedium = 3,
269                 MeterFalloffFast = 4,
270                 MeterFalloffFaster = 5,
271                 MeterFalloffFastest = 6
272         };
273
274         enum MeterHold {
275                 MeterHoldOff = 0,
276                 MeterHoldShort = 40,
277                 MeterHoldMedium = 100,
278                 MeterHoldLong = 200
279         };
280
281         enum EditMode {
282                 Slide,
283                 Splice,
284                 Lock
285         };
286
287         enum RegionPoint {
288                 Start,
289                 End,
290                 SyncPoint
291         };
292
293         enum Change {
294                 range_guarantee = ~0
295         };
296
297
298         enum Placement {
299                 PreFader,
300                 PostFader
301         };
302
303         enum MonitorModel {
304                 HardwareMonitoring,
305                 SoftwareMonitoring,
306                 ExternalMonitoring
307         };
308
309         enum DenormalModel {
310                 DenormalNone,
311                 DenormalFTZ,
312                 DenormalDAZ,
313                 DenormalFTZDAZ
314         };
315
316         enum RemoteModel {
317                 UserOrdered,
318                 MixerOrdered,
319                 EditorOrdered
320         };
321
322         enum CrossfadeModel {
323                 FullCrossfade,
324                 ShortCrossfade
325         };
326
327         enum LayerModel {
328                 LaterHigher,
329                 MoveAddHigher,
330                 AddHigher
331         };
332
333         enum ListenPosition {
334                 AfterFaderListen,
335                 PreFaderListen
336         };
337
338         enum AutoConnectOption {
339                 ManualConnect = 0x0,
340                 AutoConnectPhysical = 0x1,
341                 AutoConnectMaster = 0x2
342         };
343
344         struct InterThreadInfo {
345                 volatile bool  done;
346                 volatile bool  cancel;
347                 volatile float progress;
348                 pthread_t      thread;
349         };
350
351         enum SampleFormat {
352                 FormatFloat = 0,
353                 FormatInt24,
354                 FormatInt16
355         };
356
357         enum CDMarkerFormat {
358                 CDMarkerNone,
359                 CDMarkerCUE,
360                 CDMarkerTOC
361         };
362
363         enum HeaderFormat {
364                 BWF,
365                 WAVE,
366                 WAVE64,
367                 CAF,
368                 AIFF,
369                 iXML,
370                 RF64
371         };
372
373         struct PeakData {
374                 typedef Sample PeakDatum;
375
376                 PeakDatum min;
377                 PeakDatum max;
378         };
379
380         enum PluginType {
381                 AudioUnit,
382                 LADSPA,
383                 LV2,
384                 VST
385         };
386
387         enum RunContext {
388                 ButlerContext = 0,
389                 TransportContext,
390                 ExportContext
391         };
392
393         enum SlaveSource {
394                 None = 0,
395                 MTC,
396                 JACK,
397                 MIDIClock
398         };
399
400         enum ShuttleBehaviour {
401                 Sprung,
402                 Wheel
403         };
404
405         enum ShuttleUnits {
406                 Percentage,
407                 Semitones
408         };
409
410         typedef std::vector<boost::shared_ptr<Source> > SourceList;
411
412         enum SrcQuality {
413                 SrcBest,
414                 SrcGood,
415                 SrcQuick,
416                 SrcFast,
417                 SrcFastest
418         };
419
420         struct TimeFXRequest : public InterThreadInfo {
421                 TimeFXRequest()
422                         : time_fraction(0), pitch_fraction(0),
423                         quick_seek(false), antialias(false),  opts(0) {}
424                 float time_fraction;
425                 float pitch_fraction;
426                 /* SoundTouch */
427                 bool  quick_seek;
428                 bool  antialias;
429                 /* RubberBand */
430                 int   opts; // really RubberBandStretcher::Options
431         };
432
433         typedef std::list<nframes64_t> AnalysisFeatureList;
434
435         typedef std::list<boost::shared_ptr<Route> >      RouteList;
436
437         class Bundle;
438         typedef std::vector<boost::shared_ptr<Bundle> > BundleList;
439
440         enum WaveformScale {
441                 Linear,
442                 Logarithmic
443         };
444
445         enum WaveformShape {
446                 Traditional,
447                 Rectified
448         };
449
450         enum QuantizeType {
451                 Plain,
452                 Legato,
453                 Groove
454         };
455
456 } // namespace ARDOUR
457
458 std::istream& operator>>(std::istream& o, ARDOUR::SampleFormat& sf);
459 std::istream& operator>>(std::istream& o, ARDOUR::HeaderFormat& sf);
460 std::istream& operator>>(std::istream& o, ARDOUR::AutoConnectOption& sf);
461 std::istream& operator>>(std::istream& o, ARDOUR::EditMode& sf);
462 std::istream& operator>>(std::istream& o, ARDOUR::MonitorModel& sf);
463 std::istream& operator>>(std::istream& o, ARDOUR::RemoteModel& sf);
464 std::istream& operator>>(std::istream& o, ARDOUR::ListenPosition& sf);
465 std::istream& operator>>(std::istream& o, ARDOUR::LayerModel& sf);
466 std::istream& operator>>(std::istream& o, ARDOUR::CrossfadeModel& sf);
467 std::istream& operator>>(std::istream& o, ARDOUR::SlaveSource& sf);
468 std::istream& operator>>(std::istream& o, ARDOUR::ShuttleBehaviour& sf);
469 std::istream& operator>>(std::istream& o, ARDOUR::ShuttleUnits& sf);
470 std::istream& operator>>(std::istream& o, ARDOUR::SmpteFormat& sf);
471 std::istream& operator>>(std::istream& o, ARDOUR::DenormalModel& sf);
472 std::istream& operator>>(std::istream& o, ARDOUR::WaveformScale& sf);
473 std::istream& operator>>(std::istream& o, ARDOUR::WaveformShape& sf);
474
475 using ARDOUR::nframes_t;
476
477 static inline nframes_t
478 session_frame_to_track_frame (nframes_t session_frame, double speed)
479 {
480         return (nframes_t)( (double)session_frame * speed );
481 }
482
483 static inline nframes_t
484 track_frame_to_session_frame (nframes_t track_frame, double speed)
485 {
486         return (nframes_t)( (double)track_frame / speed );
487 }
488
489
490 #endif /* __ardour_types_h__ */
491