rollback to 3428, before the mysterious removal of libs/* at 3431/3432
[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
55         typedef jack_default_audio_sample_t Sample;
56         typedef float                       pan_t;
57         typedef float                       gain_t;
58         typedef uint32_t                    layer_t;
59         typedef uint64_t                    microseconds_t;
60         typedef uint32_t                    nframes_t;
61
62         enum IOChange {
63                 NoChange = 0,
64                 ConfigurationChanged = 0x1,
65                 ConnectionsChanged = 0x2
66         };
67
68         enum OverlapType {
69                 OverlapNone,      // no overlap
70                 OverlapInternal,  // the overlap is 100% with the object
71                 OverlapStart,     // overlap covers start, but ends within
72                 OverlapEnd,       // overlap begins within and covers end 
73                 OverlapExternal   // overlap extends to (at least) begin+end
74         };
75
76         OverlapType coverage (nframes_t start_a, nframes_t end_a,
77                               nframes_t start_b, nframes_t end_b);
78
79         /** See parameter.h
80          * XXX: I don't think/hope these hex values matter anymore.
81          */
82         enum AutomationType {
83                 NullAutomation = 0x0,
84                 GainAutomation = 0x1,
85                 PanAutomation = 0x2,
86                 PluginAutomation = 0x4,
87                 SoloAutomation = 0x8,
88                 MuteAutomation = 0x10,
89                 MidiCCAutomation = 0x20,
90                 MidiPgmChangeAutomation = 0x21,
91                 MidiPitchBenderAutomation = 0x22,
92                 MidiChannelAftertouchAutomation = 0x23,
93                 FadeInAutomation = 0x40,
94                 FadeOutAutomation = 0x80,
95                 EnvelopeAutomation = 0x100
96         };
97
98         enum AutoState {
99                 Off = 0x0,
100                 Write = 0x1,
101                 Touch = 0x2,
102                 Play = 0x4
103         };
104
105         std::string auto_state_to_string (AutoState);
106         AutoState string_to_auto_state (std::string);
107
108         enum AutoStyle {
109                 Absolute = 0x1,
110                 Trim = 0x2
111         };
112
113         std::string auto_style_to_string (AutoStyle);
114         AutoStyle string_to_auto_style (std::string);
115
116         enum AlignStyle {
117                 CaptureTime,
118                 ExistingMaterial
119         };
120
121         enum MeterPoint {
122                 MeterInput,
123                 MeterPreFader,
124                 MeterPostFader
125         };
126
127         enum TrackMode {
128                 Normal,
129                 Destructive
130         };
131         
132         enum NoteMode {
133                 Sustained,
134                 Percussive
135         };
136         
137         enum ChannelMode {
138                 AllChannels = 0, ///< Pass through all channel information unmodified
139                 FilterChannels,  ///< Ignore events on certain channels
140                 ForceChannel     ///< Force all events to a certain channel
141         };
142
143         enum EventTimeUnit {
144                 Frames,
145                 Beats
146         };
147         
148         struct BBT_Time {
149             uint32_t bars;
150             uint32_t beats;
151             uint32_t ticks;
152
153             BBT_Time() {
154                     bars = 1;
155                     beats = 1;
156                     ticks = 0;
157             }
158
159             /* we can't define arithmetic operators for BBT_Time, because
160                the results depend on a TempoMap, but we can define 
161                a useful check on the less-than condition.
162             */
163
164             bool operator< (const BBT_Time& other) const {
165                     return bars < other.bars || 
166                             (bars == other.bars && beats < other.beats) ||
167                             (bars == other.bars && beats == other.beats && ticks < other.ticks);
168             }
169
170             bool operator== (const BBT_Time& other) const {
171                     return bars == other.bars && beats == other.beats && ticks == other.ticks;
172             }
173             
174         };
175         enum SmpteFormat {
176                 smpte_23976,
177                 smpte_24,
178                 smpte_24976,
179                 smpte_25,
180                 smpte_2997,
181                 smpte_2997drop,
182                 smpte_30,
183                 smpte_30drop,
184                 smpte_5994,
185                 smpte_60
186         };
187
188         struct AnyTime {
189             enum Type {
190                     SMPTE,
191                     BBT,
192                     Frames,
193                     Seconds
194             };
195
196             Type type;
197
198             SMPTE::Time    smpte;
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 Change {
283                 range_guarantee = ~0
284         };
285
286
287         enum Placement {
288                 PreFader,
289                 PostFader
290         };
291
292         enum MonitorModel {
293                 HardwareMonitoring,
294                 SoftwareMonitoring,
295                 ExternalMonitoring
296         };
297
298         enum DenormalModel {
299                 DenormalNone,
300                 DenormalFTZ,
301                 DenormalDAZ,
302                 DenormalFTZDAZ
303         };
304
305         enum RemoteModel {
306                 UserOrdered,
307                 MixerOrdered,
308                 EditorOrdered
309         };
310
311         enum CrossfadeModel {
312                 FullCrossfade,
313                 ShortCrossfade
314         };
315         
316         enum LayerModel {
317                 LaterHigher,
318                 MoveAddHigher,
319                 AddHigher
320         };
321
322         enum SoloModel {
323                 InverseMute,
324                 SoloBus
325         };
326
327         enum AutoConnectOption {
328                 AutoConnectPhysical = 0x1,
329                 AutoConnectMaster = 0x2
330         };
331
332         struct InterThreadInfo {
333             volatile bool  done;
334             volatile bool  cancel;
335             volatile float progress;
336             pthread_t      thread;
337         };
338
339         enum SampleFormat {
340                 FormatFloat = 0,
341                 FormatInt24,
342                 FormatInt16
343         };
344
345
346         enum HeaderFormat {
347                 BWF,
348                 WAVE,
349                 WAVE64,
350                 CAF,
351                 AIFF,
352                 iXML,
353                 RF64
354         };
355
356         struct PeakData {
357             typedef Sample PeakDatum;
358             
359             PeakDatum min;
360             PeakDatum max;
361         };
362         
363         enum PluginType {
364                 AudioUnit,
365                 LADSPA,
366                 LV2,
367                 VST
368         };
369
370         enum SlaveSource {
371                 None = 0,
372                 MTC,
373                 JACK
374         };
375
376         enum ShuttleBehaviour {
377                 Sprung,
378                 Wheel
379         };
380
381         enum ShuttleUnits {
382                 Percentage,
383                 Semitones
384         };
385
386         typedef std::vector<boost::shared_ptr<Source> > SourceList;
387
388         enum SrcQuality {
389                 SrcBest,
390                 SrcGood,
391                 SrcQuick,
392                 SrcFast,
393                 SrcFastest
394         };
395
396         struct TimeFXRequest : public InterThreadInfo {
397                 TimeFXRequest() : time_fraction(0), pitch_fraction(0),
398                         quick_seek(false), antialias(false),  opts(0) {}
399             float time_fraction;
400             float pitch_fraction;
401             /* SoundTouch */
402             bool  quick_seek; 
403             bool  antialias;  
404             /* RubberBand */
405             int   opts; // really RubberBandStretcher::Options
406         };
407
408         typedef std::list<nframes64_t> AnalysisFeatureList;
409
410 } // namespace ARDOUR
411
412 std::istream& operator>>(std::istream& o, ARDOUR::SampleFormat& sf);
413 std::istream& operator>>(std::istream& o, ARDOUR::HeaderFormat& sf);
414 std::istream& operator>>(std::istream& o, ARDOUR::AutoConnectOption& sf);
415 std::istream& operator>>(std::istream& o, ARDOUR::EditMode& sf);
416 std::istream& operator>>(std::istream& o, ARDOUR::MonitorModel& sf);
417 std::istream& operator>>(std::istream& o, ARDOUR::RemoteModel& sf);
418 std::istream& operator>>(std::istream& o, ARDOUR::SoloModel& sf);
419 std::istream& operator>>(std::istream& o, ARDOUR::LayerModel& sf);
420 std::istream& operator>>(std::istream& o, ARDOUR::CrossfadeModel& sf);
421 std::istream& operator>>(std::istream& o, ARDOUR::SlaveSource& sf);
422 std::istream& operator>>(std::istream& o, ARDOUR::ShuttleBehaviour& sf);
423 std::istream& operator>>(std::istream& o, ARDOUR::ShuttleUnits& sf);
424 std::istream& operator>>(std::istream& o, ARDOUR::SmpteFormat& sf);
425 std::istream& operator>>(std::istream& o, ARDOUR::DenormalModel& sf);
426
427 using ARDOUR::nframes_t;
428
429 static inline nframes_t
430 session_frame_to_track_frame (nframes_t session_frame, double speed)
431 {
432         return (nframes_t)( (double)session_frame * speed );
433 }
434
435 static inline nframes_t
436 track_frame_to_session_frame (nframes_t track_frame, double speed)
437 {
438         return (nframes_t)( (double)track_frame / speed );
439 }
440
441
442 #endif /* __ardour_types_h__ */
443