From 879b09d9202210f45e984f6dd1c529f3209b1b96 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 23 Sep 2016 15:24:45 -0500 Subject: [PATCH] stop crashes from out-of-range values --- libs/surfaces/push2/mix.cc | 15 +++++---------- libs/surfaces/push2/push2.cc | 10 ++++++++-- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/libs/surfaces/push2/mix.cc b/libs/surfaces/push2/mix.cc index 58e29fc877..c61ee45008 100644 --- a/libs/surfaces/push2/mix.cc +++ b/libs/surfaces/push2/mix.cc @@ -44,8 +44,9 @@ #include "ardour/vca_manager.h" #include "canvas/colors.h" -#include "canvas/rectangle.h" #include "canvas/line.h" +#include "canvas/rectangle.h" +#include "canvas/text.h" #include "gtkmm2ext/gui_thread.h" @@ -400,15 +401,9 @@ MixLayout::strip_vpot (int n, int delta) boost::shared_ptr ac = knobs[n]->controllable(); if (ac) { - if (ac->is_gain_like()) { - /* 128 steps from fader position 0 to 1.0 .. - */ - const double new_fader_position = min (1.0, max (0.0, ac->internal_to_interface (ac->get_value()) + ((1.0 / 128.0) * delta))); - ac->set_value (ac->interface_to_internal (new_fader_position), PBD::Controllable::UseGroup); - } else { - /* 128 steps from min to max */ - ac->set_value (ac->get_value() + (((ac->upper() - ac->lower()) / 128.0) * delta) , PBD::Controllable::UseGroup); - } + ac->set_value (ac->interface_to_internal ( + min (ac->upper(), max (ac->lower(), ac->internal_to_interface (ac->get_value()) + (delta/256.0)))), + PBD::Controllable::UseGroup); } } diff --git a/libs/surfaces/push2/push2.cc b/libs/surfaces/push2/push2.cc index fb33a916cb..7e9316c17e 100644 --- a/libs/surfaces/push2/push2.cc +++ b/libs/surfaces/push2/push2.cc @@ -1094,7 +1094,11 @@ Push2::other_vpot (int n, int delta) click_gain = session->click_gain(); if (click_gain) { boost::shared_ptr ac = click_gain->gain_control(); - ac->set_value (ac->interface_to_internal (ac->internal_to_interface (ac->get_value()) + (delta/128.0)), PBD::Controllable::UseGroup); + if (ac) { + ac->set_value (ac->interface_to_internal ( + min (ac->upper(), max (ac->lower(), ac->internal_to_interface (ac->get_value()) + (delta/256.0)))), + PBD::Controllable::UseGroup); + } } break; case 2: @@ -1102,7 +1106,9 @@ Push2::other_vpot (int n, int delta) if (master) { boost::shared_ptr ac = master->gain_control(); if (ac) { - ac->set_value (ac->interface_to_internal (ac->internal_to_interface (ac->get_value()) + (delta/128.0)), PBD::Controllable::UseGroup); + ac->set_value (ac->interface_to_internal ( + min (ac->upper(), max (ac->lower(), ac->internal_to_interface (ac->get_value()) + (delta/256.0)))), + PBD::Controllable::UseGroup); } } break;