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