From 588d2976b00972ea27cf007dbad8110d02cca02d Mon Sep 17 00:00:00 2001
From: "v.audacity" <v.audacity@47890b92-0858-11df-a26f-8b716316a5bc>
Date: Tue, 21 May 2013 02:35:29 +0000
Subject: [PATCH] further constraints, against negative pasted frequencies that
 wxValidator doesn't prevent

---
 src/effects/ChangePitch.cpp | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/src/effects/ChangePitch.cpp b/src/effects/ChangePitch.cpp
index 10997058e..9a0675419 100644
--- a/src/effects/ChangePitch.cpp
+++ b/src/effects/ChangePitch.cpp
@@ -576,19 +576,15 @@ void ChangePitchDialog::OnText_FromFrequency(wxCommandEvent & WXUNUSED(event))
 
    if (m_pTextCtrl_FromFrequency) {
       wxString str = m_pTextCtrl_FromFrequency->GetValue();
-      // Empty string causes unpredictable results with ToDouble() and later calculations.
-      if (str.IsEmpty())
-      {
-         this->FindWindow(wxID_OK)->Disable();
-         return;
-      }
       double newDouble;
       str.ToDouble(&newDouble);
-      // Zero frequency makes no sense, but user might still be editing, 
+      // Empty string causes unpredictable results with ToDouble() and later calculations.
+      // Non-positive frequency makes no sense, but user might still be editing, 
       // so it's not an error, but we do not want to update the values/controls. 
-      if (newDouble == 0.0) 
+      if (str.IsEmpty() || (newDouble <= 0.0) )
       {
          this->FindWindow(wxID_OK)->Disable();
+         this->FindWindow(ID_EFFECT_PREVIEW)->Disable();
          return;
       }
       m_FromFrequency = newDouble;
@@ -614,19 +610,15 @@ void ChangePitchDialog::OnText_ToFrequency(wxCommandEvent & WXUNUSED(event))
 
    if (m_pTextCtrl_ToFrequency) {
       wxString str = m_pTextCtrl_ToFrequency->GetValue();
-      // Empty string causes unpredictable results with ToDouble() and later calculations.
-      if (str.IsEmpty())
-      {
-         this->FindWindow(wxID_OK)->Disable();
-         return;
-      }
       double newDouble;
       str.ToDouble(&newDouble);
-      // Zero frequency makes no sense, but user might still be editing, 
+      // Empty string causes unpredictable results with ToDouble() and later calculations.
+      // Non-positive frequency makes no sense, but user might still be editing, 
       // so it's not an error, but we do not want to update the values/controls. 
-      if (newDouble == 0.0) 
+      if (str.IsEmpty() || (newDouble <= 0.0) )
       {
          this->FindWindow(wxID_OK)->Disable();
+         this->FindWindow(ID_EFFECT_PREVIEW)->Disable();
          return;
       }
       m_ToFrequency = newDouble;