2 Copyright (C) 2008 Paul Davis
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.
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.
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.
22 #include "ardour/types.h"
23 #include "ardour/event_type_map.h"
24 #include "evoral/Parameter.hpp"
25 #include "evoral/midi_events.h"
26 #include "evoral/MIDIParameters.hpp"
27 #include "pbd/error.h"
28 #include "pbd/compose.h"
34 EventTypeMap EventTypeMap::event_type_map;
37 EventTypeMap::type_is_midi(uint32_t type) const
39 return (type >= MidiCCAutomation) && (type <= MidiChannelPressureAutomation);
43 EventTypeMap::is_midi_parameter(const Evoral::Parameter& param)
45 return type_is_midi(param.type());
49 EventTypeMap::parameter_midi_type(const Evoral::Parameter& param) const
51 switch (param.type()) {
52 case MidiCCAutomation: return MIDI_CMD_CONTROL; break;
53 case MidiPgmChangeAutomation: return MIDI_CMD_PGM_CHANGE; break;
54 case MidiChannelPressureAutomation: return MIDI_CMD_CHANNEL_PRESSURE; break;
55 case MidiPitchBenderAutomation: return MIDI_CMD_BENDER; break;
56 case MidiSystemExclusiveAutomation: return MIDI_CMD_COMMON_SYSEX; break;
62 EventTypeMap::midi_event_type(uint8_t status) const
64 switch (status & 0xF0) {
65 case MIDI_CMD_CONTROL: return MidiCCAutomation; break;
66 case MIDI_CMD_PGM_CHANGE: return MidiPgmChangeAutomation; break;
67 case MIDI_CMD_CHANNEL_PRESSURE: return MidiChannelPressureAutomation; break;
68 case MIDI_CMD_BENDER: return MidiPitchBenderAutomation; break;
69 case MIDI_CMD_COMMON_SYSEX: return MidiSystemExclusiveAutomation; break;
75 EventTypeMap::is_integer(const Evoral::Parameter& param) const
77 return ( param.type() >= MidiCCAutomation
78 && param.type() <= MidiChannelPressureAutomation);
81 Evoral::ControlList::InterpolationStyle
82 EventTypeMap::interpolation_of(const Evoral::Parameter& param)
84 switch (param.type()) {
85 case MidiCCAutomation:
87 case MIDI_CTL_LSB_BANK:
88 case MIDI_CTL_MSB_BANK:
89 case MIDI_CTL_LSB_EFFECT1:
90 case MIDI_CTL_LSB_EFFECT2:
91 case MIDI_CTL_MSB_EFFECT1:
92 case MIDI_CTL_MSB_EFFECT2:
93 case MIDI_CTL_MSB_GENERAL_PURPOSE1:
94 case MIDI_CTL_MSB_GENERAL_PURPOSE2:
95 case MIDI_CTL_MSB_GENERAL_PURPOSE3:
96 case MIDI_CTL_MSB_GENERAL_PURPOSE4:
97 case MIDI_CTL_SUSTAIN:
98 case MIDI_CTL_PORTAMENTO:
99 case MIDI_CTL_SOSTENUTO:
100 case MIDI_CTL_SOFT_PEDAL:
101 case MIDI_CTL_LEGATO_FOOTSWITCH:
103 case MIDI_CTL_GENERAL_PURPOSE5:
104 case MIDI_CTL_GENERAL_PURPOSE6:
105 case MIDI_CTL_GENERAL_PURPOSE7:
106 case MIDI_CTL_GENERAL_PURPOSE8:
107 case MIDI_CTL_DATA_INCREMENT:
108 case MIDI_CTL_DATA_DECREMENT:
109 case MIDI_CTL_NONREG_PARM_NUM_LSB:
110 case MIDI_CTL_NONREG_PARM_NUM_MSB:
111 case MIDI_CTL_REGIST_PARM_NUM_LSB:
112 case MIDI_CTL_REGIST_PARM_NUM_MSB:
113 case MIDI_CTL_ALL_SOUNDS_OFF:
114 case MIDI_CTL_RESET_CONTROLLERS:
115 case MIDI_CTL_LOCAL_CONTROL_SWITCH:
116 case MIDI_CTL_ALL_NOTES_OFF:
117 case MIDI_CTL_OMNI_OFF:
118 case MIDI_CTL_OMNI_ON:
121 return Evoral::ControlList::Discrete;
123 default: return Evoral::ControlList::Linear; break;
126 case MidiPgmChangeAutomation: return Evoral::ControlList::Discrete; break;
127 case MidiChannelPressureAutomation: return Evoral::ControlList::Linear; break;
128 case MidiPitchBenderAutomation: return Evoral::ControlList::Linear; break;
129 default: assert(false);
135 EventTypeMap::new_parameter(uint32_t type, uint8_t channel, uint32_t id) const
137 Evoral::Parameter p(type, channel, id);
141 double normal = 0.0f;
142 switch((AutomationType)type) {
151 case PluginAutomation:
154 case FadeInAutomation:
155 case FadeOutAutomation:
156 case EnvelopeAutomation:
160 case MidiCCAutomation:
161 case MidiPgmChangeAutomation:
162 case MidiChannelPressureAutomation:
163 Evoral::MIDI::controller_range(min, max, normal); break;
164 case MidiPitchBenderAutomation:
165 Evoral::MIDI::bender_range(min, max, normal); break;
166 case MidiSystemExclusiveAutomation:
170 p.set_range(type, min, max, normal);
175 EventTypeMap::new_parameter(const string& str) const
177 AutomationType p_type = NullAutomation;
178 uint8_t p_channel = 0;
182 p_type = GainAutomation;
183 } else if (str == "solo") {
184 p_type = SoloAutomation;
185 } else if (str == "mute") {
186 p_type = MuteAutomation;
187 } else if (str == "fadein") {
188 p_type = FadeInAutomation;
189 } else if (str == "fadeout") {
190 p_type = FadeOutAutomation;
191 } else if (str == "envelope") {
192 p_type = EnvelopeAutomation;
193 } else if (str == "pan") {
194 p_type = PanAutomation;
195 } else if (str.length() > 4 && str.substr(0, 4) == "pan-") {
196 p_type = PanAutomation;
197 p_id = atoi(str.c_str()+4);
198 } else if (str.length() > 10 && str.substr(0, 10) == "parameter-") {
199 p_type = PluginAutomation;
200 p_id = atoi(str.c_str()+10);
201 } else if (str.length() > 7 && str.substr(0, 7) == "midicc-") {
202 p_type = MidiCCAutomation;
203 uint32_t channel = 0;
204 sscanf(str.c_str(), "midicc-%d-%d", &channel, &p_id);
205 assert(channel < 16);
207 } else if (str.length() > 16 && str.substr(0, 16) == "midi-pgm-change-") {
208 p_type = MidiPgmChangeAutomation;
209 uint32_t channel = 0;
210 sscanf(str.c_str(), "midi-pgm-change-%d", &channel);
211 assert(channel < 16);
214 } else if (str.length() > 18 && str.substr(0, 18) == "midi-pitch-bender-") {
215 p_type = MidiPitchBenderAutomation;
216 uint32_t channel = 0;
217 sscanf(str.c_str(), "midi-pitch-bender-%d", &channel);
218 assert(channel < 16);
221 } else if (str.length() > 24 && str.substr(0, 24) == "midi-channel-pressure-") {
222 p_type = MidiChannelPressureAutomation;
223 uint32_t channel = 0;
224 sscanf(str.c_str(), "midi-channel-pressure-%d", &channel);
225 assert(channel < 16);
229 PBD::warning << "Unknown Parameter '" << str << "'" << endmsg;
232 return new_parameter(p_type, p_channel, p_id);
235 /** Unique string representation, suitable as an XML property value.
236 * e.g. <AutomationList automation-id="whatthisreturns">
239 EventTypeMap::to_symbol(const Evoral::Parameter& param) const
241 AutomationType t = (AutomationType)param.type();
243 if (t == GainAutomation) {
245 } else if (t == PanAutomation) {
246 return string_compose("pan-%1", param.id());
247 } else if (t == SoloAutomation) {
249 } else if (t == MuteAutomation) {
251 } else if (t == FadeInAutomation) {
253 } else if (t == FadeOutAutomation) {
255 } else if (t == EnvelopeAutomation) {
257 } else if (t == PluginAutomation) {
258 return string_compose("parameter-%1", param.id());
259 } else if (t == MidiCCAutomation) {
260 return string_compose("midicc-%1-%2", int(param.channel()), param.id());
261 } else if (t == MidiPgmChangeAutomation) {
262 return string_compose("midi-pgm-change-%1", int(param.channel()));
263 } else if (t == MidiPitchBenderAutomation) {
264 return string_compose("midi-pitch-bender-%1", int(param.channel()));
265 } else if (t == MidiChannelPressureAutomation) {
266 return string_compose("midi-channel-pressure-%1", int(param.channel()));
268 PBD::warning << "Uninitialized Parameter symbol() called." << endmsg;
273 } // namespace ARDOUR