From 273f81fad7e5fb40894a665a50fb57ae2bb8f243 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 10 Oct 2023 05:12:53 +0200 Subject: [PATCH] VarispeedDialog fixes, use 100% for speed 1.0 * Honor max-speed * Fix percentage off-by one (100%) * keep cents in range -50 .. +50 --- gtk2_ardour/varispeed_dialog.cc | 34 +++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/gtk2_ardour/varispeed_dialog.cc b/gtk2_ardour/varispeed_dialog.cc index 80fd2027f4..4b39553b32 100644 --- a/gtk2_ardour/varispeed_dialog.cc +++ b/gtk2_ardour/varispeed_dialog.cc @@ -99,10 +99,24 @@ VarispeedDialog::apply_semitones () int cents = _semitones_spinner.get_value () * 100 + _cents_spinner.get_value (); double speed = pow (2.0, ((double)cents / 1200.0)); + double const max_speed = ARDOUR::Config->get_max_transport_speed (); { PBD::Unwinder uw (ignore_changes, true); - _percent_adjustment.set_value (100. * pow (2.0, (cents/1200.0))); + + if (speed >= max_speed) { + speed = max_speed; + double semitones = 12. * (log (speed) / log(2.)); + int cents = 100 * fmod (semitones, 1.); + if (cents > 50) { + cents -= 100; + semitones += 1; + } + _semitones_adjustment.set_value (floor (semitones)); + _cents_adjustment.set_value (cents); + } + + _percent_adjustment.set_value (100. * speed); } if (_session && _session->default_play_speed () != speed) { @@ -117,14 +131,26 @@ VarispeedDialog::apply_percentage () return; } - double speed = 1.0 + (_percent_spinner.get_value() / 100.0); + double speed = _percent_spinner.get_value() / 100.0; + double max_speed = ARDOUR::Config->get_max_transport_speed (); { PBD::Unwinder uw (ignore_changes, true); + + if (speed >= max_speed) { + speed = max_speed; + _percent_adjustment.set_value (100. * speed); + } + double absspeed = ::abs (speed); - double semitones = 12. * (log (absspeed - 1.0) / log(2.)); + double semitones = 12. * (log (absspeed) / log(2.)); + int cents = 100 * fmod (semitones, 1.); + if (cents > 50) { + cents -= 100; + semitones += 1; + } _semitones_adjustment.set_value (floor (semitones)); - _cents_adjustment.set_value (100. * fmod (semitones, 1.)); + _cents_adjustment.set_value (cents); } if (_session && _session->default_play_speed () != speed) {