📄 changespeed.cpp
字号:
pStaticText = new wxStaticText(this, -1, _("Percent Change:"), wxDefaultPosition, wxDefaultSize, 0); pBoxSizer_PercentChange->Add(pStaticText, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, 4); //v Override wxTextValidator to disallow negative values <= -100.0? m_pTextCtrl_PercentChange = new wxTextCtrl(this, ID_TEXT_PERCENTCHANGE, wxT("0.0"), wxDefaultPosition, wxSize(40, -1), 0, wxTextValidator(wxFILTER_NUMERIC)); pBoxSizer_PercentChange->Add(m_pTextCtrl_PercentChange, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT | wxALL, 4); pBoxSizer_Dialog->Add(pBoxSizer_PercentChange, 0, wxALIGN_CENTER | wxALL, 4); m_pSlider_PercentChange = new wxSlider(this, ID_SLIDER_PERCENTCHANGE, 0, PERCENTCHANGE_MIN, PERCENTCHANGE_MAX, wxDefaultPosition, wxSize(100, -1), wxSL_HORIZONTAL); pBoxSizer_Dialog->Add(m_pSlider_PercentChange, 1, wxGROW | wxALIGN_CENTER | wxLEFT | wxRIGHT, 4); pBoxSizer_Dialog->Add(0, 8, 0); // spacer // from/to Vinyl controls wxBoxSizer * pBoxSizer_Vinyl = new wxBoxSizer(wxHORIZONTAL); const wxString strArray_VinylRPM[] = {wxT("33 1/3"), wxT("45"), wxT("78"), /* i18n-hint: n/a is an English abbreviation meaning "not applicable" (in other words, unimportant, not relevant). */ _("n/a")}; const int numChoices = 4; pStaticText = new wxStaticText(this, -1, _("Standard Vinyl RPM: from"), wxDefaultPosition, wxDefaultSize, 0); pBoxSizer_Vinyl->Add(pStaticText, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, 4); m_pChoice_FromVinyl = new wxChoice(this, ID_CHOICE_FROMVINYL, wxDefaultPosition, wxSize(64, -1), numChoices, strArray_VinylRPM); pBoxSizer_Vinyl->Add(m_pChoice_FromVinyl, 0, wxALIGN_CENTER | wxALL, 4); pStaticText = new wxStaticText(this, -1, _("to"), wxDefaultPosition, wxDefaultSize, 0); pBoxSizer_Vinyl->Add(pStaticText, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, 4); m_pChoice_ToVinyl = new wxChoice(this, ID_CHOICE_TOVINYL, wxDefaultPosition, wxSize(64, -1), numChoices, strArray_VinylRPM); pBoxSizer_Vinyl->Add(m_pChoice_ToVinyl, 0, wxALIGN_CENTER | wxALL, 4); pBoxSizer_Dialog->Add(pBoxSizer_Vinyl, 0, wxALIGN_CENTER | wxALL, 4); // Preview, OK, & Cancel buttons pBoxSizer_Dialog->Add(0, 8, 0); // spacer wxBoxSizer * pBoxSizer_OK = new wxBoxSizer(wxHORIZONTAL); wxButton * pButton_Preview = new wxButton(this, ID_BUTTON_PREVIEW, m_pEffect->GetPreviewName()); pBoxSizer_OK->Add(pButton_Preview, 0, wxALIGN_CENTER | wxALL, 4); pBoxSizer_OK->Add(32, 8); // horizontal spacer wxButton * pButton_Cancel = new wxButton(this, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0); pBoxSizer_OK->Add(pButton_Cancel, 0, wxALIGN_CENTER | wxALL, 4); wxButton * pButton_OK = new wxButton(this, wxID_OK, _("OK"), wxDefaultPosition, wxDefaultSize, 0); pButton_OK->SetDefault(); pButton_OK->SetFocus(); pBoxSizer_OK->Add(pButton_OK, 0, wxALIGN_CENTER | wxALL, 4); pBoxSizer_Dialog->Add(pBoxSizer_OK, 0, wxALIGN_CENTER | wxALL, 8); this->SetAutoLayout(true); this->SetSizer(pBoxSizer_Dialog); pBoxSizer_Dialog->Fit(this); pBoxSizer_Dialog->SetSizeHints(this);}bool ChangeSpeedDialog::Validate(){ return true; }bool ChangeSpeedDialog::TransferDataToWindow(){ m_bLoopDetect = true; // percent change controls this->Update_Text_PercentChange(); this->Update_Slider_PercentChange(); // from/to Vinyl controls if (m_pChoice_FromVinyl) m_pChoice_FromVinyl->SetSelection(m_FromVinyl); if (m_pChoice_ToVinyl) m_pChoice_ToVinyl->SetSelection(m_ToVinyl); m_bLoopDetect = false; return true;}bool ChangeSpeedDialog::TransferDataFromWindow(){ wxString str; // percent change controls if (m_pTextCtrl_PercentChange) { double newValue = 0; str = m_pTextCtrl_PercentChange->GetValue(); str.ToDouble(&newValue); m_PercentChange = newValue; } // Ignore Slider_PercentChange because TextCtrl_PercentChange // always tracks it & is more precise (decimal points). // from/to Vinyl controls if (m_pChoice_FromVinyl) m_FromVinyl = m_pChoice_FromVinyl->GetSelection(); if (m_pChoice_ToVinyl) m_ToVinyl = m_pChoice_ToVinyl->GetSelection(); return true;}// handler implementations for ChangeSpeedDialogvoid ChangeSpeedDialog::OnText_PercentChange(wxCommandEvent & event){ if (m_bLoopDetect) return; if (m_pTextCtrl_PercentChange) { double newValue = 0; wxString str = m_pTextCtrl_PercentChange->GetValue(); str.ToDouble(&newValue); m_PercentChange = newValue; m_bLoopDetect = true; this->Update_Slider_PercentChange(); this->Update_Vinyl(); m_bLoopDetect = false; FindWindow(wxID_OK)->Enable(m_PercentChange > -100.0); }}void ChangeSpeedDialog::OnSlider_PercentChange(wxCommandEvent & event){ if (m_bLoopDetect) return; if (m_pSlider_PercentChange) { m_PercentChange = (double)(m_pSlider_PercentChange->GetValue()); // Warp positive values to actually go up faster & further than negatives. if (m_PercentChange > 0.0) m_PercentChange = pow(m_PercentChange, PERCENTCHANGE_SLIDER_WARP); m_bLoopDetect = true; this->Update_Text_PercentChange(); this->Update_Vinyl(); m_bLoopDetect = false; }}void ChangeSpeedDialog::OnChoice_FromVinyl(wxCommandEvent & event){ if (m_bLoopDetect) return; if (m_pChoice_FromVinyl) { m_FromVinyl = m_pChoice_FromVinyl->GetSelection(); m_bLoopDetect = true; this->Update_PercentChange(); m_bLoopDetect = false; }}void ChangeSpeedDialog::OnChoice_ToVinyl(wxCommandEvent & event){ if (m_bLoopDetect) return; if (m_pChoice_ToVinyl) { m_ToVinyl = m_pChoice_ToVinyl->GetSelection(); m_bLoopDetect = true; this->Update_PercentChange(); m_bLoopDetect = false; }}void ChangeSpeedDialog::OnPreview(wxCommandEvent &event){ TransferDataFromWindow(); // Save & restore parameters around Preview, because we didn't do OK. double oldPercentChange = m_pEffect->m_PercentChange; m_pEffect->m_PercentChange = m_PercentChange; m_pEffect->Preview(); m_pEffect->m_PercentChange = oldPercentChange; }void ChangeSpeedDialog::OnOk(wxCommandEvent & event){ TransferDataFromWindow(); if (Validate()) EndModal(true); else event.Skip();}void ChangeSpeedDialog::OnCancel(wxCommandEvent & event){ EndModal(false);}// helper fnsvoid ChangeSpeedDialog::Update_Text_PercentChange(){ if (m_pTextCtrl_PercentChange) { wxString str; str.Printf(wxT("%.3f"), m_PercentChange); m_pTextCtrl_PercentChange->SetValue(str); }}void ChangeSpeedDialog::Update_Slider_PercentChange(){ if (m_pSlider_PercentChange) { double unwarped = m_PercentChange; if (unwarped > 0.0) // Un-warp values above zero to actually go up to PERCENTCHANGE_MAX. unwarped = pow(m_PercentChange, (1.0 / PERCENTCHANGE_SLIDER_WARP)); // Add 0.5 to unwarped so trunc -> round. m_pSlider_PercentChange->SetValue((int)(unwarped + 0.5)); }}void ChangeSpeedDialog::Update_Vinyl() // Update Vinyl controls for new percent change.{ if (m_pChoice_ToVinyl) // Chances are so low that the slider will exactly match a // standard ratio, just turn it "n/a" unless it's 0.0. if ((m_PercentChange == 0.0) && m_pChoice_FromVinyl) m_pChoice_ToVinyl->SetSelection(m_pChoice_FromVinyl->GetSelection()); else m_pChoice_ToVinyl->SetSelection(CHOICE_NA);}void ChangeSpeedDialog::Update_PercentChange() // Update percent change controls for new Vinyl values.{ // If m_FromVinyl & m_ToVinyl are set, then there's a new percent change. if ((m_FromVinyl != CHOICE_NA) && (m_ToVinyl != CHOICE_NA)) { double fromRPM; double toRPM; switch (m_FromVinyl) { default: case CHOICE_33ANDATHIRD: fromRPM = 33.0 + (1.0 / 3.0); break; case CHOICE_45: fromRPM = 45.0; break; case CHOICE_78: fromRPM = 78; break; } switch (m_ToVinyl) { default: case CHOICE_33ANDATHIRD: toRPM = 33.0 + (1.0 / 3.0); break; case CHOICE_45: toRPM = 45.0; break; case CHOICE_78: toRPM = 78; break; } m_PercentChange = ((toRPM * 100.0) / fromRPM) - 100.0; this->Update_Text_PercentChange(); this->Update_Slider_PercentChange(); }}// Indentation settings for Vim and Emacs and unique identifier for Arch, a// version control system. Please do not modify past this point.//// Local Variables:// c-basic-offset: 3// indent-tabs-mode: nil// End://// vim: et sts=3 sw=3// arch-tag: 84775e31-325f-46fd-bcec-7336b0a574e1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -