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::parameter_midi_type(const Evoral::Parameter& param) const
44 switch (param.type()) {
45 case MidiCCAutomation: return MIDI_CMD_CONTROL; break;
46 case MidiPgmChangeAutomation: return MIDI_CMD_PGM_CHANGE; break;
47 case MidiChannelPressureAutomation: return MIDI_CMD_CHANNEL_PRESSURE; break;
48 case MidiPitchBenderAutomation: return MIDI_CMD_BENDER; break;
54 EventTypeMap::midi_event_type(uint8_t status) const
56 switch (status & 0xF0) {
57 case MIDI_CMD_CONTROL: return MidiCCAutomation; break;
58 case MIDI_CMD_PGM_CHANGE: return MidiPgmChangeAutomation; break;
59 case MIDI_CMD_CHANNEL_PRESSURE: return MidiChannelPressureAutomation; break;
60 case MIDI_CMD_BENDER: return MidiPitchBenderAutomation; break;
66 EventTypeMap::is_integer(const Evoral::Parameter& param) const
68 return ( param.type() >= MidiCCAutomation
69 && param.type() <= MidiChannelPressureAutomation);
73 EventTypeMap::new_parameter(uint32_t type, uint8_t channel, uint32_t id) const
75 Evoral::Parameter p(type, channel, id);
80 switch((AutomationType)type) {
89 case PluginAutomation:
92 case FadeInAutomation:
93 case FadeOutAutomation:
94 case EnvelopeAutomation:
98 case MidiCCAutomation:
99 case MidiPgmChangeAutomation:
100 case MidiChannelPressureAutomation:
101 Evoral::MIDI::controller_range(min, max, normal); break;
102 case MidiPitchBenderAutomation:
103 Evoral::MIDI::bender_range(min, max, normal); break;
106 p.set_range(type, min, max, normal);
111 EventTypeMap::new_parameter(const string& str) const
113 AutomationType p_type = NullAutomation;
114 uint8_t p_channel = 0;
118 p_type = GainAutomation;
119 } else if (str == "solo") {
120 p_type = SoloAutomation;
121 } else if (str == "mute") {
122 p_type = MuteAutomation;
123 } else if (str == "fadein") {
124 p_type = FadeInAutomation;
125 } else if (str == "fadeout") {
126 p_type = FadeOutAutomation;
127 } else if (str == "envelope") {
128 p_type = EnvelopeAutomation;
129 } else if (str == "pan") {
130 p_type = PanAutomation;
131 } else if (str.length() > 4 && str.substr(0, 4) == "pan-") {
132 p_type = PanAutomation;
133 p_id = atoi(str.c_str()+4);
134 } else if (str.length() > 10 && str.substr(0, 10) == "parameter-") {
135 p_type = PluginAutomation;
136 p_id = atoi(str.c_str()+10);
137 } else if (str.length() > 7 && str.substr(0, 7) == "midicc-") {
138 p_type = MidiCCAutomation;
139 uint32_t channel = 0;
140 sscanf(str.c_str(), "midicc-%d-%d", &channel, &p_id);
141 assert(channel < 16);
143 } else if (str.length() > 16 && str.substr(0, 16) == "midi-pgm-change-") {
144 p_type = MidiPgmChangeAutomation;
145 uint32_t channel = 0;
146 sscanf(str.c_str(), "midi-pgm-change-%d", &channel);
147 assert(channel < 16);
150 } else if (str.length() > 18 && str.substr(0, 18) == "midi-pitch-bender-") {
151 p_type = MidiPitchBenderAutomation;
152 uint32_t channel = 0;
153 sscanf(str.c_str(), "midi-pitch-bender-%d", &channel);
154 assert(channel < 16);
157 } else if (str.length() > 24 && str.substr(0, 24) == "midi-channel-pressure-") {
158 p_type = MidiChannelPressureAutomation;
159 uint32_t channel = 0;
160 sscanf(str.c_str(), "midi-channel-pressure-%d", &channel);
161 assert(channel < 16);
165 PBD::warning << "Unknown Parameter '" << str << "'" << endmsg;
168 return new_parameter(p_type, p_channel, p_id);
171 /** Unique string representation, suitable as an XML property value.
172 * e.g. <AutomationList automation-id="whatthisreturns">
175 EventTypeMap::to_symbol(const Evoral::Parameter& param) const
177 AutomationType t = (AutomationType)param.type();
179 if (t == GainAutomation) {
181 } else if (t == PanAutomation) {
182 return string_compose("pan-%1", param.id());
183 } else if (t == SoloAutomation) {
185 } else if (t == MuteAutomation) {
187 } else if (t == FadeInAutomation) {
189 } else if (t == FadeOutAutomation) {
191 } else if (t == EnvelopeAutomation) {
193 } else if (t == PluginAutomation) {
194 return string_compose("parameter-%1", param.id());
195 } else if (t == MidiCCAutomation) {
196 return string_compose("midicc-%1-%2", int(param.channel()), param.id());
197 } else if (t == MidiPgmChangeAutomation) {
198 return string_compose("midi-pgm-change-%1", int(param.channel()));
199 } else if (t == MidiPitchBenderAutomation) {
200 return string_compose("midi-pitch-bender-%1", int(param.channel()));
201 } else if (t == MidiChannelPressureAutomation) {
202 return string_compose("midi-channel-pressure-%1", int(param.channel()));
204 PBD::warning << "Uninitialized Parameter symbol() called." << endmsg;
209 } // namespace ARDOUR