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;
160 bool toggled = false;
162 switch((AutomationType)type) {
168 case PanAzimuthAutomation:
169 normal = 0.5f; // there really is no normal but this works for stereo, sort of
171 case PanWidthAutomation:
176 case PanElevationAutomation:
177 case PanFrontBackAutomation:
178 case PanLFEAutomation:
180 case RecEnableAutomation:
181 /* default 0.0 - 1.0 is fine */
184 case PluginAutomation:
185 case FadeInAutomation:
186 case FadeOutAutomation:
187 case EnvelopeAutomation:
197 case MidiCCAutomation:
198 case MidiPgmChangeAutomation:
199 case MidiChannelPressureAutomation:
200 Evoral::MIDI::controller_range(min, max, normal); break;
201 case MidiPitchBenderAutomation:
202 Evoral::MIDI::bender_range(min, max, normal); break;
203 case MidiSystemExclusiveAutomation:
205 case PluginPropertyAutomation:
209 p.set_range(type, min, max, normal, toggled);
214 EventTypeMap::new_parameter(const string& str) const
216 AutomationType p_type = NullAutomation;
217 uint8_t p_channel = 0;
221 p_type = GainAutomation;
222 } else if (str == "solo") {
223 p_type = SoloAutomation;
224 } else if (str == "mute") {
225 p_type = MuteAutomation;
226 } else if (str == "fadein") {
227 p_type = FadeInAutomation;
228 } else if (str == "fadeout") {
229 p_type = FadeOutAutomation;
230 } else if (str == "envelope") {
231 p_type = EnvelopeAutomation;
232 } else if (str == "pan-azimuth") {
233 p_type = PanAzimuthAutomation;
234 } else if (str == "pan-width") {
235 p_type = PanWidthAutomation;
236 } else if (str == "pan-elevation") {
237 p_type = PanElevationAutomation;
238 } else if (str == "pan-frontback") {
239 p_type = PanFrontBackAutomation;
240 } else if (str == "pan-lfe") {
241 p_type = PanLFEAutomation;
242 } else if (str.length() > 10 && str.substr(0, 10) == "parameter-") {
243 p_type = PluginAutomation;
244 p_id = atoi(str.c_str()+10);
245 } else if (str.length() > 9 && str.substr(0, 9) == "property-") {
246 p_type = PluginPropertyAutomation;
247 const char* name = str.c_str() + 9;
248 if (isdigit(str.c_str()[0])) {
251 p_id = _uri_map.uri_to_id(name);
253 } else if (str.length() > 7 && str.substr(0, 7) == "midicc-") {
254 p_type = MidiCCAutomation;
255 uint32_t channel = 0;
256 sscanf(str.c_str(), "midicc-%d-%d", &channel, &p_id);
257 assert(channel < 16);
259 } else if (str.length() > 16 && str.substr(0, 16) == "midi-pgm-change-") {
260 p_type = MidiPgmChangeAutomation;
261 uint32_t channel = 0;
262 sscanf(str.c_str(), "midi-pgm-change-%d", &channel);
263 assert(channel < 16);
266 } else if (str.length() > 18 && str.substr(0, 18) == "midi-pitch-bender-") {
267 p_type = MidiPitchBenderAutomation;
268 uint32_t channel = 0;
269 sscanf(str.c_str(), "midi-pitch-bender-%d", &channel);
270 assert(channel < 16);
273 } else if (str.length() > 22 && str.substr(0, 22) == "midi-channel-pressure-") {
274 p_type = MidiChannelPressureAutomation;
275 uint32_t channel = 0;
276 sscanf(str.c_str(), "midi-channel-pressure-%d", &channel);
277 assert(channel < 16);
281 PBD::warning << "Unknown Parameter '" << str << "'" << endmsg;
284 return new_parameter(p_type, p_channel, p_id);
287 /** Unique string representation, suitable as an XML property value.
288 * e.g. <AutomationList automation-id="whatthisreturns">
291 EventTypeMap::to_symbol(const Evoral::Parameter& param) const
293 AutomationType t = (AutomationType)param.type();
295 if (t == GainAutomation) {
297 } else if (t == PanAzimuthAutomation) {
298 return "pan-azimuth";
299 } else if (t == PanElevationAutomation) {
300 return "pan-elevation";
301 } else if (t == PanWidthAutomation) {
303 } else if (t == PanFrontBackAutomation) {
304 return "pan-frontback";
305 } else if (t == PanLFEAutomation) {
307 } else if (t == SoloAutomation) {
309 } else if (t == MuteAutomation) {
311 } else if (t == FadeInAutomation) {
313 } else if (t == FadeOutAutomation) {
315 } else if (t == EnvelopeAutomation) {
317 } else if (t == PluginAutomation) {
318 return string_compose("parameter-%1", param.id());
319 } else if (t == PluginPropertyAutomation) {
320 const char* uri = _uri_map.id_to_uri(param.id());
322 return string_compose("property-%1", uri);
324 return string_compose("property-%1", param.id());
326 } else if (t == MidiCCAutomation) {
327 return string_compose("midicc-%1-%2", int(param.channel()), param.id());
328 } else if (t == MidiPgmChangeAutomation) {
329 return string_compose("midi-pgm-change-%1", int(param.channel()));
330 } else if (t == MidiPitchBenderAutomation) {
331 return string_compose("midi-pitch-bender-%1", int(param.channel()));
332 } else if (t == MidiChannelPressureAutomation) {
333 return string_compose("midi-channel-pressure-%1", int(param.channel()));
335 PBD::warning << "Uninitialized Parameter symbol() called." << endmsg;
340 } // namespace ARDOUR