X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fevent_type_map.cc;h=708a52205f776056115f37e6ab885cd3b838ee75;hb=5fa05b403ca21a6573d07b921dc14f0769dc9fc7;hp=0388a934f20bd9fa92ebd5af2e0ee1257040db17;hpb=b6e90314b0087e870ad21ce658b92bd23851fe29;p=ardour.git diff --git a/libs/ardour/event_type_map.cc b/libs/ardour/event_type_map.cc index 0388a934f2..708a52205f 100644 --- a/libs/ardour/event_type_map.cc +++ b/libs/ardour/event_type_map.cc @@ -1,6 +1,6 @@ /* Copyright (C) 2008 Paul Davis - Author: Dave Robillard + Author: David Robillard This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,12 +18,18 @@ */ +#include #include #include "ardour/types.h" #include "ardour/event_type_map.h" +#include "ardour/parameter_descriptor.h" +#include "ardour/parameter_types.h" +#ifdef LV2_SUPPORT +#include "ardour/uri_map.h" +#endif #include "evoral/Parameter.hpp" +#include "evoral/ParameterDescriptor.hpp" #include "evoral/midi_events.h" -#include "evoral/MIDIParameters.hpp" #include "pbd/error.h" #include "pbd/compose.h" @@ -31,51 +37,37 @@ using namespace std; namespace ARDOUR { -EventTypeMap EventTypeMap::event_type_map; +EventTypeMap* EventTypeMap::event_type_map; -bool -EventTypeMap::type_is_midi(uint32_t type) const +EventTypeMap& +EventTypeMap::instance() { - return (type >= MidiCCAutomation) && (type <= MidiChannelPressureAutomation); + if (!EventTypeMap::event_type_map) { +#ifdef LV2_SUPPORT + EventTypeMap::event_type_map = new EventTypeMap(&URIMap::instance()); +#else + EventTypeMap::event_type_map = new EventTypeMap(NULL); +#endif + } + return *EventTypeMap::event_type_map; } bool -EventTypeMap::is_midi_parameter(const Evoral::Parameter& param) +EventTypeMap::type_is_midi(uint32_t type) const { - return type_is_midi(param.type()); + return ARDOUR::parameter_is_midi((AutomationType)type); } uint8_t EventTypeMap::parameter_midi_type(const Evoral::Parameter& param) const { - switch (param.type()) { - case MidiCCAutomation: return MIDI_CMD_CONTROL; break; - case MidiPgmChangeAutomation: return MIDI_CMD_PGM_CHANGE; break; - case MidiChannelPressureAutomation: return MIDI_CMD_CHANNEL_PRESSURE; break; - case MidiPitchBenderAutomation: return MIDI_CMD_BENDER; break; - case MidiSystemExclusiveAutomation: return MIDI_CMD_COMMON_SYSEX; break; - default: return 0; - } -} - -uint32_t -EventTypeMap::midi_event_type(uint8_t status) const -{ - switch (status & 0xF0) { - case MIDI_CMD_CONTROL: return MidiCCAutomation; break; - case MIDI_CMD_PGM_CHANGE: return MidiPgmChangeAutomation; break; - case MIDI_CMD_CHANNEL_PRESSURE: return MidiChannelPressureAutomation; break; - case MIDI_CMD_BENDER: return MidiPitchBenderAutomation; break; - case MIDI_CMD_COMMON_SYSEX: return MidiSystemExclusiveAutomation; break; - default: return 0; - } + return ARDOUR::parameter_midi_type((AutomationType)param.type()); } -bool -EventTypeMap::is_integer(const Evoral::Parameter& param) const +Evoral::ParameterType +EventTypeMap::midi_parameter_type(const uint8_t* buf, uint32_t len) const { - return ( param.type() >= MidiCCAutomation - && param.type() <= MidiChannelPressureAutomation); + return (uint32_t)ARDOUR::midi_parameter_type(buf[0]); } Evoral::ControlList::InterpolationStyle @@ -125,55 +117,15 @@ EventTypeMap::interpolation_of(const Evoral::Parameter& param) break; case MidiPgmChangeAutomation: return Evoral::ControlList::Discrete; break; case MidiChannelPressureAutomation: return Evoral::ControlList::Linear; break; + case MidiNotePressureAutomation: return Evoral::ControlList::Linear; break; case MidiPitchBenderAutomation: return Evoral::ControlList::Linear; break; default: assert(false); } return Evoral::ControlList::Linear; // Not reached, suppress warnings } - -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; - case MidiSystemExclusiveAutomation: - return p; - } - - p.set_range(type, min, max, normal); - return p; -} - Evoral::Parameter -EventTypeMap::new_parameter(const string& str) const +EventTypeMap::from_symbol(const string& str) const { AutomationType p_type = NullAutomation; uint8_t p_channel = 0; @@ -181,8 +133,14 @@ EventTypeMap::new_parameter(const string& str) const if (str == "gain") { p_type = GainAutomation; + } else if (str == "trim") { + p_type = TrimAutomation; } else if (str == "solo") { p_type = SoloAutomation; + } else if (str == "solo-iso") { + p_type = SoloIsolateAutomation; + } else if (str == "solo-safe") { + p_type = SoloSafeAutomation; } else if (str == "mute") { p_type = MuteAutomation; } else if (str == "fadein") { @@ -191,14 +149,39 @@ EventTypeMap::new_parameter(const string& str) const 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 == "pan-azimuth") { + p_type = PanAzimuthAutomation; + } else if (str == "pan-width") { + p_type = PanWidthAutomation; + } else if (str == "pan-elevation") { + p_type = PanElevationAutomation; + } else if (str == "pan-frontback") { + p_type = PanFrontBackAutomation; + } else if (str == "pan-lfe") { + p_type = PanLFEAutomation; + } else if (str == "rec-enable") { + p_type = RecEnableAutomation; + } else if (str == "rec-safe") { + p_type = RecSafeAutomation; + } else if (str == "phase") { + p_type = PhaseAutomation; + } else if (str == "monitor") { + p_type = MonitoringAutomation; + } else if (str == "pan-lfe") { + p_type = PanLFEAutomation; } else if (str.length() > 10 && str.substr(0, 10) == "parameter-") { p_type = PluginAutomation; p_id = atoi(str.c_str()+10); +#ifdef LV2_SUPPORT + } else if (str.length() > 9 && str.substr(0, 9) == "property-") { + p_type = PluginPropertyAutomation; + const char* name = str.c_str() + 9; + if (isdigit(str.c_str()[0])) { + p_id = atoi(name); + } else { + p_id = _uri_map->uri_to_id(name); + } +#endif } else if (str.length() > 7 && str.substr(0, 7) == "midicc-") { p_type = MidiCCAutomation; uint32_t channel = 0; @@ -219,18 +202,25 @@ EventTypeMap::new_parameter(const string& str) const assert(channel < 16); p_id = 0; p_channel = channel; - } else if (str.length() > 24 && str.substr(0, 24) == "midi-channel-pressure-") { + } else if (str.length() > 22 && str.substr(0, 22) == "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 if (str.length() > 19 && str.substr(0, 19) == "midi-note-pressure-") { + p_type = MidiNotePressureAutomation; + uint32_t channel = 0; + sscanf(str.c_str(), "midi-note-pressure-%d-%d", &channel, &p_id); + assert(channel < 16); + assert(p_id < 127); + p_channel = channel; } else { PBD::warning << "Unknown Parameter '" << str << "'" << endmsg; } - return new_parameter(p_type, p_channel, p_id); + return Evoral::Parameter(p_type, p_channel, p_id); } /** Unique string representation, suitable as an XML property value. @@ -243,8 +233,18 @@ EventTypeMap::to_symbol(const Evoral::Parameter& param) const if (t == GainAutomation) { return "gain"; - } else if (t == PanAutomation) { - return string_compose("pan-%1", param.id()); + } else if (t == TrimAutomation) { + return "trim"; + } else if (t == PanAzimuthAutomation) { + return "pan-azimuth"; + } else if (t == PanElevationAutomation) { + return "pan-elevation"; + } else if (t == PanWidthAutomation) { + return "pan-width"; + } else if (t == PanFrontBackAutomation) { + return "pan-frontback"; + } else if (t == PanLFEAutomation) { + return "pan-lfe"; } else if (t == SoloAutomation) { return "solo"; } else if (t == MuteAutomation) { @@ -255,21 +255,64 @@ EventTypeMap::to_symbol(const Evoral::Parameter& param) const return "fadeout"; } else if (t == EnvelopeAutomation) { return "envelope"; + } else if (t == PhaseAutomation) { + return "phase"; + } else if (t == SoloIsolateAutomation) { + return "solo-iso"; + } else if (t == SoloSafeAutomation) { + return "solo-safe"; + } else if (t == MonitoringAutomation) { + return "monitor"; + } else if (t == RecEnableAutomation) { + return "rec-enable"; + } else if (t == RecSafeAutomation) { + return "rec-safe"; } else if (t == PluginAutomation) { - return string_compose("parameter-%1", param.id()); + return std::string("parameter-") + PBD::to_string(param.id()); +#ifdef LV2_SUPPORT + } else if (t == PluginPropertyAutomation) { + const char* uri = _uri_map->id_to_uri(param.id()); + if (uri) { + return std::string("property-") + uri; + } else { + return std::string("property-") + PBD::to_string(param.id()); + } +#endif } else if (t == MidiCCAutomation) { - return string_compose("midicc-%1-%2", int(param.channel()), param.id()); + return std::string("midicc-") + PBD::to_string (param.channel()) + "-" + PBD::to_string (param.id()); } else if (t == MidiPgmChangeAutomation) { - return string_compose("midi-pgm-change-%1", int(param.channel())); + return std::string("midi-pgm-change-") + PBD::to_string(param.channel()); } else if (t == MidiPitchBenderAutomation) { - return string_compose("midi-pitch-bender-%1", int(param.channel())); + return std::string("midi-pitch-bender-") + PBD::to_string(param.channel()); } else if (t == MidiChannelPressureAutomation) { - return string_compose("midi-channel-pressure-%1", int(param.channel())); + return std::string("midi-channel-pressure-") + PBD::to_string(param.channel()); + } else if (t == MidiNotePressureAutomation) { + return std::string ("midi-note-pressure-") + PBD::to_string (param.channel()) + "-" + PBD::to_string (param.id()); } else { PBD::warning << "Uninitialized Parameter symbol() called." << endmsg; return ""; } } +Evoral::ParameterDescriptor +EventTypeMap::descriptor(const Evoral::Parameter& param) const +{ + // Found an existing (perhaps custom) descriptor + Descriptors::const_iterator d = _descriptors.find(param); + if (d != _descriptors.end()) { + return d->second; + } + + // Add default descriptor and return that + return ARDOUR::ParameterDescriptor(param); +} + +void +EventTypeMap::set_descriptor(const Evoral::Parameter& param, + const Evoral::ParameterDescriptor& desc) +{ + _descriptors.insert(std::make_pair(param, desc)); +} + } // namespace ARDOUR