1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-23 15:02:56 +02:00

Bug 1982 - Numeric entry in Play-at-Speed dialog allows entries not supported by the slider or the PAS functionality

This commit is contained in:
Leland Lucius
2021-02-14 15:47:19 -06:00
parent 379348898d
commit 7356c735ae
2 changed files with 53 additions and 16 deletions

View File

@@ -63,6 +63,7 @@ or ASlider.
#include "../ProjectWindowBase.h" #include "../ProjectWindowBase.h"
#include "../ShuttleGui.h" #include "../ShuttleGui.h"
#include "../Theme.h" #include "../Theme.h"
#include "valnum.h"
#include "../AllThemeResources.h" #include "../AllThemeResources.h"
@@ -275,13 +276,34 @@ SliderDialog::SliderDialog(wxWindow * parent, wxWindowID id,
{ {
SetName(); SetName();
mpOrigin = pSource; mpOrigin = pSource;
mValue = mpOrigin->Get(false);
auto prec = 2;
auto trailing = NumValidatorStyle::TWO_TRAILING_ZEROES;
if (style == DB_SLIDER)
{
prec = 1;
trailing = NumValidatorStyle::ONE_TRAILING_ZERO;
}
ShuttleGui S(this, eIsCreating); ShuttleGui S(this, eIsCreating);
S.StartVerticalLay(); S.StartVerticalLay();
{ {
mTextCtrl = S.Validator<wxTextValidator>(wxFILTER_NUMERIC) if (style == PAN_SLIDER)
.AddTextBox( {}, wxEmptyString, 15); {
mTextCtrl = S
.Validator<IntegerValidator<float>>(
&mValue, NumValidatorStyle::DEFAULT, -100.0, 100.0)
.AddTextBox({}, wxEmptyString, 15);
}
else
{
mTextCtrl = S
.Validator<FloatingPointValidator<float>>(
prec, &mValue, trailing, mpOrigin->GetMinValue(), mpOrigin->GetMaxValue())
.AddTextBox({}, wxEmptyString, 15);
}
mSlider = safenew ASlider(S.GetParent(), mSlider = safenew ASlider(S.GetParent(),
wxID_ANY, wxID_ANY,
title, title,
@@ -308,7 +330,10 @@ SliderDialog::~SliderDialog()
bool SliderDialog::TransferDataToWindow() bool SliderDialog::TransferDataToWindow()
{ {
float value = mSlider->Get(false); float value = mSlider->Get(false);
mTextCtrl->SetValue(wxString::Format(wxT("%g"), value)); mValue = mStyle == PAN_SLIDER
? value * 100.0
: value;
mTextCtrl->GetValidator()->TransferToWindow();
mTextCtrl->SetSelection(-1, -1); mTextCtrl->SetSelection(-1, -1);
if (mpOrigin) { if (mpOrigin) {
mpOrigin->Set(value); mpOrigin->Set(value);
@@ -320,18 +345,13 @@ bool SliderDialog::TransferDataToWindow()
bool SliderDialog::TransferDataFromWindow() bool SliderDialog::TransferDataFromWindow()
{ {
// Bug #2458 if (mTextCtrl->GetValidator()->TransferFromWindow())
//
// If the user clears the text control, the ToDouble below will NOT set "value"
// since it checks the length of the incoming string and bypasses setting it if
// it's empty. So initialize "value" for good measure and check the return value
// of ToDouble for success before using "value".
double value = 0.0;
if (mTextCtrl->GetValue().ToDouble(&value))
{ {
float value = mValue;
if (mStyle == DB_SLIDER) if (mStyle == DB_SLIDER)
value = DB_TO_LINEAR(value); value = DB_TO_LINEAR(value);
else if (mStyle == PAN_SLIDER)
value /= 100.0;
mSlider->Set(value); mSlider->Set(value);
if (mpOrigin) { if (mpOrigin) {
mpOrigin->Set(value); mpOrigin->Set(value);
@@ -350,7 +370,10 @@ void SliderDialog::OnSlider(wxCommandEvent & event)
void SliderDialog::OnTextChange(wxCommandEvent & event) void SliderDialog::OnTextChange(wxCommandEvent & event)
{ {
if (mTextCtrl->GetValidator()->TransferFromWindow())
{
TransferDataFromWindow(); TransferDataFromWindow();
}
event.Skip(false); event.Skip(false);
} }
@@ -1502,7 +1525,7 @@ void LWSlider::Refresh()
mParent->Refresh(false); mParent->Refresh(false);
} }
bool LWSlider::GetEnabled() bool LWSlider::GetEnabled() const
{ {
return mEnabled; return mEnabled;
} }
@@ -1517,6 +1540,16 @@ void LWSlider::SetEnabled(bool enabled)
Refresh(); Refresh();
} }
float LWSlider::GetMinValue() const
{
return mMinValue;
}
float LWSlider::GetMaxValue() const
{
return mMaxValue;
}
// //
// ASlider // ASlider
// //

View File

@@ -141,7 +141,10 @@ class LWSlider
bool ShowDialog(wxPoint pos); bool ShowDialog(wxPoint pos);
void SetEnabled(bool enabled); void SetEnabled(bool enabled);
bool GetEnabled(); bool GetEnabled() const;
float GetMinValue() const;
float GetMaxValue() const;
static void DeleteSharedTipPanel(); static void DeleteSharedTipPanel();
@@ -353,6 +356,7 @@ class SliderDialog final : public wxDialogWrapper
wxTextCtrl * mTextCtrl; wxTextCtrl * mTextCtrl;
int mStyle; int mStyle;
LWSlider * mpOrigin; LWSlider * mpOrigin;
float mValue;
public: public:
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()