add new sigc++2 directory
[ardour.git] / libs / ardour / ardour / midi_util.h
1 /*
2     Copyright (C) 2006 Paul Davis
3         Written by Dave Robillard, 2006
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20
21 #ifndef __ardour_midi_util_h__ 
22 #define __ardour_midi_util_h__
23
24 #include <midi++/events.h>
25
26 namespace ARDOUR {
27
28 /** Return the size of the given event NOT including the status byte,
29  * or -1 if unknown (eg sysex)
30  */
31 static inline int
32 midi_event_size(unsigned char status)
33 {
34         // if we have a channel event
35         if (status >= 0x80 && status < 0xF0) {
36                 status &= 0xF0; // mask off the channel
37         }
38
39         switch (status) {
40                 case MIDI_CMD_NOTE_OFF:
41                 case MIDI_CMD_NOTE_ON:
42                 case MIDI_CMD_NOTE_PRESSURE:
43                 case MIDI_CMD_CONTROL:
44                 case MIDI_CMD_BENDER:
45                 case MIDI_CMD_COMMON_SONG_POS:
46                         return 2;
47
48                 case MIDI_CMD_PGM_CHANGE:
49                 case MIDI_CMD_CHANNEL_PRESSURE:
50                 case MIDI_CMD_COMMON_MTC_QUARTER:
51                 case MIDI_CMD_COMMON_SONG_SELECT:
52                         return 1;
53
54                 case MIDI_CMD_COMMON_TUNE_REQUEST:
55                 case MIDI_CMD_COMMON_SYSEX_END:
56                 case MIDI_CMD_COMMON_CLOCK:
57                 case MIDI_CMD_COMMON_START:
58                 case MIDI_CMD_COMMON_CONTINUE:
59                 case MIDI_CMD_COMMON_STOP:
60                 case MIDI_CMD_COMMON_SENSING:
61                 case MIDI_CMD_COMMON_RESET:
62                         return 0;
63                 
64                 case MIDI_CMD_COMMON_SYSEX:
65                         return -1;
66         }
67
68         return -1;
69 }
70
71 } // namespace ARDOUR
72
73 #endif /* __ardour_midi_util_h__ */