ardour
event_type_map.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 Paul Davis
3  Author: David Robillard
4 
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.
9 
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.
14 
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.
18 
19 */
20 
21 #include <ctype.h>
22 #include <cstdio>
23 #include "ardour/types.h"
24 #include "ardour/event_type_map.h"
26 #include "ardour/parameter_types.h"
27 #include "ardour/uri_map.h"
28 #include "evoral/Parameter.hpp"
30 #include "evoral/midi_events.h"
31 #include "pbd/error.h"
32 #include "pbd/compose.h"
33 
34 using namespace std;
35 
36 namespace ARDOUR {
37 
38 EventTypeMap* EventTypeMap::event_type_map;
39 
40 EventTypeMap&
41 EventTypeMap::instance()
42 {
43  if (!EventTypeMap::event_type_map) {
44 #ifdef LV2_SUPPORT
45  EventTypeMap::event_type_map = new EventTypeMap(&URIMap::instance());
46 #else
47  EventTypeMap::event_type_map = new EventTypeMap(NULL);
48 #endif
49  }
50  return *EventTypeMap::event_type_map;
51 }
52 
53 bool
54 EventTypeMap::type_is_midi(uint32_t type) const
55 {
57 }
58 
59 uint8_t
61 {
63 }
64 
65 uint32_t
66 EventTypeMap::midi_event_type(uint8_t status) const
67 {
68  return (uint32_t)ARDOUR::midi_parameter_type(status);
69 }
70 
72 EventTypeMap::interpolation_of(const Evoral::Parameter& param)
73 {
74  switch (param.type()) {
75  case MidiCCAutomation:
76  switch (param.id()) {
77  case MIDI_CTL_LSB_BANK:
78  case MIDI_CTL_MSB_BANK:
87  case MIDI_CTL_SUSTAIN:
89  case MIDI_CTL_SOSTENUTO:
92  case MIDI_CTL_HOLD2:
107  case MIDI_CTL_OMNI_OFF:
108  case MIDI_CTL_OMNI_ON:
109  case MIDI_CTL_MONO:
110  case MIDI_CTL_POLY:
111  return Evoral::ControlList::Discrete; break;
112  default:
113  return Evoral::ControlList::Linear; break;
114  }
115  break;
119  default: assert(false);
120  }
121  return Evoral::ControlList::Linear; // Not reached, suppress warnings
122 }
123 
125 EventTypeMap::from_symbol(const string& str) const
126 {
128  uint8_t p_channel = 0;
129  uint32_t p_id = 0;
130 
131  if (str == "gain") {
132  p_type = GainAutomation;
133  } else if (str == "trim") {
134  p_type = TrimAutomation;
135  } else if (str == "solo") {
136  p_type = SoloAutomation;
137  } else if (str == "mute") {
138  p_type = MuteAutomation;
139  } else if (str == "fadein") {
140  p_type = FadeInAutomation;
141  } else if (str == "fadeout") {
142  p_type = FadeOutAutomation;
143  } else if (str == "envelope") {
144  p_type = EnvelopeAutomation;
145  } else if (str == "pan-azimuth") {
146  p_type = PanAzimuthAutomation;
147  } else if (str == "pan-width") {
148  p_type = PanWidthAutomation;
149  } else if (str == "pan-elevation") {
150  p_type = PanElevationAutomation;
151  } else if (str == "pan-frontback") {
152  p_type = PanFrontBackAutomation;
153  } else if (str == "pan-lfe") {
154  p_type = PanLFEAutomation;
155  } else if (str.length() > 10 && str.substr(0, 10) == "parameter-") {
156  p_type = PluginAutomation;
157  p_id = atoi(str.c_str()+10);
158 #ifdef LV2_SUPPORT
159  } else if (str.length() > 9 && str.substr(0, 9) == "property-") {
160  p_type = PluginPropertyAutomation;
161  const char* name = str.c_str() + 9;
162  if (isdigit(str.c_str()[0])) {
163  p_id = atoi(name);
164  } else {
165  p_id = _uri_map->uri_to_id(name);
166  }
167 #endif
168  } else if (str.length() > 7 && str.substr(0, 7) == "midicc-") {
169  p_type = MidiCCAutomation;
170  uint32_t channel = 0;
171  sscanf(str.c_str(), "midicc-%d-%d", &channel, &p_id);
172  assert(channel < 16);
173  p_channel = channel;
174  } else if (str.length() > 16 && str.substr(0, 16) == "midi-pgm-change-") {
175  p_type = MidiPgmChangeAutomation;
176  uint32_t channel = 0;
177  sscanf(str.c_str(), "midi-pgm-change-%d", &channel);
178  assert(channel < 16);
179  p_id = 0;
180  p_channel = channel;
181  } else if (str.length() > 18 && str.substr(0, 18) == "midi-pitch-bender-") {
182  p_type = MidiPitchBenderAutomation;
183  uint32_t channel = 0;
184  sscanf(str.c_str(), "midi-pitch-bender-%d", &channel);
185  assert(channel < 16);
186  p_id = 0;
187  p_channel = channel;
188  } else if (str.length() > 22 && str.substr(0, 22) == "midi-channel-pressure-") {
190  uint32_t channel = 0;
191  sscanf(str.c_str(), "midi-channel-pressure-%d", &channel);
192  assert(channel < 16);
193  p_id = 0;
194  p_channel = channel;
195  } else {
196  PBD::warning << "Unknown Parameter '" << str << "'" << endmsg;
197  }
198 
199  return Evoral::Parameter(p_type, p_channel, p_id);
200 }
201 
205 std::string
206 EventTypeMap::to_symbol(const Evoral::Parameter& param) const
207 {
208  AutomationType t = (AutomationType)param.type();
209 
210  if (t == GainAutomation) {
211  return "gain";
212  } else if (t == TrimAutomation) {
213  return "trim";
214  } else if (t == PanAzimuthAutomation) {
215  return "pan-azimuth";
216  } else if (t == PanElevationAutomation) {
217  return "pan-elevation";
218  } else if (t == PanWidthAutomation) {
219  return "pan-width";
220  } else if (t == PanFrontBackAutomation) {
221  return "pan-frontback";
222  } else if (t == PanLFEAutomation) {
223  return "pan-lfe";
224  } else if (t == SoloAutomation) {
225  return "solo";
226  } else if (t == MuteAutomation) {
227  return "mute";
228  } else if (t == FadeInAutomation) {
229  return "fadein";
230  } else if (t == FadeOutAutomation) {
231  return "fadeout";
232  } else if (t == EnvelopeAutomation) {
233  return "envelope";
234  } else if (t == PluginAutomation) {
235  return string_compose("parameter-%1", param.id());
236 #ifdef LV2_SUPPORT
237  } else if (t == PluginPropertyAutomation) {
238  const char* uri = _uri_map->id_to_uri(param.id());
239  if (uri) {
240  return string_compose("property-%1", uri);
241  } else {
242  return string_compose("property-%1", param.id());
243  }
244 #endif
245  } else if (t == MidiCCAutomation) {
246  return string_compose("midicc-%1-%2", int(param.channel()), param.id());
247  } else if (t == MidiPgmChangeAutomation) {
248  return string_compose("midi-pgm-change-%1", int(param.channel()));
249  } else if (t == MidiPitchBenderAutomation) {
250  return string_compose("midi-pitch-bender-%1", int(param.channel()));
251  } else if (t == MidiChannelPressureAutomation) {
252  return string_compose("midi-channel-pressure-%1", int(param.channel()));
253  } else {
254  PBD::warning << "Uninitialized Parameter symbol() called." << endmsg;
255  return "";
256  }
257 }
258 
260 EventTypeMap::descriptor(const Evoral::Parameter& param) const
261 {
262  // Found an existing (perhaps custom) descriptor
263  Descriptors::const_iterator d = _descriptors.find(param);
264  if (d != _descriptors.end()) {
265  return d->second;
266  }
267 
268  // Add default descriptor and return that
269  return ARDOUR::ParameterDescriptor(param);
270 }
271 
272 void
273 EventTypeMap::set_descriptor(const Evoral::Parameter& param,
274  const Evoral::ParameterDescriptor& desc)
275 {
276  _descriptors.insert(std::make_pair(param, desc));
277 }
278 
279 } // namespace ARDOUR
280 
#define MIDI_CTL_POLY
Definition: midi_events.h:104
#define MIDI_CTL_MSB_BANK
Definition: midi_events.h:33
int atoi(const string &s)
Definition: convert.cc:140
#define MIDI_CTL_NONREG_PARM_NUM_LSB
Definition: midi_events.h:93
#define MIDI_CTL_LOCAL_CONTROL_SWITCH
Definition: midi_events.h:99
#define MIDI_CTL_LSB_BANK
Definition: midi_events.h:49
#define MIDI_CTL_MSB_GENERAL_PURPOSE3
Definition: midi_events.h:47
#define MIDI_CTL_OMNI_ON
Definition: midi_events.h:102
#define MIDI_CTL_LSB_EFFECT2
Definition: midi_events.h:60
#define MIDI_CTL_MONO
Definition: midi_events.h:103
#define MIDI_CTL_MSB_GENERAL_PURPOSE1
Definition: midi_events.h:45
Definition: Beats.hpp:239
LIBPBD_API Transmitter warning
#define MIDI_CTL_ALL_SOUNDS_OFF
Definition: midi_events.h:97
std::ostream & endmsg(std::ostream &ostr)
Definition: transmitter.h:71
#define MIDI_CTL_MSB_EFFECT2
Definition: midi_events.h:44
#define MIDI_CTL_LEGATO_FOOTSWITCH
Definition: midi_events.h:69
#define MIDI_CTL_RESET_CONTROLLERS
Definition: midi_events.h:98
#define MIDI_CTL_MSB_GENERAL_PURPOSE2
Definition: midi_events.h:46
#define MIDI_CTL_REGIST_PARM_NUM_LSB
Definition: midi_events.h:95
#define MIDI_CTL_GENERAL_PURPOSE6
Definition: midi_events.h:82
#define MIDI_CTL_HOLD2
Definition: midi_events.h:70
Definition: amp.h:29
#define MIDI_CTL_SUSTAIN
Definition: midi_events.h:65
#define MIDI_CTL_REGIST_PARM_NUM_MSB
Definition: midi_events.h:96
#define MIDI_CTL_LSB_EFFECT1
Definition: midi_events.h:59
#define MIDI_CTL_MSB_GENERAL_PURPOSE4
Definition: midi_events.h:48
AutomationType
Definition: types.h:121
#define MIDI_CTL_GENERAL_PURPOSE7
Definition: midi_events.h:83
#define MIDI_CTL_SOSTENUTO
Definition: midi_events.h:67
#define MIDI_CTL_NONREG_PARM_NUM_MSB
Definition: midi_events.h:94
#define MIDI_CTL_OMNI_OFF
Definition: midi_events.h:101
#define MIDI_CTL_DATA_INCREMENT
Definition: midi_events.h:91
const char * name
uint32_t id() const
Definition: Parameter.hpp:49
bool parameter_is_midi(AutomationType type)
#define MIDI_CTL_PORTAMENTO
Definition: midi_events.h:66
uint32_t type() const
Definition: Parameter.hpp:47
#define MIDI_CTL_DATA_DECREMENT
Definition: midi_events.h:92
#define MIDI_CTL_MSB_EFFECT1
Definition: midi_events.h:43
AutomationType midi_parameter_type(uint8_t status)
uint8_t channel() const
Definition: Parameter.hpp:48
#define MIDI_CTL_ALL_NOTES_OFF
Definition: midi_events.h:100
#define MIDI_CTL_GENERAL_PURPOSE8
Definition: midi_events.h:84
#define MIDI_CTL_GENERAL_PURPOSE5
Definition: midi_events.h:81
uint8_t parameter_midi_type(AutomationType type)
std::string string_compose(const std::string &fmt, const T1 &o1)
Definition: compose.h:208
#define MIDI_CTL_SOFT_PEDAL
Definition: midi_events.h:68