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