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/ParameterDescriptor.hpp"
29 #include "evoral/midi_events.h"
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 return *EventTypeMap::event_type_map;
49 EventTypeMap::type_is_midi(uint32_t type) const
51 return ARDOUR::parameter_is_midi((AutomationType)type);
55 EventTypeMap::parameter_midi_type(const Evoral::Parameter& param) const
57 return ARDOUR::parameter_midi_type((AutomationType)param.type());
61 EventTypeMap::midi_event_type(uint8_t status) const
63 return (uint32_t)ARDOUR::midi_parameter_type(status);
66 Evoral::ControlList::InterpolationStyle
67 EventTypeMap::interpolation_of(const Evoral::Parameter& param)
69 switch (param.type()) {
70 case MidiCCAutomation:
72 case MIDI_CTL_LSB_BANK:
73 case MIDI_CTL_MSB_BANK:
74 case MIDI_CTL_LSB_EFFECT1:
75 case MIDI_CTL_LSB_EFFECT2:
76 case MIDI_CTL_MSB_EFFECT1:
77 case MIDI_CTL_MSB_EFFECT2:
78 case MIDI_CTL_MSB_GENERAL_PURPOSE1:
79 case MIDI_CTL_MSB_GENERAL_PURPOSE2:
80 case MIDI_CTL_MSB_GENERAL_PURPOSE3:
81 case MIDI_CTL_MSB_GENERAL_PURPOSE4:
82 case MIDI_CTL_SUSTAIN:
83 case MIDI_CTL_PORTAMENTO:
84 case MIDI_CTL_SOSTENUTO:
85 case MIDI_CTL_SOFT_PEDAL:
86 case MIDI_CTL_LEGATO_FOOTSWITCH:
88 case MIDI_CTL_GENERAL_PURPOSE5:
89 case MIDI_CTL_GENERAL_PURPOSE6:
90 case MIDI_CTL_GENERAL_PURPOSE7:
91 case MIDI_CTL_GENERAL_PURPOSE8:
92 case MIDI_CTL_DATA_INCREMENT:
93 case MIDI_CTL_DATA_DECREMENT:
94 case MIDI_CTL_NONREG_PARM_NUM_LSB:
95 case MIDI_CTL_NONREG_PARM_NUM_MSB:
96 case MIDI_CTL_REGIST_PARM_NUM_LSB:
97 case MIDI_CTL_REGIST_PARM_NUM_MSB:
98 case MIDI_CTL_ALL_SOUNDS_OFF:
99 case MIDI_CTL_RESET_CONTROLLERS:
100 case MIDI_CTL_LOCAL_CONTROL_SWITCH:
101 case MIDI_CTL_ALL_NOTES_OFF:
102 case MIDI_CTL_OMNI_OFF:
103 case MIDI_CTL_OMNI_ON:
106 return Evoral::ControlList::Discrete; break;
108 return Evoral::ControlList::Linear; break;
111 case MidiPgmChangeAutomation: return Evoral::ControlList::Discrete; break;
112 case MidiChannelPressureAutomation: return Evoral::ControlList::Linear; break;
113 case MidiPitchBenderAutomation: return Evoral::ControlList::Linear; break;
114 default: assert(false);
116 return Evoral::ControlList::Linear; // Not reached, suppress warnings
120 EventTypeMap::from_symbol(const string& str) const
122 AutomationType p_type = NullAutomation;
123 uint8_t p_channel = 0;
127 p_type = GainAutomation;
128 } else if (str == "solo") {
129 p_type = SoloAutomation;
130 } else if (str == "mute") {
131 p_type = MuteAutomation;
132 } else if (str == "fadein") {
133 p_type = FadeInAutomation;
134 } else if (str == "fadeout") {
135 p_type = FadeOutAutomation;
136 } else if (str == "envelope") {
137 p_type = EnvelopeAutomation;
138 } else if (str == "pan-azimuth") {
139 p_type = PanAzimuthAutomation;
140 } else if (str == "pan-width") {
141 p_type = PanWidthAutomation;
142 } else if (str == "pan-elevation") {
143 p_type = PanElevationAutomation;
144 } else if (str == "pan-frontback") {
145 p_type = PanFrontBackAutomation;
146 } else if (str == "pan-lfe") {
147 p_type = PanLFEAutomation;
148 } else if (str.length() > 10 && str.substr(0, 10) == "parameter-") {
149 p_type = PluginAutomation;
150 p_id = atoi(str.c_str()+10);
151 } else if (str.length() > 9 && str.substr(0, 9) == "property-") {
152 p_type = PluginPropertyAutomation;
153 const char* name = str.c_str() + 9;
154 if (isdigit(str.c_str()[0])) {
157 p_id = _uri_map.uri_to_id(name);
159 } else if (str.length() > 7 && str.substr(0, 7) == "midicc-") {
160 p_type = MidiCCAutomation;
161 uint32_t channel = 0;
162 sscanf(str.c_str(), "midicc-%d-%d", &channel, &p_id);
163 assert(channel < 16);
165 } else if (str.length() > 16 && str.substr(0, 16) == "midi-pgm-change-") {
166 p_type = MidiPgmChangeAutomation;
167 uint32_t channel = 0;
168 sscanf(str.c_str(), "midi-pgm-change-%d", &channel);
169 assert(channel < 16);
172 } else if (str.length() > 18 && str.substr(0, 18) == "midi-pitch-bender-") {
173 p_type = MidiPitchBenderAutomation;
174 uint32_t channel = 0;
175 sscanf(str.c_str(), "midi-pitch-bender-%d", &channel);
176 assert(channel < 16);
179 } else if (str.length() > 22 && str.substr(0, 22) == "midi-channel-pressure-") {
180 p_type = MidiChannelPressureAutomation;
181 uint32_t channel = 0;
182 sscanf(str.c_str(), "midi-channel-pressure-%d", &channel);
183 assert(channel < 16);
187 PBD::warning << "Unknown Parameter '" << str << "'" << endmsg;
190 return Evoral::Parameter(p_type, p_channel, p_id);
193 /** Unique string representation, suitable as an XML property value.
194 * e.g. <AutomationList automation-id="whatthisreturns">
197 EventTypeMap::to_symbol(const Evoral::Parameter& param) const
199 AutomationType t = (AutomationType)param.type();
201 if (t == GainAutomation) {
203 } else if (t == PanAzimuthAutomation) {
204 return "pan-azimuth";
205 } else if (t == PanElevationAutomation) {
206 return "pan-elevation";
207 } else if (t == PanWidthAutomation) {
209 } else if (t == PanFrontBackAutomation) {
210 return "pan-frontback";
211 } else if (t == PanLFEAutomation) {
213 } else if (t == SoloAutomation) {
215 } else if (t == MuteAutomation) {
217 } else if (t == FadeInAutomation) {
219 } else if (t == FadeOutAutomation) {
221 } else if (t == EnvelopeAutomation) {
223 } else if (t == PluginAutomation) {
224 return string_compose("parameter-%1", param.id());
225 } else if (t == PluginPropertyAutomation) {
226 const char* uri = _uri_map.id_to_uri(param.id());
228 return string_compose("property-%1", uri);
230 return string_compose("property-%1", param.id());
232 } else if (t == MidiCCAutomation) {
233 return string_compose("midicc-%1-%2", int(param.channel()), param.id());
234 } else if (t == MidiPgmChangeAutomation) {
235 return string_compose("midi-pgm-change-%1", int(param.channel()));
236 } else if (t == MidiPitchBenderAutomation) {
237 return string_compose("midi-pitch-bender-%1", int(param.channel()));
238 } else if (t == MidiChannelPressureAutomation) {
239 return string_compose("midi-channel-pressure-%1", int(param.channel()));
241 PBD::warning << "Uninitialized Parameter symbol() called." << endmsg;
246 const Evoral::ParameterDescriptor&
247 EventTypeMap::descriptor(const Evoral::Parameter& param) const
249 static const Evoral::ParameterDescriptor nil;
251 Descriptors::const_iterator d = _descriptors.find(param);
252 return (d != _descriptors.end()) ? d->second : nil;
256 EventTypeMap::set_descriptor(const Evoral::Parameter& param,
257 const Evoral::ParameterDescriptor& desc)
259 _descriptors.insert(std::make_pair(param, desc));
262 } // namespace ARDOUR