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