MIDI polyphonic pressure, part 2
[ardour.git] / libs / ardour / ardour / parameter_types.h
1 /*
2     Copyright (C) 2014 Paul Davis
3     Author: David Robillard
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_parameter_types_h__
22 #define __ardour_parameter_types_h__
23
24 #include <stdint.h>
25
26 #include "ardour/types.h"
27 #include "evoral/Parameter.hpp"
28 #include "evoral/midi_events.h"
29
30 namespace ARDOUR {
31
32 inline uint8_t
33 parameter_midi_type(AutomationType type)
34 {
35         switch (type) {
36         case MidiCCAutomation:              return MIDI_CMD_CONTROL;          break;
37         case MidiPgmChangeAutomation:       return MIDI_CMD_PGM_CHANGE;       break;
38         case MidiChannelPressureAutomation: return MIDI_CMD_CHANNEL_PRESSURE; break;
39         case MidiNotePressureAutomation:    return MIDI_CMD_NOTE_PRESSURE; break;
40         case MidiPitchBenderAutomation:     return MIDI_CMD_BENDER;           break;
41         case MidiSystemExclusiveAutomation: return MIDI_CMD_COMMON_SYSEX;     break;
42         default: return 0;
43         }
44 }
45
46 inline AutomationType
47 midi_parameter_type(uint8_t status)
48 {
49         switch (status & 0xF0) {
50         case MIDI_CMD_CONTROL:          return MidiCCAutomation;              break;
51         case MIDI_CMD_PGM_CHANGE:       return MidiPgmChangeAutomation;       break;
52         case MIDI_CMD_CHANNEL_PRESSURE: return MidiChannelPressureAutomation; break;
53         case MIDI_CMD_NOTE_PRESSURE:    return MidiNotePressureAutomation; break;
54         case MIDI_CMD_BENDER:           return MidiPitchBenderAutomation;     break;
55         case MIDI_CMD_COMMON_SYSEX:     return MidiSystemExclusiveAutomation; break;
56         default: return NullAutomation;
57         }
58 }
59
60 inline Evoral::Parameter
61 midi_parameter(const uint8_t* buf, const uint32_t len)
62 {
63         const uint8_t channel = buf[0] & 0x0F;
64         switch (midi_parameter_type(buf[0])) {
65         case MidiCCAutomation:
66                 return Evoral::Parameter(MidiCCAutomation, channel, buf[1]);
67         case MidiPgmChangeAutomation:
68                 return Evoral::Parameter(MidiPgmChangeAutomation, channel);
69         case MidiChannelPressureAutomation:
70                 return Evoral::Parameter(MidiChannelPressureAutomation, channel);
71         case MidiNotePressureAutomation:
72                 return Evoral::Parameter(MidiChannelPressureAutomation, channel);
73         case MidiPitchBenderAutomation:
74                 return Evoral::Parameter(MidiPitchBenderAutomation, channel);
75         case MidiSystemExclusiveAutomation:
76                 return Evoral::Parameter(MidiSystemExclusiveAutomation, channel);
77         default:
78                 return Evoral::Parameter(NullAutomation);
79         }
80 }
81
82 inline bool
83 parameter_is_midi(AutomationType type)
84 {
85         return (type >= MidiCCAutomation) && (type <= MidiChannelPressureAutomation);
86 }
87
88 }  // namespace ARDOUR
89
90 #endif /* __ardour_parameter_types_h__ */
91