Note modes: note, percussion.
[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 parameter.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         enum NoteMode {
147                 Note,
148                 Percussion
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         };
277
278         enum RegionPoint { 
279             Start,
280             End,
281             SyncPoint
282         };
283
284         enum Change {
285                 range_guarantee = ~0
286         };
287
288
289         enum Placement {
290                 PreFader,
291                 PostFader
292         };
293
294         enum MonitorModel {
295                 HardwareMonitoring,
296                 SoftwareMonitoring,
297                 ExternalMonitoring,
298         };
299
300         enum DenormalModel {
301                 DenormalNone,
302                 DenormalFTZ,
303                 DenormalDAZ,
304                 DenormalFTZDAZ
305         };
306
307         enum RemoteModel {
308                 UserOrdered,
309                 MixerOrdered,
310                 EditorOrdered,
311         };
312
313         enum CrossfadeModel {
314                 FullCrossfade,
315                 ShortCrossfade
316         };
317         
318         enum LayerModel {
319                 LaterHigher,
320                 MoveAddHigher,
321                 AddHigher
322         };
323
324         enum SoloModel {
325                 InverseMute,
326                 SoloBus
327         };
328
329         enum AutoConnectOption {
330                 AutoConnectPhysical = 0x1,
331                 AutoConnectMaster = 0x2
332         };
333
334         struct InterThreadInfo {
335             volatile bool  done;
336             volatile bool  cancel;
337             volatile float progress;
338             pthread_t      thread;
339         };
340
341         enum SampleFormat {
342                 FormatFloat = 0,
343                 FormatInt24
344         };
345
346
347         enum HeaderFormat {
348                 BWF,
349                 WAVE,
350                 WAVE64,
351                 CAF,
352                 AIFF,
353                 iXML,
354                 RF64
355         };
356
357         struct PeakData {
358             typedef Sample PeakDatum;
359             
360             PeakDatum min;
361             PeakDatum max;
362         };
363         
364         enum PluginType {
365                 AudioUnit,
366                 LADSPA,
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 } // namespace ARDOUR
388
389 std::istream& operator>>(std::istream& o, ARDOUR::SampleFormat& sf);
390 std::istream& operator>>(std::istream& o, ARDOUR::HeaderFormat& sf);
391 std::istream& operator>>(std::istream& o, ARDOUR::AutoConnectOption& sf);
392 std::istream& operator>>(std::istream& o, ARDOUR::EditMode& sf);
393 std::istream& operator>>(std::istream& o, ARDOUR::MonitorModel& sf);
394 std::istream& operator>>(std::istream& o, ARDOUR::RemoteModel& sf);
395 std::istream& operator>>(std::istream& o, ARDOUR::SoloModel& sf);
396 std::istream& operator>>(std::istream& o, ARDOUR::LayerModel& sf);
397 std::istream& operator>>(std::istream& o, ARDOUR::CrossfadeModel& sf);
398 std::istream& operator>>(std::istream& o, ARDOUR::SlaveSource& sf);
399 std::istream& operator>>(std::istream& o, ARDOUR::ShuttleBehaviour& sf);
400 std::istream& operator>>(std::istream& o, ARDOUR::ShuttleUnits& sf);
401 std::istream& operator>>(std::istream& o, ARDOUR::SmpteFormat& sf);
402 std::istream& operator>>(std::istream& o, ARDOUR::DenormalModel& sf);
403
404 using ARDOUR::nframes_t;
405
406 static inline nframes_t
407 session_frame_to_track_frame (nframes_t session_frame, double speed)
408 {
409         return (nframes_t)( (double)session_frame * speed );
410 }
411
412 static inline nframes_t
413 track_frame_to_session_frame (nframes_t track_frame, double speed)
414 {
415         return (nframes_t)( (double)track_frame / speed );
416 }
417
418
419 #endif /* __ardour_types_h__ */
420