2 Copyright (C) 2008 Paul Davis
3 Author: David Robillard
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.
23 #include "ardour/types.h"
24 #include "ardour/event_type_map.h"
25 #include "ardour/parameter_types.h"
26 #include "ardour/uri_map.h"
27 #include "evoral/Parameter.hpp"
28 #include "evoral/midi_events.h"
29 #include "evoral/MIDIParameters.hpp"
30 #include "pbd/error.h"
31 #include "pbd/compose.h"
37 EventTypeMap* EventTypeMap::event_type_map;
40 EventTypeMap::instance()
42 if (!EventTypeMap::event_type_map) {
43 EventTypeMap::event_type_map = new EventTypeMap(URIMap::instance());
45 // Initialize parameter metadata
46 EventTypeMap::event_type_map->new_parameter(NullAutomation);
47 EventTypeMap::event_type_map->new_parameter(GainAutomation);
48 EventTypeMap::event_type_map->new_parameter(PanAzimuthAutomation);
49 EventTypeMap::event_type_map->new_parameter(PanElevationAutomation);
50 EventTypeMap::event_type_map->new_parameter(PanWidthAutomation);
51 EventTypeMap::event_type_map->new_parameter(PluginAutomation);
52 EventTypeMap::event_type_map->new_parameter(PluginPropertyAutomation);
53 EventTypeMap::event_type_map->new_parameter(SoloAutomation);
54 EventTypeMap::event_type_map->new_parameter(MuteAutomation);
55 EventTypeMap::event_type_map->new_parameter(MidiCCAutomation);
56 EventTypeMap::event_type_map->new_parameter(MidiPgmChangeAutomation);
57 EventTypeMap::event_type_map->new_parameter(MidiPitchBenderAutomation);
58 EventTypeMap::event_type_map->new_parameter(MidiChannelPressureAutomation);
59 EventTypeMap::event_type_map->new_parameter(FadeInAutomation);
60 EventTypeMap::event_type_map->new_parameter(FadeOutAutomation);
61 EventTypeMap::event_type_map->new_parameter(EnvelopeAutomation);
62 EventTypeMap::event_type_map->new_parameter(MidiCCAutomation);
64 return *EventTypeMap::event_type_map;
68 EventTypeMap::type_is_midi(uint32_t type) const
70 return ARDOUR::parameter_is_midi((AutomationType)type);
74 EventTypeMap::is_midi_parameter(const Evoral::Parameter& param)
76 return type_is_midi(param.type());
80 EventTypeMap::parameter_midi_type(const Evoral::Parameter& param) const
82 return ARDOUR::parameter_midi_type((AutomationType)param.type());
86 EventTypeMap::midi_event_type(uint8_t status) const
88 return (uint32_t)ARDOUR::midi_parameter_type(status);
92 EventTypeMap::is_integer(const Evoral::Parameter& param) const
94 return ( param.type() >= MidiCCAutomation
95 && param.type() <= MidiChannelPressureAutomation);
98 Evoral::ControlList::InterpolationStyle
99 EventTypeMap::interpolation_of(const Evoral::Parameter& param)
101 switch (param.type()) {
102 case MidiCCAutomation:
103 switch (param.id()) {
104 case MIDI_CTL_LSB_BANK:
105 case MIDI_CTL_MSB_BANK:
106 case MIDI_CTL_LSB_EFFECT1:
107 case MIDI_CTL_LSB_EFFECT2:
108 case MIDI_CTL_MSB_EFFECT1:
109 case MIDI_CTL_MSB_EFFECT2:
110 case MIDI_CTL_MSB_GENERAL_PURPOSE1:
111 case MIDI_CTL_MSB_GENERAL_PURPOSE2:
112 case MIDI_CTL_MSB_GENERAL_PURPOSE3:
113 case MIDI_CTL_MSB_GENERAL_PURPOSE4:
114 case MIDI_CTL_SUSTAIN:
115 case MIDI_CTL_PORTAMENTO:
116 case MIDI_CTL_SOSTENUTO:
117 case MIDI_CTL_SOFT_PEDAL:
118 case MIDI_CTL_LEGATO_FOOTSWITCH:
120 case MIDI_CTL_GENERAL_PURPOSE5:
121 case MIDI_CTL_GENERAL_PURPOSE6:
122 case MIDI_CTL_GENERAL_PURPOSE7:
123 case MIDI_CTL_GENERAL_PURPOSE8:
124 case MIDI_CTL_DATA_INCREMENT:
125 case MIDI_CTL_DATA_DECREMENT:
126 case MIDI_CTL_NONREG_PARM_NUM_LSB:
127 case MIDI_CTL_NONREG_PARM_NUM_MSB:
128 case MIDI_CTL_REGIST_PARM_NUM_LSB:
129 case MIDI_CTL_REGIST_PARM_NUM_MSB:
130 case MIDI_CTL_ALL_SOUNDS_OFF:
131 case MIDI_CTL_RESET_CONTROLLERS:
132 case MIDI_CTL_LOCAL_CONTROL_SWITCH:
133 case MIDI_CTL_ALL_NOTES_OFF:
134 case MIDI_CTL_OMNI_OFF:
135 case MIDI_CTL_OMNI_ON:
138 return Evoral::ControlList::Discrete; break;
140 return Evoral::ControlList::Linear; break;
143 case MidiPgmChangeAutomation: return Evoral::ControlList::Discrete; break;
144 case MidiChannelPressureAutomation: return Evoral::ControlList::Linear; break;
145 case MidiPitchBenderAutomation: return Evoral::ControlList::Linear; break;
146 default: assert(false);
148 return Evoral::ControlList::Linear; // Not reached, suppress warnings
153 EventTypeMap::new_parameter(uint32_t type, uint8_t channel, uint32_t id) const
155 Evoral::Parameter p(type, channel, id);
159 double normal = 0.0f;
161 switch((AutomationType)type) {
167 case PanAzimuthAutomation:
168 normal = 0.5f; // there really is no normal but this works for stereo, sort of
170 case PanWidthAutomation:
175 case PanElevationAutomation:
176 case PanFrontBackAutomation:
177 case PanLFEAutomation:
179 case RecEnableAutomation:
180 /* default 0.0 - 1.0 is fine */
182 case PluginAutomation:
183 case FadeInAutomation:
184 case FadeOutAutomation:
185 case EnvelopeAutomation:
194 case MidiCCAutomation:
195 case MidiPgmChangeAutomation:
196 case MidiChannelPressureAutomation:
197 Evoral::MIDI::controller_range(min, max, normal); break;
198 case MidiPitchBenderAutomation:
199 Evoral::MIDI::bender_range(min, max, normal); break;
200 case MidiSystemExclusiveAutomation:
202 case PluginPropertyAutomation:
206 p.set_range(type, min, max, normal, false);
211 EventTypeMap::new_parameter(const string& str) const
213 AutomationType p_type = NullAutomation;
214 uint8_t p_channel = 0;
218 p_type = GainAutomation;
219 } else if (str == "solo") {
220 p_type = SoloAutomation;
221 } else if (str == "mute") {
222 p_type = MuteAutomation;
223 } else if (str == "fadein") {
224 p_type = FadeInAutomation;
225 } else if (str == "fadeout") {
226 p_type = FadeOutAutomation;
227 } else if (str == "envelope") {
228 p_type = EnvelopeAutomation;
229 } else if (str == "pan-azimuth") {
230 p_type = PanAzimuthAutomation;
231 } else if (str == "pan-width") {
232 p_type = PanWidthAutomation;
233 } else if (str == "pan-elevation") {
234 p_type = PanElevationAutomation;
235 } else if (str == "pan-frontback") {
236 p_type = PanFrontBackAutomation;
237 } else if (str == "pan-lfe") {
238 p_type = PanLFEAutomation;
239 } else if (str.length() > 10 && str.substr(0, 10) == "parameter-") {
240 p_type = PluginAutomation;
241 p_id = atoi(str.c_str()+10);
242 } else if (str.length() > 9 && str.substr(0, 9) == "property-") {
243 p_type = PluginPropertyAutomation;
244 const char* name = str.c_str() + 9;
245 if (isdigit(str.c_str()[0])) {
248 p_id = _uri_map.uri_to_id(name);
250 } else if (str.length() > 7 && str.substr(0, 7) == "midicc-") {
251 p_type = MidiCCAutomation;
252 uint32_t channel = 0;
253 sscanf(str.c_str(), "midicc-%d-%d", &channel, &p_id);
254 assert(channel < 16);
256 } else if (str.length() > 16 && str.substr(0, 16) == "midi-pgm-change-") {
257 p_type = MidiPgmChangeAutomation;
258 uint32_t channel = 0;
259 sscanf(str.c_str(), "midi-pgm-change-%d", &channel);
260 assert(channel < 16);
263 } else if (str.length() > 18 && str.substr(0, 18) == "midi-pitch-bender-") {
264 p_type = MidiPitchBenderAutomation;
265 uint32_t channel = 0;
266 sscanf(str.c_str(), "midi-pitch-bender-%d", &channel);
267 assert(channel < 16);
270 } else if (str.length() > 22 && str.substr(0, 22) == "midi-channel-pressure-") {
271 p_type = MidiChannelPressureAutomation;
272 uint32_t channel = 0;
273 sscanf(str.c_str(), "midi-channel-pressure-%d", &channel);
274 assert(channel < 16);
278 PBD::warning << "Unknown Parameter '" << str << "'" << endmsg;
281 return new_parameter(p_type, p_channel, p_id);
284 /** Unique string representation, suitable as an XML property value.
285 * e.g. <AutomationList automation-id="whatthisreturns">
288 EventTypeMap::to_symbol(const Evoral::Parameter& param) const
290 AutomationType t = (AutomationType)param.type();
292 if (t == GainAutomation) {
294 } else if (t == PanAzimuthAutomation) {
295 return "pan-azimuth";
296 } else if (t == PanElevationAutomation) {
297 return "pan-elevation";
298 } else if (t == PanWidthAutomation) {
300 } else if (t == PanFrontBackAutomation) {
301 return "pan-frontback";
302 } else if (t == PanLFEAutomation) {
304 } else if (t == SoloAutomation) {
306 } else if (t == MuteAutomation) {
308 } else if (t == FadeInAutomation) {
310 } else if (t == FadeOutAutomation) {
312 } else if (t == EnvelopeAutomation) {
314 } else if (t == PluginAutomation) {
315 return string_compose("parameter-%1", param.id());
316 } else if (t == PluginPropertyAutomation) {
317 const char* uri = _uri_map.id_to_uri(param.id());
319 return string_compose("property-%1", uri);
321 return string_compose("property-%1", param.id());
323 } else if (t == MidiCCAutomation) {
324 return string_compose("midicc-%1-%2", int(param.channel()), param.id());
325 } else if (t == MidiPgmChangeAutomation) {
326 return string_compose("midi-pgm-change-%1", int(param.channel()));
327 } else if (t == MidiPitchBenderAutomation) {
328 return string_compose("midi-pitch-bender-%1", int(param.channel()));
329 } else if (t == MidiChannelPressureAutomation) {
330 return string_compose("midi-channel-pressure-%1", int(param.channel()));
332 PBD::warning << "Uninitialized Parameter symbol() called." << endmsg;
337 } // namespace ARDOUR