From 89a4c98bfd63454e50a9b5fafa272be9a56e1ff6 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Mon, 19 Jul 2021 02:30:25 +0200 Subject: [PATCH] Allow vari-speed control via scroll-wheel --- gtk2_ardour/shuttle_control.cc | 29 +++++++++++++++++++++ gtk2_ardour/shuttle_control.h | 1 + gtk2_ardour/varispeed_dialog.cc | 10 +++++--- gtk2_ardour/varispeed_dialog.h | 2 +- libs/ardour/ardour/plugin_region.h | 41 ++++++++++++++++++++++++++++++ 5 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 libs/ardour/ardour/plugin_region.h diff --git a/gtk2_ardour/shuttle_control.cc b/gtk2_ardour/shuttle_control.cc index 52056f72cb..d80a9b0d70 100644 --- a/gtk2_ardour/shuttle_control.cc +++ b/gtk2_ardour/shuttle_control.cc @@ -183,6 +183,7 @@ ShuttleControl::ShuttleControl () _vari_button.set_name ("vari button"); _vari_button.set_text(_("Vari")); _vari_button.signal_clicked.connect (sigc::mem_fun (*this, &ShuttleControl::varispeed_button_clicked)); + _vari_button.signal_scroll_event().connect (sigc::mem_fun (*this, &ShuttleControl::varispeed_button_scroll_event), false); /* gtkmm 2.4: the C++ wrapper doesn't work */ g_signal_connect ((GObject*) gobj(), "query-tooltip", G_CALLBACK (qt), NULL); @@ -206,6 +207,34 @@ ShuttleControl::varispeed_button_clicked () } } +bool +ShuttleControl::varispeed_button_scroll_event (GdkEventScroll* ev) +{ + double semi = 1.0; + + if (ev->state & Gtkmm2ext::Keyboard::GainFineScaleModifier) { + if (ev->state & Gtkmm2ext::Keyboard::GainExtraFineScaleModifier) { + semi = 0.1; + } else { + semi = 0.5; + } + } + + switch (ev->direction) { + case GDK_SCROLL_UP: + case GDK_SCROLL_RIGHT: + _vari_dialog.present (); + _vari_dialog.adj_semi (semi); + break; + case GDK_SCROLL_DOWN: + case GDK_SCROLL_LEFT: + _vari_dialog.present (); + _vari_dialog.adj_semi (-semi); + break; + } + return true; +} + void ShuttleControl::do_blink (bool onoff) { diff --git a/gtk2_ardour/shuttle_control.h b/gtk2_ardour/shuttle_control.h index 47e4f8a640..075760e932 100644 --- a/gtk2_ardour/shuttle_control.h +++ b/gtk2_ardour/shuttle_control.h @@ -121,6 +121,7 @@ protected: VarispeedDialog _vari_dialog; ArdourWidgets::ArdourButton _vari_button; void varispeed_button_clicked (); + bool varispeed_button_scroll_event (GdkEventScroll*); bool on_enter_notify_event (GdkEventCrossing*); bool on_leave_notify_event (GdkEventCrossing*); diff --git a/gtk2_ardour/varispeed_dialog.cc b/gtk2_ardour/varispeed_dialog.cc index 932060bbfa..04b188ffac 100644 --- a/gtk2_ardour/varispeed_dialog.cc +++ b/gtk2_ardour/varispeed_dialog.cc @@ -69,10 +69,13 @@ VarispeedDialog::on_key_press_event (GdkEventKey* ev) } void -VarispeedDialog::reset () +VarispeedDialog::adj_semi (double delta) { - _semitones_spinner.set_value (0); - _cents_spinner.set_value (0); + int cents = _semitones_spinner.get_value () * 100 + _cents_spinner.get_value (); + cents += 100.0 * delta; + + _semitones_spinner.set_value (cents / 100); + _cents_spinner.set_value (cents % 100); } void @@ -82,6 +85,7 @@ VarispeedDialog::apply_speed () double speed = pow (2.0, ((double)cents / 1200.0)); + printf ("VarispeedDialog::apply_speed\n"); if (_session && _session->default_play_speed () != speed) { _session->set_default_play_speed (speed); } diff --git a/gtk2_ardour/varispeed_dialog.h b/gtk2_ardour/varispeed_dialog.h index be341cde23..094075030f 100644 --- a/gtk2_ardour/varispeed_dialog.h +++ b/gtk2_ardour/varispeed_dialog.h @@ -31,10 +31,10 @@ class VarispeedDialog : public ArdourDialog { public: VarispeedDialog (); + void adj_semi (double delta); private: void apply_speed (); - void reset (); void on_show (); void on_hide (); diff --git a/libs/ardour/ardour/plugin_region.h b/libs/ardour/ardour/plugin_region.h new file mode 100644 index 0000000000..6aa2409e3c --- /dev/null +++ b/libs/ardour/ardour/plugin_region.h @@ -0,0 +1,41 @@ +#ifndef __ardour_plugin_region_h__ +#define __ardour_plugin_region_h__ + +namespace ARDOUR { + +class LIBARDOUR_API PluginRegion : public Region +{ +public: + ~PluginRegion(); + + XMLNode& state (); + int set_state (const XMLNode&, int version); + + /* Readable interface */ + virtual samplecnt_t read (Sample*, samplepos_t /*pos*/, samplecnt_t /*cnt*/, int /*channel*/) const; + virtual samplecnt_t readable_length() const { return length(); } + virtual uint32_t n_channels () const; + + /* automation */ + boost::shared_ptr + control(const Evoral::Parameter& id, bool create=false) { + return _automatable.control(id, create); + } + + boost::shared_ptr + control(const Evoral::Parameter& id) const { + return _automatable.control(id); + } + +private: + friend class RegionFactory; + PluginRegion (Session& s, boost::shared_ptr pi, samplepos_t, samplecnt_t); + + virtual void recompute_at_start () = 0; + virtual void recompute_at_end () = 0; + + Automatable _automatable; +}; + +} /* namespace ARDOUR */ +#endif /* __ardour_plugin_region_h__ */