From b5ec66ae6cb60fa43c343d3d29340b2370d0b9d1 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 29 Sep 2008 22:47:40 +0000 Subject: Can't call the wrong function when there's only one of them: remove ARDOUR::Parameter and just use Evoral::Parameter (move Ardour specific functionality to EventTypeMap where it belongs). Less than pretty in places but easily seddable just in case... git-svn-id: svn://localhost/ardour2/branches/3.0@3838 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/event_type_map.cc | 142 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) (limited to 'libs/ardour/event_type_map.cc') diff --git a/libs/ardour/event_type_map.cc b/libs/ardour/event_type_map.cc index 2d724a26ef..39c2e3d6eb 100644 --- a/libs/ardour/event_type_map.cc +++ b/libs/ardour/event_type_map.cc @@ -22,6 +22,11 @@ #include #include #include +#include +#include +#include + +using namespace std; namespace ARDOUR { @@ -64,5 +69,142 @@ EventTypeMap::is_integer(const Evoral::Parameter& param) const && param.type() <= MidiChannelPressureAutomation); } +Evoral::Parameter +EventTypeMap::new_parameter(uint32_t type, uint8_t channel, uint32_t id) const +{ + Evoral::Parameter p(type, channel, id); + + double min = 0.0f; + double max = 1.0f; + double normal = 0.0f; + switch((AutomationType)type) { + case NullAutomation: + case GainAutomation: + max = 2.0f; + normal = 1.0f; + break; + case PanAutomation: + normal = 0.5f; + break; + case PluginAutomation: + case SoloAutomation: + case MuteAutomation: + case FadeInAutomation: + case FadeOutAutomation: + case EnvelopeAutomation: + max = 2.0f; + normal = 1.0f; + break; + case MidiCCAutomation: + case MidiPgmChangeAutomation: + case MidiChannelPressureAutomation: + Evoral::MIDI::controller_range(min, max, normal); break; + case MidiPitchBenderAutomation: + Evoral::MIDI::bender_range(min, max, normal); break; + } + + p.set_range(type, min, max, normal); + return p; +} + +Evoral::Parameter +EventTypeMap::new_parameter(const string& str) const +{ + AutomationType p_type = NullAutomation; + uint8_t p_channel = 0; + uint32_t p_id = 0; + + if (str == "gain") { + p_type = GainAutomation; + } else if (str == "solo") { + p_type = SoloAutomation; + } else if (str == "mute") { + p_type = MuteAutomation; + } else if (str == "fadein") { + p_type = FadeInAutomation; + } else if (str == "fadeout") { + p_type = FadeOutAutomation; + } else if (str == "envelope") { + p_type = EnvelopeAutomation; + } else if (str == "pan") { + p_type = PanAutomation; + } else if (str.length() > 4 && str.substr(0, 4) == "pan-") { + p_type = PanAutomation; + p_id = atoi(str.c_str()+4); + } else if (str.length() > 10 && str.substr(0, 10) == "parameter-") { + p_type = PluginAutomation; + p_id = atoi(str.c_str()+10); + } else if (str.length() > 7 && str.substr(0, 7) == "midicc-") { + p_type = MidiCCAutomation; + uint32_t channel = 0; + sscanf(str.c_str(), "midicc-%d-%d", &channel, &p_id); + assert(channel < 16); + p_channel = channel; + } else if (str.length() > 16 && str.substr(0, 16) == "midi-pgm-change-") { + p_type = MidiPgmChangeAutomation; + uint32_t channel = 0; + sscanf(str.c_str(), "midi-pgm-change-%d", &channel); + assert(channel < 16); + p_id = 0; + p_channel = channel; + } else if (str.length() > 18 && str.substr(0, 18) == "midi-pitch-bender-") { + p_type = MidiPitchBenderAutomation; + uint32_t channel = 0; + sscanf(str.c_str(), "midi-pitch-bender-%d", &channel); + assert(channel < 16); + p_id = 0; + p_channel = channel; + } else if (str.length() > 24 && str.substr(0, 24) == "midi-channel-pressure-") { + p_type = MidiChannelPressureAutomation; + uint32_t channel = 0; + sscanf(str.c_str(), "midi-channel-pressure-%d", &channel); + assert(channel < 16); + p_id = 0; + p_channel = channel; + } else { + PBD::warning << "Unknown Parameter '" << str << "'" << endmsg; + } + + return new_parameter(p_type, p_channel, p_id); +} + +/** Unique string representation, suitable as an XML property value. + * e.g. + */ +std::string +EventTypeMap::to_symbol(const Evoral::Parameter& param) const +{ + AutomationType t = (AutomationType)param.type(); + + if (t == GainAutomation) { + return "gain"; + } else if (t == PanAutomation) { + return string_compose("pan-%1", param.id()); + } else if (t == SoloAutomation) { + return "solo"; + } else if (t == MuteAutomation) { + return "mute"; + } else if (t == FadeInAutomation) { + return "fadein"; + } else if (t == FadeOutAutomation) { + return "fadeout"; + } else if (t == EnvelopeAutomation) { + return "envelope"; + } else if (t == PluginAutomation) { + return string_compose("parameter-%1", param.id()); + } else if (t == MidiCCAutomation) { + return string_compose("midicc-%1-%2", int(param.channel()), param.id()); + } else if (t == MidiPgmChangeAutomation) { + return string_compose("midi-pgm-change-%1", int(param.channel())); + } else if (t == MidiPitchBenderAutomation) { + return string_compose("midi-pitch-bender-%1", int(param.channel())); + } else if (t == MidiChannelPressureAutomation) { + return string_compose("midi-channel-pressure-%1", int(param.channel())); + } else { + PBD::warning << "Uninitialized Parameter symbol() called." << endmsg; + return ""; + } +} + } // namespace ARDOUR -- cgit v1.2.3