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_descriptor.h"
26 #include "ardour/parameter_types.h"
28 #include "ardour/uri_map.h"
30 #include "evoral/Parameter.hpp"
31 #include "evoral/ParameterDescriptor.hpp"
32 #include "evoral/midi_events.h"
33 #include "pbd/error.h"
34 #include "pbd/compose.h"
40 EventTypeMap* EventTypeMap::event_type_map;
43 EventTypeMap::instance()
45 if (!EventTypeMap::event_type_map) {
47 EventTypeMap::event_type_map = new EventTypeMap(&URIMap::instance());
49 EventTypeMap::event_type_map = new EventTypeMap(NULL);
52 return *EventTypeMap::event_type_map;
56 EventTypeMap::type_is_midi(uint32_t type) const
58 return ARDOUR::parameter_is_midi((AutomationType)type);
62 EventTypeMap::parameter_midi_type(const Evoral::Parameter& param) const
64 return ARDOUR::parameter_midi_type((AutomationType)param.type());
68 EventTypeMap::midi_parameter_type(const uint8_t* buf, uint32_t len) const
70 return (uint32_t)ARDOUR::midi_parameter_type(buf[0]);
73 Evoral::ControlList::InterpolationStyle
74 EventTypeMap::interpolation_of(const Evoral::Parameter& param)
76 switch (param.type()) {
77 case MidiCCAutomation:
79 case MIDI_CTL_LSB_BANK:
80 case MIDI_CTL_MSB_BANK:
81 case MIDI_CTL_LSB_EFFECT1:
82 case MIDI_CTL_LSB_EFFECT2:
83 case MIDI_CTL_MSB_EFFECT1:
84 case MIDI_CTL_MSB_EFFECT2:
85 case MIDI_CTL_MSB_GENERAL_PURPOSE1:
86 case MIDI_CTL_MSB_GENERAL_PURPOSE2:
87 case MIDI_CTL_MSB_GENERAL_PURPOSE3:
88 case MIDI_CTL_MSB_GENERAL_PURPOSE4:
89 case MIDI_CTL_SUSTAIN:
90 case MIDI_CTL_PORTAMENTO:
91 case MIDI_CTL_SOSTENUTO:
92 case MIDI_CTL_SOFT_PEDAL:
93 case MIDI_CTL_LEGATO_FOOTSWITCH:
95 case MIDI_CTL_GENERAL_PURPOSE5:
96 case MIDI_CTL_GENERAL_PURPOSE6:
97 case MIDI_CTL_GENERAL_PURPOSE7:
98 case MIDI_CTL_GENERAL_PURPOSE8:
99 case MIDI_CTL_DATA_INCREMENT:
100 case MIDI_CTL_DATA_DECREMENT:
101 case MIDI_CTL_NONREG_PARM_NUM_LSB:
102 case MIDI_CTL_NONREG_PARM_NUM_MSB:
103 case MIDI_CTL_REGIST_PARM_NUM_LSB:
104 case MIDI_CTL_REGIST_PARM_NUM_MSB:
105 case MIDI_CTL_ALL_SOUNDS_OFF:
106 case MIDI_CTL_RESET_CONTROLLERS:
107 case MIDI_CTL_LOCAL_CONTROL_SWITCH:
108 case MIDI_CTL_ALL_NOTES_OFF:
109 case MIDI_CTL_OMNI_OFF:
110 case MIDI_CTL_OMNI_ON:
113 return Evoral::ControlList::Discrete; break;
115 return Evoral::ControlList::Linear; break;
118 case MidiPgmChangeAutomation: return Evoral::ControlList::Discrete; break;
119 case MidiChannelPressureAutomation: return Evoral::ControlList::Linear; break;
120 case MidiNotePressureAutomation: return Evoral::ControlList::Linear; break;
121 case MidiPitchBenderAutomation: return Evoral::ControlList::Linear; break;
122 default: assert(false);
124 return Evoral::ControlList::Linear; // Not reached, suppress warnings
128 EventTypeMap::from_symbol(const string& str) const
130 AutomationType p_type = NullAutomation;
131 uint8_t p_channel = 0;
135 p_type = GainAutomation;
136 } else if (str == "trim") {
137 p_type = TrimAutomation;
138 } else if (str == "solo") {
139 p_type = SoloAutomation;
140 } else if (str == "solo-iso") {
141 p_type = SoloIsolateAutomation;
142 } else if (str == "solo-safe") {
143 p_type = SoloSafeAutomation;
144 } else if (str == "mute") {
145 p_type = MuteAutomation;
146 } else if (str == "fadein") {
147 p_type = FadeInAutomation;
148 } else if (str == "fadeout") {
149 p_type = FadeOutAutomation;
150 } else if (str == "envelope") {
151 p_type = EnvelopeAutomation;
152 } else if (str == "pan-azimuth") {
153 p_type = PanAzimuthAutomation;
154 } else if (str == "pan-width") {
155 p_type = PanWidthAutomation;
156 } else if (str == "pan-elevation") {
157 p_type = PanElevationAutomation;
158 } else if (str == "pan-frontback") {
159 p_type = PanFrontBackAutomation;
160 } else if (str == "pan-lfe") {
161 p_type = PanLFEAutomation;
162 } else if (str == "rec-enable") {
163 p_type = RecEnableAutomation;
164 } else if (str == "rec-safe") {
165 p_type = RecSafeAutomation;
166 } else if (str == "phase") {
167 p_type = PhaseAutomation;
168 } else if (str == "monitor") {
169 p_type = MonitoringAutomation;
170 } else if (str == "pan-lfe") {
171 p_type = PanLFEAutomation;
172 } else if (str.length() > 10 && str.substr(0, 10) == "parameter-") {
173 p_type = PluginAutomation;
174 p_id = atoi(str.c_str()+10);
176 } else if (str.length() > 9 && str.substr(0, 9) == "property-") {
177 p_type = PluginPropertyAutomation;
178 const char* name = str.c_str() + 9;
179 if (isdigit(str.c_str()[0])) {
182 p_id = _uri_map->uri_to_id(name);
185 } else if (str.length() > 7 && str.substr(0, 7) == "midicc-") {
186 p_type = MidiCCAutomation;
187 uint32_t channel = 0;
188 sscanf(str.c_str(), "midicc-%d-%d", &channel, &p_id);
189 assert(channel < 16);
191 } else if (str.length() > 16 && str.substr(0, 16) == "midi-pgm-change-") {
192 p_type = MidiPgmChangeAutomation;
193 uint32_t channel = 0;
194 sscanf(str.c_str(), "midi-pgm-change-%d", &channel);
195 assert(channel < 16);
198 } else if (str.length() > 18 && str.substr(0, 18) == "midi-pitch-bender-") {
199 p_type = MidiPitchBenderAutomation;
200 uint32_t channel = 0;
201 sscanf(str.c_str(), "midi-pitch-bender-%d", &channel);
202 assert(channel < 16);
205 } else if (str.length() > 22 && str.substr(0, 22) == "midi-channel-pressure-") {
206 p_type = MidiChannelPressureAutomation;
207 uint32_t channel = 0;
208 sscanf(str.c_str(), "midi-channel-pressure-%d", &channel);
209 assert(channel < 16);
212 } else if (str.length() > 19 && str.substr(0, 19) == "midi-note-pressure-") {
213 p_type = MidiNotePressureAutomation;
214 uint32_t channel = 0;
215 sscanf(str.c_str(), "midi-note-pressure-%d-%d", &channel, &p_id);
216 assert(channel < 16);
220 PBD::warning << "Unknown Parameter '" << str << "'" << endmsg;
223 return Evoral::Parameter(p_type, p_channel, p_id);
226 /** Unique string representation, suitable as an XML property value.
227 * e.g. <AutomationList automation-id="whatthisreturns">
230 EventTypeMap::to_symbol(const Evoral::Parameter& param) const
232 AutomationType t = (AutomationType)param.type();
234 if (t == GainAutomation) {
236 } else if (t == TrimAutomation) {
238 } else if (t == PanAzimuthAutomation) {
239 return "pan-azimuth";
240 } else if (t == PanElevationAutomation) {
241 return "pan-elevation";
242 } else if (t == PanWidthAutomation) {
244 } else if (t == PanFrontBackAutomation) {
245 return "pan-frontback";
246 } else if (t == PanLFEAutomation) {
248 } else if (t == SoloAutomation) {
250 } else if (t == MuteAutomation) {
252 } else if (t == FadeInAutomation) {
254 } else if (t == FadeOutAutomation) {
256 } else if (t == EnvelopeAutomation) {
258 } else if (t == PhaseAutomation) {
260 } else if (t == SoloIsolateAutomation) {
262 } else if (t == SoloSafeAutomation) {
264 } else if (t == MonitoringAutomation) {
266 } else if (t == RecEnableAutomation) {
268 } else if (t == RecSafeAutomation) {
270 } else if (t == PluginAutomation) {
271 return std::string("parameter-") + PBD::to_string(param.id());
273 } else if (t == PluginPropertyAutomation) {
274 const char* uri = _uri_map->id_to_uri(param.id());
276 return std::string("property-") + uri;
278 return std::string("property-") + PBD::to_string(param.id());
281 } else if (t == MidiCCAutomation) {
282 return std::string("midicc-") + PBD::to_string (param.channel()) + "-" + PBD::to_string (param.id());
283 } else if (t == MidiPgmChangeAutomation) {
284 return std::string("midi-pgm-change-") + PBD::to_string(param.channel());
285 } else if (t == MidiPitchBenderAutomation) {
286 return std::string("midi-pitch-bender-") + PBD::to_string(param.channel());
287 } else if (t == MidiChannelPressureAutomation) {
288 return std::string("midi-channel-pressure-") + PBD::to_string(param.channel());
289 } else if (t == MidiNotePressureAutomation) {
290 return std::string ("midi-note-pressure-") + PBD::to_string (param.channel()) + "-" + PBD::to_string (param.id());
292 PBD::warning << "Uninitialized Parameter symbol() called." << endmsg;
297 Evoral::ParameterDescriptor
298 EventTypeMap::descriptor(const Evoral::Parameter& param) const
300 // Found an existing (perhaps custom) descriptor
301 Descriptors::const_iterator d = _descriptors.find(param);
302 if (d != _descriptors.end()) {
306 // Add default descriptor and return that
307 return ARDOUR::ParameterDescriptor(param);
311 EventTypeMap::set_descriptor(const Evoral::Parameter& param,
312 const Evoral::ParameterDescriptor& desc)
314 _descriptors.insert(std::make_pair(param, desc));
317 } // namespace ARDOUR