* Add SysEx Support to MidiModel / SMF
[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         enum EventTimeUnit {
152                 Frames,
153                 Beats
154         };
155
156         struct BBT_Time {
157             uint32_t bars;
158             uint32_t beats;
159             uint32_t ticks;
160
161             BBT_Time() {
162                     bars = 1;
163                     beats = 1;
164                     ticks = 0;
165             }
166
167             /* we can't define arithmetic operators for BBT_Time, because
168                the results depend on a TempoMap, but we can define
169                a useful check on the less-than condition.
170             */
171
172             bool operator< (const BBT_Time& other) const {
173                     return bars < other.bars ||
174                             (bars == other.bars && beats < other.beats) ||
175                             (bars == other.bars && beats == other.beats && ticks < other.ticks);
176             }
177
178             bool operator== (const BBT_Time& other) const {
179                     return bars == other.bars && beats == other.beats && ticks == other.ticks;
180             }
181
182         };
183         enum SmpteFormat {
184                 smpte_23976,
185                 smpte_24,
186                 smpte_24976,
187                 smpte_25,
188                 smpte_2997,
189                 smpte_2997drop,
190                 smpte_30,
191                 smpte_30drop,
192                 smpte_5994,
193                 smpte_60
194         };
195
196         struct AnyTime {
197             enum Type {
198                     SMPTE,
199                     BBT,
200                     Frames,
201                     Seconds
202             };
203
204             Type type;
205
206             SMPTE::Time    smpte;
207             BBT_Time       bbt;
208
209             union {
210                 nframes_t      frames;
211                 double         seconds;
212             };
213
214             AnyTime() { type = Frames; frames = 0; }
215         };
216
217         struct AudioRange {
218             nframes_t start;
219             nframes_t end;
220             uint32_t id;
221
222             AudioRange (nframes_t s, nframes_t e, uint32_t i) : start (s), end (e) , id (i) {}
223
224             nframes_t length() { return end - start + 1; }
225
226             bool operator== (const AudioRange& other) const {
227                     return start == other.start && end == other.end && id == other.id;
228             }
229
230             bool equal (const AudioRange& other) const {
231                     return start == other.start && end == other.end;
232             }
233
234             OverlapType coverage (nframes_t s, nframes_t e) const {
235                     return ARDOUR::coverage (start, end, s, e);
236             }
237         };
238
239         struct MusicRange {
240             BBT_Time start;
241             BBT_Time end;
242             uint32_t id;
243
244             MusicRange (BBT_Time& s, BBT_Time& e, uint32_t i)
245                     : start (s), end (e), id (i) {}
246
247             bool operator== (const MusicRange& other) const {
248                     return start == other.start && end == other.end && id == other.id;
249             }
250
251             bool equal (const MusicRange& other) const {
252                     return start == other.start && end == other.end;
253             }
254         };
255
256         /*
257             Slowest = 6.6dB/sec falloff at update rate of 40ms
258             Slow    = 6.8dB/sec falloff at update rate of 40ms
259         */
260
261         enum MeterFalloff {
262                 MeterFalloffOff = 0,
263                 MeterFalloffSlowest = 1,
264                 MeterFalloffSlow = 2,
265                 MeterFalloffMedium = 3,
266                 MeterFalloffFast = 4,
267                 MeterFalloffFaster = 5,
268                 MeterFalloffFastest = 6
269         };
270
271         enum MeterHold {
272                 MeterHoldOff = 0,
273                 MeterHoldShort = 40,
274                 MeterHoldMedium = 100,
275                 MeterHoldLong = 200
276         };
277
278         enum EditMode {
279                 Slide,
280                 Splice,
281                 Lock
282         };
283
284         enum RegionPoint {
285             Start,
286             End,
287             SyncPoint
288         };
289
290         enum Change {
291                 range_guarantee = ~0
292         };
293
294
295         enum Placement {
296                 PreFader,
297                 PostFader
298         };
299
300         enum MonitorModel {
301                 HardwareMonitoring,
302                 SoftwareMonitoring,
303                 ExternalMonitoring
304         };
305
306         enum DenormalModel {
307                 DenormalNone,
308                 DenormalFTZ,
309                 DenormalDAZ,
310                 DenormalFTZDAZ
311         };
312
313         enum RemoteModel {
314                 UserOrdered,
315                 MixerOrdered,
316                 EditorOrdered
317         };
318
319         enum CrossfadeModel {
320                 FullCrossfade,
321                 ShortCrossfade
322         };
323
324         enum LayerModel {
325                 LaterHigher,
326                 MoveAddHigher,
327                 AddHigher
328         };
329
330         enum SoloModel {
331                 InverseMute,
332                 SoloBus
333         };
334
335         enum AutoConnectOption {
336                 AutoConnectPhysical = 0x1,
337                 AutoConnectMaster = 0x2
338         };
339
340         struct InterThreadInfo {
341             volatile bool  done;
342             volatile bool  cancel;
343             volatile float progress;
344             pthread_t      thread;
345         };
346
347         enum SampleFormat {
348                 FormatFloat = 0,
349                 FormatInt24,
350                 FormatInt16
351         };
352
353         enum CDMarkerFormat {
354                 CDMarkerNone,
355                 CDMarkerCUE,
356                 CDMarkerTOC
357         };
358
359         enum HeaderFormat {
360                 BWF,
361                 WAVE,
362                 WAVE64,
363                 CAF,
364                 AIFF,
365                 iXML,
366                 RF64
367         };
368
369         struct PeakData {
370             typedef Sample PeakDatum;
371
372             PeakDatum min;
373             PeakDatum max;
374         };
375
376         enum PluginType {
377                 AudioUnit,
378                 LADSPA,
379                 LV2,
380                 VST
381         };
382         
383         enum RunContext {
384                 ButlerContext = 0,
385                 TransportContext,
386                 ExportContext
387         };
388
389         enum SlaveSource {
390                 None = 0,
391                 MTC,
392                 JACK,
393                 MIDIClock
394         };
395
396         enum ShuttleBehaviour {
397                 Sprung,
398                 Wheel
399         };
400
401         enum ShuttleUnits {
402                 Percentage,
403                 Semitones
404         };
405
406         typedef std::vector<boost::shared_ptr<Source> > SourceList;
407
408         enum SrcQuality {
409                 SrcBest,
410                 SrcGood,
411                 SrcQuick,
412                 SrcFast,
413                 SrcFastest
414         };
415
416         struct TimeFXRequest : public InterThreadInfo {
417                 TimeFXRequest() : time_fraction(0), pitch_fraction(0),
418                         quick_seek(false), antialias(false),  opts(0) {}
419             float time_fraction;
420             float pitch_fraction;
421             /* SoundTouch */
422             bool  quick_seek;
423             bool  antialias;
424             /* RubberBand */
425             int   opts; // really RubberBandStretcher::Options
426         };
427
428         typedef std::list<nframes64_t> AnalysisFeatureList;
429
430         typedef std::list<boost::shared_ptr<Route> >      RouteList;
431
432         class Bundle;
433         typedef std::vector<boost::shared_ptr<Bundle> > BundleList;
434
435 } // namespace ARDOUR
436
437 std::istream& operator>>(std::istream& o, ARDOUR::SampleFormat& sf);
438 std::istream& operator>>(std::istream& o, ARDOUR::HeaderFormat& sf);
439 std::istream& operator>>(std::istream& o, ARDOUR::AutoConnectOption& sf);
440 std::istream& operator>>(std::istream& o, ARDOUR::EditMode& sf);
441 std::istream& operator>>(std::istream& o, ARDOUR::MonitorModel& sf);
442 std::istream& operator>>(std::istream& o, ARDOUR::RemoteModel& sf);
443 std::istream& operator>>(std::istream& o, ARDOUR::SoloModel& sf);
444 std::istream& operator>>(std::istream& o, ARDOUR::LayerModel& sf);
445 std::istream& operator>>(std::istream& o, ARDOUR::CrossfadeModel& sf);
446 std::istream& operator>>(std::istream& o, ARDOUR::SlaveSource& sf);
447 std::istream& operator>>(std::istream& o, ARDOUR::ShuttleBehaviour& sf);
448 std::istream& operator>>(std::istream& o, ARDOUR::ShuttleUnits& sf);
449 std::istream& operator>>(std::istream& o, ARDOUR::SmpteFormat& sf);
450 std::istream& operator>>(std::istream& o, ARDOUR::DenormalModel& sf);
451
452 using ARDOUR::nframes_t;
453
454 static inline nframes_t
455 session_frame_to_track_frame (nframes_t session_frame, double speed)
456 {
457         return (nframes_t)( (double)session_frame * speed );
458 }
459
460 static inline nframes_t
461 track_frame_to_session_frame (nframes_t track_frame, double speed)
462 {
463         return (nframes_t)( (double)track_frame / speed );
464 }
465
466
467 #endif /* __ardour_types_h__ */
468