2 Copyright (C) 2008 Paul Davis
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.
21 #include <ardour/types.h>
22 #include <ardour/event_type_map.h>
23 #include <evoral/Parameter.hpp>
24 #include <evoral/midi_events.h>
25 #include <evoral/MIDIParameters.hpp>
26 #include <pbd/error.h>
27 #include <pbd/compose.h>
33 EventTypeMap EventTypeMap::event_type_map;
36 EventTypeMap::type_is_midi(uint32_t type) const
38 return (type >= MidiCCAutomation) && (type <= MidiChannelPressureAutomation);
42 EventTypeMap::is_midi_parameter(const Evoral::Parameter& param)
44 return type_is_midi(param.type());
48 EventTypeMap::parameter_midi_type(const Evoral::Parameter& param) const
50 switch (param.type()) {
51 case MidiCCAutomation: return MIDI_CMD_CONTROL; break;
52 case MidiPgmChangeAutomation: return MIDI_CMD_PGM_CHANGE; break;
53 case MidiChannelPressureAutomation: return MIDI_CMD_CHANNEL_PRESSURE; break;
54 case MidiPitchBenderAutomation: return MIDI_CMD_BENDER; break;
60 EventTypeMap::midi_event_type(uint8_t status) const
62 switch (status & 0xF0) {
63 case MIDI_CMD_CONTROL: return MidiCCAutomation; break;
64 case MIDI_CMD_PGM_CHANGE: return MidiPgmChangeAutomation; break;
65 case MIDI_CMD_CHANNEL_PRESSURE: return MidiChannelPressureAutomation; break;
66 case MIDI_CMD_BENDER: return MidiPitchBenderAutomation; break;
72 EventTypeMap::is_integer(const Evoral::Parameter& param) const
74 return ( param.type() >= MidiCCAutomation
75 && param.type() <= MidiChannelPressureAutomation);
79 EventTypeMap::new_parameter(uint32_t type, uint8_t channel, uint32_t id) const
81 Evoral::Parameter p(type, channel, id);
86 switch((AutomationType)type) {
95 case PluginAutomation:
98 case FadeInAutomation:
99 case FadeOutAutomation:
100 case EnvelopeAutomation:
104 case MidiCCAutomation:
105 case MidiPgmChangeAutomation:
106 case MidiChannelPressureAutomation:
107 Evoral::MIDI::controller_range(min, max, normal); break;
108 case MidiPitchBenderAutomation:
109 Evoral::MIDI::bender_range(min, max, normal); break;
112 p.set_range(type, min, max, normal);
117 EventTypeMap::new_parameter(const string& str) const
119 AutomationType p_type = NullAutomation;
120 uint8_t p_channel = 0;
124 p_type = GainAutomation;
125 } else if (str == "solo") {
126 p_type = SoloAutomation;
127 } else if (str == "mute") {
128 p_type = MuteAutomation;
129 } else if (str == "fadein") {
130 p_type = FadeInAutomation;
131 } else if (str == "fadeout") {
132 p_type = FadeOutAutomation;
133 } else if (str == "envelope") {
134 p_type = EnvelopeAutomation;
135 } else if (str == "pan") {
136 p_type = PanAutomation;
137 } else if (str.length() > 4 && str.substr(0, 4) == "pan-") {
138 p_type = PanAutomation;
139 p_id = atoi(str.c_str()+4);
140 } else if (str.length() > 10 && str.substr(0, 10) == "parameter-") {
141 p_type = PluginAutomation;
142 p_id = atoi(str.c_str()+10);
143 } else if (str.length() > 7 && str.substr(0, 7) == "midicc-") {
144 p_type = MidiCCAutomation;
145 uint32_t channel = 0;
146 sscanf(str.c_str(), "midicc-%d-%d", &channel, &p_id);
147 assert(channel < 16);
149 } else if (str.length() > 16 && str.substr(0, 16) == "midi-pgm-change-") {
150 p_type = MidiPgmChangeAutomation;
151 uint32_t channel = 0;
152 sscanf(str.c_str(), "midi-pgm-change-%d", &channel);
153 assert(channel < 16);
156 } else if (str.length() > 18 && str.substr(0, 18) == "midi-pitch-bender-") {
157 p_type = MidiPitchBenderAutomation;
158 uint32_t channel = 0;
159 sscanf(str.c_str(), "midi-pitch-bender-%d", &channel);
160 assert(channel < 16);
163 } else if (str.length() > 24 && str.substr(0, 24) == "midi-channel-pressure-") {
164 p_type = MidiChannelPressureAutomation;
165 uint32_t channel = 0;
166 sscanf(str.c_str(), "midi-channel-pressure-%d", &channel);
167 assert(channel < 16);
171 PBD::warning << "Unknown Parameter '" << str << "'" << endmsg;
174 return new_parameter(p_type, p_channel, p_id);
177 /** Unique string representation, suitable as an XML property value.
178 * e.g. <AutomationList automation-id="whatthisreturns">
181 EventTypeMap::to_symbol(const Evoral::Parameter& param) const
183 AutomationType t = (AutomationType)param.type();
185 if (t == GainAutomation) {
187 } else if (t == PanAutomation) {
188 return string_compose("pan-%1", param.id());
189 } else if (t == SoloAutomation) {
191 } else if (t == MuteAutomation) {
193 } else if (t == FadeInAutomation) {
195 } else if (t == FadeOutAutomation) {
197 } else if (t == EnvelopeAutomation) {
199 } else if (t == PluginAutomation) {
200 return string_compose("parameter-%1", param.id());
201 } else if (t == MidiCCAutomation) {
202 return string_compose("midicc-%1-%2", int(param.channel()), param.id());
203 } else if (t == MidiPgmChangeAutomation) {
204 return string_compose("midi-pgm-change-%1", int(param.channel()));
205 } else if (t == MidiPitchBenderAutomation) {
206 return string_compose("midi-pitch-bender-%1", int(param.channel()));
207 } else if (t == MidiChannelPressureAutomation) {
208 return string_compose("midi-channel-pressure-%1", int(param.channel()));
210 PBD::warning << "Uninitialized Parameter symbol() called." << endmsg;
215 } // namespace ARDOUR