From 1d117aa37241e88ed98424ea406bece23a23866f Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Sun, 18 Dec 2022 15:40:53 -0700 Subject: [PATCH] give MIDI tracks a (n automatable) velocity control --- libs/ardour/ardour/midi_track.h | 5 +++ libs/ardour/ardour/types.h | 1 + libs/ardour/ardour/velocity_control.h | 44 +++++++++++++++++++++++++++ libs/ardour/automation_list.cc | 1 + libs/ardour/enums.cc | 1 + libs/ardour/midi_track.cc | 4 +++ libs/ardour/velocity_control.cc | 38 +++++++++++++++++++++++ libs/ardour/wscript | 1 + 8 files changed, 95 insertions(+) create mode 100644 libs/ardour/ardour/velocity_control.h create mode 100644 libs/ardour/velocity_control.cc diff --git a/libs/ardour/ardour/midi_track.h b/libs/ardour/ardour/midi_track.h index 6f67a3a2b8..3023896659 100644 --- a/libs/ardour/ardour/midi_track.h +++ b/libs/ardour/ardour/midi_track.h @@ -34,6 +34,7 @@ class MidiPlaylist; class RouteGroup; class SMFSource; class Session; +class VelocityControl; class LIBARDOUR_API MidiTrack : public Track { @@ -75,6 +76,8 @@ public: void midi_panic(void); bool write_immediate_event (Evoral::EventType event_type, size_t size, const uint8_t* buf); + boost::shared_ptr velocity_control() const; + /** A control that will send "immediate" events to a MIDI track when twiddled */ struct MidiControl : public AutomationControl { MidiControl(MidiTrack* route, const Evoral::Parameter& param, @@ -166,6 +169,8 @@ private: MidiChannelFilter _playback_filter; MidiChannelFilter _capture_filter; + boost::shared_ptr _velocity_control; + void set_state_part_two (); void set_state_part_three (); diff --git a/libs/ardour/ardour/types.h b/libs/ardour/ardour/types.h index baf520ff8a..45c2b53e6d 100644 --- a/libs/ardour/ardour/types.h +++ b/libs/ardour/ardour/types.h @@ -175,6 +175,7 @@ enum AutomationType { BusSendEnable, InsertReturnLevel, MainOutVolume, + MidiVelocityAutomation, /* used only by Controllable Descriptor to access send parameters */ diff --git a/libs/ardour/ardour/velocity_control.h b/libs/ardour/ardour/velocity_control.h new file mode 100644 index 0000000000..006c7290dc --- /dev/null +++ b/libs/ardour/ardour/velocity_control.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2022 Paul Davis + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __ardour_velocity_control_h__ +#define __ardour_velocity_control_h__ + +#include + +#include + +#include "pbd/controllable.h" + +#include "evoral/Parameter.h" + +#include "ardour/slavable_automation_control.h" +#include "ardour/libardour_visibility.h" + +namespace ARDOUR { + +class Session; + +class LIBARDOUR_API VelocityControl : public SlavableAutomationControl { + public: + VelocityControl (Session& session); +}; + +} /* namespace */ + +#endif /* __ardour_velocity_control_h__ */ diff --git a/libs/ardour/automation_list.cc b/libs/ardour/automation_list.cc index 69dd61a0ad..15b2440c5c 100644 --- a/libs/ardour/automation_list.cc +++ b/libs/ardour/automation_list.cc @@ -166,6 +166,7 @@ AutomationList::create_curve_if_necessary() case FadeInAutomation: case FadeOutAutomation: case EnvelopeAutomation: + case MidiVelocityAutomation: create_curve(); break; default: diff --git a/libs/ardour/enums.cc b/libs/ardour/enums.cc index c9e175233f..7aace4ea8f 100644 --- a/libs/ardour/enums.cc +++ b/libs/ardour/enums.cc @@ -208,6 +208,7 @@ setup_enum_writer () REGISTER_ENUM (BusSendEnable); REGISTER_ENUM (InsertReturnLevel); REGISTER_ENUM (MainOutVolume); + REGISTER_ENUM (MidiVelocityAutomation); REGISTER (_AutomationType); REGISTER_ENUM (Off); diff --git a/libs/ardour/midi_track.cc b/libs/ardour/midi_track.cc index d8305695df..f9a05b7b3f 100644 --- a/libs/ardour/midi_track.cc +++ b/libs/ardour/midi_track.cc @@ -64,6 +64,7 @@ #include "ardour/session_playlists.h" #include "ardour/types_convert.h" #include "ardour/utils.h" +#include "ardour/velocity_control.h" #include "pbd/i18n.h" @@ -108,6 +109,9 @@ MidiTrack::init () return -1; } + _velocity_control.reset (new VelocityControl (_session)); + add_control (_velocity_control); + _input->changed.connect_same_thread (*this, boost::bind (&MidiTrack::track_input_active, this, _1, _2)); _disk_writer->set_note_mode (_note_mode); diff --git a/libs/ardour/velocity_control.cc b/libs/ardour/velocity_control.cc new file mode 100644 index 0000000000..1c44681829 --- /dev/null +++ b/libs/ardour/velocity_control.cc @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2022 Paul Davis + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include + +#include "pbd/convert.h" +#include "pbd/strsplit.h" + +#include "ardour/velocity_control.h" +#include "ardour/session.h" + +#include "pbd/i18n.h" + +using namespace ARDOUR; +using namespace std; + + +VelocityControl::VelocityControl (Session& session) + : SlavableAutomationControl (session, Evoral::Parameter (MidiVelocityAutomation), ParameterDescriptor (Evoral::Parameter (MidiVelocityAutomation)), + boost::shared_ptr (new AutomationList (Evoral::Parameter (MidiVelocityAutomation), Temporal::BeatTime)), + _("Velocity")) +{ +} diff --git a/libs/ardour/wscript b/libs/ardour/wscript index ab6f0b098a..768959aa4e 100644 --- a/libs/ardour/wscript +++ b/libs/ardour/wscript @@ -278,6 +278,7 @@ libardour_sources = [ 'utils.cc', 'vca.cc', 'vca_manager.cc', + 'velocity_control.cc', 'video_tools_paths.cc', 'vumeterdsp.cc', 'worker.cc',