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"
27 #include "ardour/uri_map.h"
28 #include "evoral/Parameter.hpp"
29 #include "evoral/ParameterDescriptor.hpp"
30 #include "evoral/midi_events.h"
31 #include "pbd/error.h"
32 #include "pbd/compose.h"
38 EventTypeMap* EventTypeMap::event_type_map;
41 EventTypeMap::instance()
43 if (!EventTypeMap::event_type_map) {
45 EventTypeMap::event_type_map = new EventTypeMap(&URIMap::instance());
47 EventTypeMap::event_type_map = new EventTypeMap(NULL);
50 return *EventTypeMap::event_type_map;
54 EventTypeMap::type_is_midi(uint32_t type) const
56 return ARDOUR::parameter_is_midi((AutomationType)type);
60 EventTypeMap::parameter_midi_type(const Evoral::Parameter& param) const
62 return ARDOUR::parameter_midi_type((AutomationType)param.type());
66 EventTypeMap::midi_event_type(uint8_t status) const
68 return (uint32_t)ARDOUR::midi_parameter_type(status);
71 Evoral::ControlList::InterpolationStyle
72 EventTypeMap::interpolation_of(const Evoral::Parameter& param)
74 switch (param.type()) {
75 case MidiCCAutomation:
77 case MIDI_CTL_LSB_BANK:
78 case MIDI_CTL_MSB_BANK:
79 case MIDI_CTL_LSB_EFFECT1:
80 case MIDI_CTL_LSB_EFFECT2:
81 case MIDI_CTL_MSB_EFFECT1:
82 case MIDI_CTL_MSB_EFFECT2:
83 case MIDI_CTL_MSB_GENERAL_PURPOSE1:
84 case MIDI_CTL_MSB_GENERAL_PURPOSE2:
85 case MIDI_CTL_MSB_GENERAL_PURPOSE3:
86 case MIDI_CTL_MSB_GENERAL_PURPOSE4:
87 case MIDI_CTL_SUSTAIN:
88 case MIDI_CTL_PORTAMENTO:
89 case MIDI_CTL_SOSTENUTO:
90 case MIDI_CTL_SOFT_PEDAL:
91 case MIDI_CTL_LEGATO_FOOTSWITCH:
93 case MIDI_CTL_GENERAL_PURPOSE5:
94 case MIDI_CTL_GENERAL_PURPOSE6:
95 case MIDI_CTL_GENERAL_PURPOSE7:
96 case MIDI_CTL_GENERAL_PURPOSE8:
97 case MIDI_CTL_DATA_INCREMENT:
98 case MIDI_CTL_DATA_DECREMENT:
99 case MIDI_CTL_NONREG_PARM_NUM_LSB:
100 case MIDI_CTL_NONREG_PARM_NUM_MSB:
101 case MIDI_CTL_REGIST_PARM_NUM_LSB:
102 case MIDI_CTL_REGIST_PARM_NUM_MSB:
103 case MIDI_CTL_ALL_SOUNDS_OFF:
104 case MIDI_CTL_RESET_CONTROLLERS:
105 case MIDI_CTL_LOCAL_CONTROL_SWITCH:
106 case MIDI_CTL_ALL_NOTES_OFF:
107 case MIDI_CTL_OMNI_OFF:
108 case MIDI_CTL_OMNI_ON:
111 return Evoral::ControlList::Discrete; break;
113 return Evoral::ControlList::Linear; break;
116 case MidiPgmChangeAutomation: return Evoral::ControlList::Discrete; break;
117 case MidiChannelPressureAutomation: return Evoral::ControlList::Linear; break;
118 case MidiPitchBenderAutomation: return Evoral::ControlList::Linear; break;
119 default: assert(false);
121 return Evoral::ControlList::Linear; // Not reached, suppress warnings
125 EventTypeMap::from_symbol(const string& str) const
127 AutomationType p_type = NullAutomation;
128 uint8_t p_channel = 0;
132 p_type = GainAutomation;
133 } else if (str == "solo") {
134 p_type = SoloAutomation;
135 } else if (str == "mute") {
136 p_type = MuteAutomation;
137 } else if (str == "fadein") {
138 p_type = FadeInAutomation;
139 } else if (str == "fadeout") {
140 p_type = FadeOutAutomation;
141 } else if (str == "envelope") {
142 p_type = EnvelopeAutomation;
143 } else if (str == "pan-azimuth") {
144 p_type = PanAzimuthAutomation;
145 } else if (str == "pan-width") {
146 p_type = PanWidthAutomation;
147 } else if (str == "pan-elevation") {
148 p_type = PanElevationAutomation;
149 } else if (str == "pan-frontback") {
150 p_type = PanFrontBackAutomation;
151 } else if (str == "pan-lfe") {
152 p_type = PanLFEAutomation;
153 } else if (str.length() > 10 && str.substr(0, 10) == "parameter-") {
154 p_type = PluginAutomation;
155 p_id = atoi(str.c_str()+10);
157 } else if (str.length() > 9 && str.substr(0, 9) == "property-") {
158 p_type = PluginPropertyAutomation;
159 const char* name = str.c_str() + 9;
160 if (isdigit(str.c_str()[0])) {
163 p_id = _uri_map->uri_to_id(name);
166 } else if (str.length() > 7 && str.substr(0, 7) == "midicc-") {
167 p_type = MidiCCAutomation;
168 uint32_t channel = 0;
169 sscanf(str.c_str(), "midicc-%d-%d", &channel, &p_id);
170 assert(channel < 16);
172 } else if (str.length() > 16 && str.substr(0, 16) == "midi-pgm-change-") {
173 p_type = MidiPgmChangeAutomation;
174 uint32_t channel = 0;
175 sscanf(str.c_str(), "midi-pgm-change-%d", &channel);
176 assert(channel < 16);
179 } else if (str.length() > 18 && str.substr(0, 18) == "midi-pitch-bender-") {
180 p_type = MidiPitchBenderAutomation;
181 uint32_t channel = 0;
182 sscanf(str.c_str(), "midi-pitch-bender-%d", &channel);
183 assert(channel < 16);
186 } else if (str.length() > 22 && str.substr(0, 22) == "midi-channel-pressure-") {
187 p_type = MidiChannelPressureAutomation;
188 uint32_t channel = 0;
189 sscanf(str.c_str(), "midi-channel-pressure-%d", &channel);
190 assert(channel < 16);
194 PBD::warning << "Unknown Parameter '" << str << "'" << endmsg;
197 return Evoral::Parameter(p_type, p_channel, p_id);
200 /** Unique string representation, suitable as an XML property value.
201 * e.g. <AutomationList automation-id="whatthisreturns">
204 EventTypeMap::to_symbol(const Evoral::Parameter& param) const
206 AutomationType t = (AutomationType)param.type();
208 if (t == GainAutomation) {
210 } else if (t == PanAzimuthAutomation) {
211 return "pan-azimuth";
212 } else if (t == PanElevationAutomation) {
213 return "pan-elevation";
214 } else if (t == PanWidthAutomation) {
216 } else if (t == PanFrontBackAutomation) {
217 return "pan-frontback";
218 } else if (t == PanLFEAutomation) {
220 } else if (t == SoloAutomation) {
222 } else if (t == MuteAutomation) {
224 } else if (t == FadeInAutomation) {
226 } else if (t == FadeOutAutomation) {
228 } else if (t == EnvelopeAutomation) {
230 } else if (t == PluginAutomation) {
231 return string_compose("parameter-%1", param.id());
233 } else if (t == PluginPropertyAutomation) {
234 const char* uri = _uri_map->id_to_uri(param.id());
236 return string_compose("property-%1", uri);
238 return string_compose("property-%1", param.id());
241 } else if (t == MidiCCAutomation) {
242 return string_compose("midicc-%1-%2", int(param.channel()), param.id());
243 } else if (t == MidiPgmChangeAutomation) {
244 return string_compose("midi-pgm-change-%1", int(param.channel()));
245 } else if (t == MidiPitchBenderAutomation) {
246 return string_compose("midi-pitch-bender-%1", int(param.channel()));
247 } else if (t == MidiChannelPressureAutomation) {
248 return string_compose("midi-channel-pressure-%1", int(param.channel()));
250 PBD::warning << "Uninitialized Parameter symbol() called." << endmsg;
255 Evoral::ParameterDescriptor
256 EventTypeMap::descriptor(const Evoral::Parameter& param) const
258 // Found an existing (perhaps custom) descriptor
259 Descriptors::const_iterator d = _descriptors.find(param);
260 if (d != _descriptors.end()) {
264 // Add default descriptor and return that
265 return ARDOUR::ParameterDescriptor(param);
269 EventTypeMap::set_descriptor(const Evoral::Parameter& param,
270 const Evoral::ParameterDescriptor& desc)
272 _descriptors.insert(std::make_pair(param, desc));
275 } // namespace ARDOUR