Frequency Selection toolbar from Paul Licameli.

Linux/Mac will need new files adding to project, SpectralSelectionBar.cpp, NumericTextCtrl.cpp.
This commit is contained in:
james.k.crook@gmail.com 2014-11-08 15:18:43 +00:00
parent 327bd905de
commit 67d2b274e2
36 changed files with 3050 additions and 2192 deletions

View File

@ -36,7 +36,7 @@
#include "Project.h"
#include "Track.h"
#include "ViewInfo.h"
#include "widgets/TimeTextCtrl.h"
#include "widgets/NumericTextCtrl.h"
#include "FileDialog.h"
@ -226,7 +226,7 @@ bool LabelDialog::TransferDataToWindow()
int i;
// Set the editor parameters. Do this each time since they may change
// due to new tracks and change in TimeTextCtrl format. Rate won't
// due to new tracks and change in NumericTextCtrl format. Rate won't
// change but might as well leave it here.
mChoiceEditor->SetChoices(mTrackNames);
mTimeEditor->SetFormat(mFormat);

View File

@ -67,7 +67,6 @@ simplifies construction of menu items.
#include "export/Export.h"
#include "export/ExportMultiple.h"
#include "prefs/PrefsDialog.h"
#include "widgets/TimeTextCtrl.h"
#include "ShuttleGui.h"
#include "HistoryWindow.h"
#include "LyricsWindow.h"
@ -714,8 +713,12 @@ void AudacityProject::CreateMenusAndCommands()
c->AddCheck(wxT("ShowPlayMeterTB"), _("&Playback Meter Toolbar"), FN(OnShowPlayMeterToolBar), 0, AlwaysEnabledFlag, AlwaysEnabledFlag);
/* i18n-hint: Clicking this menu item shows the toolbar with the mixer*/
c->AddCheck(wxT("ShowMixerTB"), _("Mi&xer Toolbar"), FN(OnShowMixerToolBar), 0, AlwaysEnabledFlag, AlwaysEnabledFlag);
/* i18n-hint: Clicking this menu item shows the toolbar for selecting audio*/
/* i18n-hint: Clicking this menu item shows the toolbar for selecting a time range of audio*/
c->AddCheck(wxT("ShowSelectionTB"), _("&Selection Toolbar"), FN(OnShowSelectionToolBar), 0, AlwaysEnabledFlag, AlwaysEnabledFlag);
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
/* i18n-hint: Clicking this menu item shows the toolbar for selecting a frequency range of audio*/
c->AddCheck(wxT("ShowSpectralSelectionTB"), _("&Spectral Selection Toolbar"), FN(OnShowSpectralSelectionToolBar), 0, AlwaysEnabledFlag, AlwaysEnabledFlag);
#endif
/* i18n-hint: Clicking this menu item shows a toolbar that has some tools in it*/
c->AddCheck(wxT("ShowToolsTB"), _("T&ools Toolbar"), FN(OnShowToolsToolBar), 0, AlwaysEnabledFlag, AlwaysEnabledFlag);
/* i18n-hint: Clicking this menu item shows the toolbar for transcription (currently just vary play speed)*/
@ -1824,8 +1827,6 @@ void AudacityProject::ModifyToolbarMenus()
return;
}
mCommandManager.Check(wxT("ShowTransportTB"),
mToolManager->IsVisible(TransportBarID));
mCommandManager.Check(wxT("ShowDeviceTB"),
mToolManager->IsVisible(DeviceBarID));
mCommandManager.Check(wxT("ShowEditTB"),
@ -1840,10 +1841,16 @@ void AudacityProject::ModifyToolbarMenus()
mToolManager->IsVisible(MixerBarID));
mCommandManager.Check(wxT("ShowSelectionTB"),
mToolManager->IsVisible(SelectionBarID));
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
mCommandManager.Check(wxT("ShowSpectralSelectionTB"),
mToolManager->IsVisible(SpectralSelectionBarID));
#endif
mCommandManager.Check(wxT("ShowToolsTB"),
mToolManager->IsVisible(ToolsBarID));
mCommandManager.Check(wxT("ShowTranscriptionTB"),
mToolManager->IsVisible(TranscriptionBarID));
mCommandManager.Check(wxT("ShowTransportTB"),
mToolManager->IsVisible(TransportBarID));
// Now, go through each toolbar, and call EnableDisableButtons()
for (int i = 0; i < ToolBarCount; i++) {
@ -4909,6 +4916,14 @@ void AudacityProject::OnShowSelectionToolBar()
ModifyToolbarMenus();
}
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
void AudacityProject::OnShowSpectralSelectionToolBar()
{
mToolManager->ShowHide( SpectralSelectionBarID );
ModifyToolbarMenus();
}
#endif
void AudacityProject::OnShowToolsToolBar()
{
mToolManager->ShowHide( ToolsBarID );

View File

@ -282,6 +282,9 @@ void OnShowRecordMeterToolBar();
void OnShowPlayMeterToolBar();
void OnShowMixerToolBar();
void OnShowSelectionToolBar();
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
void OnShowSpectralSelectionToolBar();
#endif
void OnShowToolsToolBar();
void OnShowTranscriptionToolBar();
void OnResetToolBars();

View File

@ -148,6 +148,7 @@ scroll information. It also has some status flags.
#include "toolbars/MeterToolBar.h"
#include "toolbars/MixerToolBar.h"
#include "toolbars/SelectionBar.h"
#include "toolbars/SpectralSelectionBar.h"
#include "toolbars/ToolsToolBar.h"
#include "toolbars/TranscriptionToolBar.h"
@ -845,6 +846,9 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id,
//
mToolManager = new ToolManager( this );
GetSelectionBar()->SetListener(this);
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
GetSpectralSelectionBar()->SetListener(this);
#endif
mToolManager->LayoutToolBars();
// Fix the sliders on the mixer toolbar so that the tip windows
@ -1224,6 +1228,83 @@ void AudacityProject::AS_SetSelectionFormat(const wxString & format)
gPrefs->Flush();
}
double AudacityProject::SSBL_GetRate() const
{
return mRate;
}
const wxString & AudacityProject::SSBL_GetFrequencySelectionFormatName()
{
return GetFrequencySelectionFormatName();
}
void AudacityProject::SSBL_SetFrequencySelectionFormatName(const wxString & formatName)
{
mFrequencySelectionFormatName = formatName;
gPrefs->Write(wxT("/FrequencySelectionFormatName"), mFrequencySelectionFormatName);
gPrefs->Flush();
}
const wxString & AudacityProject::SSBL_GetLogFrequencySelectionFormatName()
{
return GetLogFrequencySelectionFormatName();
}
void AudacityProject::SSBL_SetLogFrequencySelectionFormatName(const wxString & formatName)
{
mLogFrequencySelectionFormatName = formatName;
gPrefs->Write(wxT("/LogFrequencySelectionFormatName"), mLogFrequencySelectionFormatName);
gPrefs->Flush();
}
void AudacityProject::SSBL_ModifySpectralSelection(double &bottom, double &top, bool done)
{
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
double nyq = mRate / 2.0;
bottom = std::max(1.0, std::min(nyq, bottom));
top = std::max(0.0, std::min(nyq, top));
mViewInfo.selectedRegion.setFrequencies(bottom, top);
mTrackPanel->Refresh(false);
if (done) {
ModifyState(false);
}
#else
bottom; top; done;
#endif
}
const wxString & AudacityProject::GetFrequencySelectionFormatName() const
{
return mFrequencySelectionFormatName;
}
void AudacityProject::SetFrequencySelectionFormatName(const wxString & formatName)
{
SSBL_SetFrequencySelectionFormatName(formatName);
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
if (GetSpectralSelectionBar()) {
GetSpectralSelectionBar()->SetFrequencySelectionFormatName(formatName);
}
#endif
}
const wxString & AudacityProject::GetLogFrequencySelectionFormatName() const
{
return mLogFrequencySelectionFormatName;
}
void AudacityProject::SetLogFrequencySelectionFormatName(const wxString & formatName)
{
SSBL_SetLogFrequencySelectionFormatName(formatName);
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
if (GetSpectralSelectionBar()) {
GetSpectralSelectionBar()->SetLogFrequencySelectionFormatName(formatName);
}
#endif
}
void AudacityProject::SetSelectionFormat(const wxString & format)
{
AS_SetSelectionFormat(format);
@ -1232,7 +1313,7 @@ void AudacityProject::SetSelectionFormat(const wxString & format)
}
}
const wxString & AudacityProject::GetSelectionFormat()
const wxString & AudacityProject::GetSelectionFormat() const
{
return mSelectionFormat;
}
@ -4066,11 +4147,21 @@ MixerToolBar *AudacityProject::GetMixerToolBar()
SelectionBar *AudacityProject::GetSelectionBar()
{
return (SelectionBar *)
(mToolManager ?
mToolManager->GetToolBar(SelectionBarID) :
NULL);
(mToolManager ?
mToolManager->GetToolBar(SelectionBarID) :
NULL);
}
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
SpectralSelectionBar *AudacityProject::GetSpectralSelectionBar()
{
return static_cast<SpectralSelectionBar*>(
(mToolManager ?
mToolManager->GetToolBar(SpectralSelectionBarID) :
NULL));
}
#endif
ToolsToolBar *AudacityProject::GetToolsToolBar()
{
return (ToolsToolBar *)
@ -4388,6 +4479,10 @@ void AudacityProject::TP_DisplaySelection()
GetSelectionBar()->SetTimes(mViewInfo.selectedRegion.t0(),
mViewInfo.selectedRegion.t1(), audioTime);
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
GetSpectralSelectionBar()->SetFrequencies
(mViewInfo.selectedRegion.f0(), mViewInfo.selectedRegion.f1());
#endif
if (!gAudioIO->IsBusy() && !mLockPlayRegion)
mRuler->SetPlayRegion(mViewInfo.selectedRegion.t0(),

View File

@ -19,6 +19,7 @@
#define __AUDACITY_PROJECT__
#include "Audacity.h"
#include "Experimental.h"
#include "DirManager.h"
#include "UndoManager.h"
@ -29,6 +30,7 @@
#include "effects/EffectManager.h"
#include "xml/XMLTagHandler.h"
#include "toolbars/SelectionBarListener.h"
#include "toolbars/SpectralSelectionBarListener.h"
#include <wx/defs.h>
#include <wx/event.h>
@ -66,6 +68,7 @@ class EditToolBar;
class MeterToolBar;
class MixerToolBar;
class SelectionBar;
class SpectralSelectionBar;
class Toolbar;
class ToolManager;
class ToolsToolBar;
@ -122,6 +125,7 @@ class ImportXMLTagHandler : public XMLTagHandler
class AUDACITY_DLL_API AudacityProject: public wxFrame,
public TrackPanelListener,
public SelectionBarListener,
public SpectralSelectionBarListener,
public XMLTagHandler,
public AudioIOListener
{
@ -313,7 +317,15 @@ class AUDACITY_DLL_API AudacityProject: public wxFrame,
// Selection Format
void SetSelectionFormat(const wxString & format);
const wxString & GetSelectionFormat();
const wxString & GetSelectionFormat() const;
// Spectral Selection Formats
void SetFrequencySelectionFormatName(const wxString & format);
const wxString & GetFrequencySelectionFormatName() const;
void SetLogFrequencySelectionFormatName(const wxString & format);
const wxString & GetLogFrequencySelectionFormatName() const;
// Scrollbars
@ -362,6 +374,9 @@ class AUDACITY_DLL_API AudacityProject: public wxFrame,
MeterToolBar *GetMeterToolBar();
MixerToolBar *GetMixerToolBar();
SelectionBar *GetSelectionBar();
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
SpectralSelectionBar *GetSpectralSelectionBar();
#endif
ToolsToolBar *GetToolsToolBar();
TranscriptionToolBar *GetTranscriptionToolBar();
@ -378,6 +393,18 @@ class AUDACITY_DLL_API AudacityProject: public wxFrame,
virtual void AS_SetSelectionFormat(const wxString & format);
virtual void AS_ModifySelection(double &start, double &end, bool done);
// SpectralSelectionBarListener callback methods
virtual double SSBL_GetRate() const;
virtual const wxString & SSBL_GetFrequencySelectionFormatName();
virtual void SSBL_SetFrequencySelectionFormatName(const wxString & formatName);
virtual const wxString & SSBL_GetLogFrequencySelectionFormatName();
virtual void SSBL_SetLogFrequencySelectionFormatName(const wxString & formatName);
virtual void SSBL_ModifySpectralSelection(double &bottom, double &top, bool done);
void SetStateTo(unsigned int n);
// XMLTagHandler callback methods
@ -453,6 +480,8 @@ class AUDACITY_DLL_API AudacityProject: public wxFrame,
int mSnapTo;
wxString mSelectionFormat;
wxString mFrequencySelectionFormatName;
wxString mLogFrequencySelectionFormatName;
TrackList *mLastSavedTracks;

View File

@ -16,7 +16,7 @@
#include "Snap.h"
#include "TrackPanel.h"
#include "WaveTrack.h"
#include "widgets/TimeTextCtrl.h"
#include "widgets/NumericTextCtrl.h"
// Change this to "true" to snap to nearest and "false" to snap to previous
// As of 2013/10/23, defaulting to "true" until a decision is made on
@ -30,6 +30,7 @@ static int CompareSnapPoints(SnapPoint *s1, SnapPoint *s2)
SnapManager::SnapManager(TrackList *tracks, TrackClipArray *exclusions,
double zoom, int pixelTolerance, bool noTimeSnap)
: mConverter(NumericConverter::TIME)
{
int i;
@ -110,10 +111,10 @@ SnapManager::SnapManager(TrackList *tracks, TrackClipArray *exclusions,
void SnapManager::CondListAdd(double t, Track *tr)
{
if (mSnapToTime) {
mConverter.SetTimeValue(t);
mConverter.SetValue(t);
}
if (!mSnapToTime || mConverter.GetTimeValue() == t) {
if (!mSnapToTime || mConverter.GetValue() == t) {
mSnapPoints->Add(new SnapPoint(t, tr));
}
}
@ -259,7 +260,7 @@ bool SnapManager::Snap(Track *currentTrack,
// Snap time to the grid
mConverter.ValueToControls(t, GetActiveProject()->GetSnapTo() == SNAP_NEAREST);
mConverter.ControlsToValue();
*out_t = mConverter.GetTimeValue();
*out_t = mConverter.GetValue();
*snappedTime = true;
}
}

View File

@ -19,7 +19,7 @@
#include <wx/dynarray.h>
#include "Track.h"
#include "widgets/TimeTextCtrl.h"
#include "widgets/NumericTextCtrl.h"
class TrackClipArray;
@ -80,7 +80,7 @@ class SnapManager {
SnapPointArray *mSnapPoints;
// Info for snap-to-time
TimeConverter mConverter;
NumericConverter mConverter;
bool mSnapToTime;
};

View File

@ -21,6 +21,7 @@
#include <wx/sizer.h>
#include <wx/string.h>
#include "widgets/NumericTextCtrl.h"
#include "ShuttleGui.h"
#include "TimeDialog.h"
@ -53,7 +54,8 @@ void TimeDialog::PopulateOrExchange(ShuttleGui &S)
S.StartStatic(mPrompt, true);
{
mTimeCtrl = new
TimeTextCtrl(this,
NumericTextCtrl(
NumericConverter::TIME, this,
wxID_ANY,
mFormat,
mTime,
@ -82,7 +84,7 @@ bool TimeDialog::TransferDataToWindow()
{
mTimeCtrl->SetFormatString(mTimeCtrl->GetBuiltinFormat(mFormat));
mTimeCtrl->SetSampleRate(mRate);
mTimeCtrl->SetTimeValue(mTime);
mTimeCtrl->SetValue(mTime);
mTimeCtrl->SetFocus();
return true;
@ -90,7 +92,7 @@ bool TimeDialog::TransferDataToWindow()
bool TimeDialog::TransferDataFromWindow()
{
mTime = mTimeCtrl->GetTimeValue();
mTime = mTimeCtrl->GetValue();
return true;
}

View File

@ -16,8 +16,7 @@
#include <wx/event.h>
#include <wx/string.h>
#include "widgets/TimeTextCtrl.h"
class NumericTextCtrl;
class ShuttleGui;
class TimeDialog:public wxDialog
@ -51,7 +50,7 @@ class TimeDialog:public wxDialog
double mRate;
double mTime;
TimeTextCtrl *mTimeCtrl;
NumericTextCtrl *mTimeCtrl;
DECLARE_EVENT_TABLE();
};

View File

@ -33,6 +33,7 @@
#include "Project.h"
#include "Internat.h"
#include "Prefs.h"
#include "widgets/NumericTextCtrl.h"
#define TIMER_ID 7000
@ -86,7 +87,8 @@ TimerRecordDialog::TimerRecordDialog(wxWindow* parent)
ShuttleGui S(this, eIsCreating);
this->PopulateOrExchange(S);
// Set initial focus to "1" of "01h" in Duration TimeTextCtrl, instead of OK button (default).
// Set initial focus to "1" of "01h" in Duration NumericTextCtrl,
// instead of OK button (default).
m_pTimeTextCtrl_Duration->SetFocus();
m_pTimeTextCtrl_Duration->SetFieldFocus(3);
@ -104,7 +106,7 @@ void TimerRecordDialog::OnTimer(wxTimerEvent& WXUNUSED(event))
if (m_DateTime_Start < dateTime_UNow) {
m_DateTime_Start = dateTime_UNow;
m_pDatePickerCtrl_Start->SetValue(m_DateTime_Start);
m_pTimeTextCtrl_Start->SetTimeValue(wxDateTime_to_AudacityTime(m_DateTime_Start));
m_pTimeTextCtrl_Start->SetValue(wxDateTime_to_AudacityTime(m_DateTime_Start));
this->UpdateEnd(); // Keep Duration constant and update End for changed Start.
}
}
@ -112,7 +114,7 @@ void TimerRecordDialog::OnTimer(wxTimerEvent& WXUNUSED(event))
void TimerRecordDialog::OnDatePicker_Start(wxDateEvent& WXUNUSED(event))
{
m_DateTime_Start = m_pDatePickerCtrl_Start->GetValue();
double dTime = m_pTimeTextCtrl_Start->GetTimeValue();
double dTime = m_pTimeTextCtrl_Start->GetValue();
long hr = (long)(dTime / 3600.0);
long min = (long)((dTime - (hr * 3600.0)) / 60.0);
long sec = (long)(dTime - (hr * 3600.0) - (min * 60.0));
@ -133,16 +135,18 @@ void TimerRecordDialog::OnDatePicker_Start(wxDateEvent& WXUNUSED(event))
void TimerRecordDialog::OnTimeText_Start(wxCommandEvent& WXUNUSED(event))
{
//v TimeTextCtrl doesn't implement upper ranges, i.e., if I tell it "024 h 060 m 060 s", then
// user increments the hours past 23, it rolls over to 0 (although if you increment below 0, it stays at 0).
//v NumericTextCtrl doesn't implement upper ranges, i.e.,
// if I tell it "024 h 060 m 060 s", then
// user increments the hours past 23, it rolls over to 0
// (although if you increment below 0, it stays at 0).
// So instead, set the max to 99 and just catch hours > 24 and fix the ctrls.
double dTime = m_pTimeTextCtrl_Start->GetTimeValue();
double dTime = m_pTimeTextCtrl_Start->GetValue();
long days = (long)(dTime / (24.0 * 3600.0));
if (days > 0) {
dTime -= (double)days * 24.0 * 3600.0;
m_DateTime_Start += wxTimeSpan::Days(days);
m_pDatePickerCtrl_Start->SetValue(m_DateTime_Start);
m_pTimeTextCtrl_Start->SetTimeValue(dTime);
m_pTimeTextCtrl_Start->SetValue(dTime);
}
wxDateEvent dummyDateEvent;
@ -152,7 +156,7 @@ void TimerRecordDialog::OnTimeText_Start(wxCommandEvent& WXUNUSED(event))
void TimerRecordDialog::OnDatePicker_End(wxDateEvent& WXUNUSED(event))
{
m_DateTime_End = m_pDatePickerCtrl_End->GetValue();
double dTime = m_pTimeTextCtrl_End->GetTimeValue();
double dTime = m_pTimeTextCtrl_End->GetValue();
long hr = (long)(dTime / 3600.0);
long min = (long)((dTime - (hr * 3600.0)) / 60.0);
long sec = (long)(dTime - (hr * 3600.0) - (min * 60.0));
@ -165,7 +169,7 @@ void TimerRecordDialog::OnDatePicker_End(wxDateEvent& WXUNUSED(event))
if (m_DateTime_End < m_DateTime_Start) {
m_DateTime_End = m_DateTime_Start;
m_pDatePickerCtrl_End->SetValue(m_DateTime_End);
m_pTimeTextCtrl_End->SetTimeValue(wxDateTime_to_AudacityTime(m_DateTime_End));
m_pTimeTextCtrl_End->SetValue(wxDateTime_to_AudacityTime(m_DateTime_End));
}
this->UpdateDuration(); // Keep Start constant and update Duration for changed End.
@ -173,16 +177,18 @@ void TimerRecordDialog::OnDatePicker_End(wxDateEvent& WXUNUSED(event))
void TimerRecordDialog::OnTimeText_End(wxCommandEvent& WXUNUSED(event))
{
//v TimeTextCtrl doesn't implement upper ranges, i.e., if I tell it "024 h 060 m 060 s", then
// user increments the hours past 23, it rolls over to 0 (although if you increment below 0, it stays at 0).
//v NumericTextCtrl doesn't implement upper ranges, i.e.,
// if I tell it "024 h 060 m 060 s", then
// user increments the hours past 23, it rolls over to 0
// (although if you increment below 0, it stays at 0).
// So instead, set the max to 99 and just catch hours > 24 and fix the ctrls.
double dTime = m_pTimeTextCtrl_End->GetTimeValue();
double dTime = m_pTimeTextCtrl_End->GetValue();
long days = (long)(dTime / (24.0 * 3600.0));
if (days > 0) {
dTime -= (double)days * 24.0 * 3600.0;
m_DateTime_End += wxTimeSpan::Days(days);
m_pDatePickerCtrl_End->SetValue(m_DateTime_End);
m_pTimeTextCtrl_End->SetTimeValue(dTime);
m_pTimeTextCtrl_End->SetValue(dTime);
}
wxDateEvent dummyDateEvent;
@ -191,7 +197,7 @@ void TimerRecordDialog::OnTimeText_End(wxCommandEvent& WXUNUSED(event))
void TimerRecordDialog::OnTimeText_Duration(wxCommandEvent& WXUNUSED(event))
{
double dTime = m_pTimeTextCtrl_Duration->GetTimeValue();
double dTime = m_pTimeTextCtrl_Duration->GetValue();
long hr = (long)(dTime / 3600.0);
long min = (long)((dTime - (hr * 3600.0)) / 60.0);
long sec = (long)(dTime - (hr * 3600.0) - (min * 60.0));
@ -342,10 +348,12 @@ void TimerRecordDialog::PopulateOrExchange(ShuttleGui& S)
m_pDatePickerCtrl_Start->SetRange(wxDateTime::Today(), wxInvalidDateTime); // No backdating.
S.AddWindow(m_pDatePickerCtrl_Start);
m_pTimeTextCtrl_Start = new TimeTextCtrl(this, ID_TIMETEXT_START);
m_pTimeTextCtrl_Start = new NumericTextCtrl(
NumericConverter::TIME, this, ID_TIMETEXT_START);
m_pTimeTextCtrl_Start->SetName(_("Start Time"));
m_pTimeTextCtrl_Start->SetFormatString(strFormat);
m_pTimeTextCtrl_Start->SetTimeValue(wxDateTime_to_AudacityTime(m_DateTime_Start));
m_pTimeTextCtrl_Start->
SetValue(wxDateTime_to_AudacityTime(m_DateTime_Start));
S.AddWindow(m_pTimeTextCtrl_Start);
m_pTimeTextCtrl_Start->EnableMenu(false);
}
@ -362,10 +370,11 @@ void TimerRecordDialog::PopulateOrExchange(ShuttleGui& S)
m_pDatePickerCtrl_End->SetName(_("End Date"));
S.AddWindow(m_pDatePickerCtrl_End);
m_pTimeTextCtrl_End = new TimeTextCtrl(this, ID_TIMETEXT_END);
m_pTimeTextCtrl_End = new NumericTextCtrl(
NumericConverter::TIME, this, ID_TIMETEXT_END);
m_pTimeTextCtrl_End->SetName(_("End Time"));
m_pTimeTextCtrl_End->SetFormatString(strFormat);
m_pTimeTextCtrl_End->SetTimeValue(wxDateTime_to_AudacityTime(m_DateTime_End));
m_pTimeTextCtrl_End->SetValue(wxDateTime_to_AudacityTime(m_DateTime_End));
S.AddWindow(m_pTimeTextCtrl_End);
m_pTimeTextCtrl_End->EnableMenu(false);
}
@ -382,10 +391,12 @@ void TimerRecordDialog::PopulateOrExchange(ShuttleGui& S)
* seconds.
*/
wxString strFormat1 = _("099 days 024 h 060 m 060 s");
m_pTimeTextCtrl_Duration = new TimeTextCtrl(this, ID_TIMETEXT_DURATION);
m_pTimeTextCtrl_Duration = new NumericTextCtrl(
NumericConverter::TIME, this, ID_TIMETEXT_DURATION);
m_pTimeTextCtrl_Duration->SetName(_("Duration"));
m_pTimeTextCtrl_Duration->SetFormatString(strFormat1);
m_pTimeTextCtrl_Duration->SetTimeValue(m_TimeSpan_Duration.GetSeconds().ToDouble());
m_pTimeTextCtrl_Duration->
SetValue(m_TimeSpan_Duration.GetSeconds().ToDouble());
S.AddWindow(m_pTimeTextCtrl_Duration);
m_pTimeTextCtrl_Duration->EnableMenu(false);
}
@ -409,7 +420,7 @@ bool TimerRecordDialog::TransferDataFromWindow()
long sec;
m_DateTime_Start = m_pDatePickerCtrl_Start->GetValue();
dTime = m_pTimeTextCtrl_Start->GetTimeValue();
dTime = m_pTimeTextCtrl_Start->GetValue();
hr = (long)(dTime / 3600.0);
min = (long)((dTime - (hr * 3600.0)) / 60.0);
sec = (long)(dTime - (hr * 3600.0) - (min * 60.0));
@ -418,7 +429,7 @@ bool TimerRecordDialog::TransferDataFromWindow()
m_DateTime_Start.SetSecond(sec);
m_DateTime_End = m_pDatePickerCtrl_End->GetValue();
dTime = m_pTimeTextCtrl_End->GetTimeValue();
dTime = m_pTimeTextCtrl_End->GetValue();
hr = (long)(dTime / 3600.0);
min = (long)((dTime - (hr * 3600.0)) / 60.0);
sec = (long)(dTime - (hr * 3600.0) - (min * 60.0));
@ -435,7 +446,7 @@ bool TimerRecordDialog::TransferDataFromWindow()
void TimerRecordDialog::UpdateDuration()
{
m_TimeSpan_Duration = m_DateTime_End - m_DateTime_Start;
m_pTimeTextCtrl_Duration->SetTimeValue(m_TimeSpan_Duration.GetSeconds().ToDouble());
m_pTimeTextCtrl_Duration->SetValue(m_TimeSpan_Duration.GetSeconds().ToDouble());
}
// Update m_DateTime_End and ctrls based on m_DateTime_Start and m_TimeSpan_Duration.
@ -446,7 +457,7 @@ void TimerRecordDialog::UpdateEnd()
m_pDatePickerCtrl_End->SetValue(m_DateTime_End);
m_pDatePickerCtrl_End->SetRange(m_DateTime_Start, wxInvalidDateTime); // No backdating.
m_pDatePickerCtrl_End->Refresh();
m_pTimeTextCtrl_End->SetTimeValue(wxDateTime_to_AudacityTime(m_DateTime_End));
m_pTimeTextCtrl_End->SetValue(wxDateTime_to_AudacityTime(m_DateTime_End));
}
int TimerRecordDialog::WaitForStart()

View File

@ -20,10 +20,10 @@
#include <wx/datectrl.h>
#include <wx/calctrl.h>
#include "widgets/TimeTextCtrl.h"
#include "ShuttleGui.h"
class NumericTextCtrl;
class TimerRecordDialog : public wxDialog
{
public:
@ -59,12 +59,12 @@ private:
// controls
wxDatePickerCtrl* m_pDatePickerCtrl_Start;
TimeTextCtrl* m_pTimeTextCtrl_Start;
NumericTextCtrl* m_pTimeTextCtrl_Start;
wxDatePickerCtrl* m_pDatePickerCtrl_End;
TimeTextCtrl* m_pTimeTextCtrl_End;
NumericTextCtrl* m_pTimeTextCtrl_End;
TimeTextCtrl* m_pTimeTextCtrl_Duration;
NumericTextCtrl* m_pTimeTextCtrl_Duration;
wxTimer m_timer;

View File

@ -220,7 +220,7 @@ is time to refresh some aspect of the screen.
#include "widgets/ASlider.h"
#include "widgets/Ruler.h"
#include "widgets/TimeTextCtrl.h"
#include "widgets/NumericTextCtrl.h"
#include <wx/arrimpl.cpp>
@ -462,7 +462,7 @@ TrackPanel::TrackPanel(wxWindow * parent, wxWindowID id,
mTrackArtist(NULL),
mBacking(NULL),
mRefreshBacking(false),
mConverter(),
mConverter(NumericConverter::TIME),
mAutoScrolling(false),
mVertScrollRemainder(0),
vrulerSize(36,0)
@ -7527,23 +7527,23 @@ void TrackPanel::OnCursorRight( bool shift, bool ctrl, bool keyup )
// negative to move backward.
double TrackPanel::GridMove(double t, int minPix)
{
TimeTextCtrl ttc(this, wxID_ANY, wxT(""), 0.0, GetProject()->GetRate());
NumericTextCtrl ttc(NumericConverter::TIME, this, wxID_ANY, wxT(""), 0.0, GetProject()->GetRate());
ttc.SetFormatName(GetProject()->GetSelectionFormat());
ttc.SetTimeValue(t);
ttc.SetValue(t);
// Try incrementing/decrementing the value; if we've moved far enough we're
// done
double result;
minPix >= 0 ? ttc.Increment() : ttc.Decrement();
result = ttc.GetTimeValue();
result = ttc.GetValue();
if (fabs(result - t) * mViewInfo->zoom >= fabs((double)minPix)) {
return result;
}
// Otherwise, move minPix pixels, then snap to the time.
result = t + minPix / mViewInfo->zoom;
ttc.SetTimeValue(result);
result = ttc.GetTimeValue();
ttc.SetValue(result);
result = ttc.GetValue();
return result;
}

View File

@ -24,7 +24,7 @@
#include "WaveClip.h"
#include "WaveTrack.h"
#include "UndoManager.h" //JKC: Included for PUSH_XXX definitions.
#include "widgets/TimeTextCtrl.h"
#include "widgets/NumericTextCtrl.h"
class wxMenu;
class wxRect;
@ -635,7 +635,7 @@ protected:
wxInt64 mSnapRight;
bool mSnapPreferRightEdge;
TimeConverter mConverter;
NumericConverter mConverter;
Track * mDrawingTrack; // Keeps track of which track you are drawing on between events cf. HandleDraw()
int mDrawingTrackTop; // Keeps track of the top position of the drawing track.

View File

@ -22,6 +22,7 @@
#include "../FileNames.h"
#include "../widgets/LinkingHtmlWindow.h"
#include "../widgets/HelpSystem.h"
#include "../widgets/NumericTextCtrl.h"
#include "FileDialog.h"
#include <math.h>
@ -72,13 +73,13 @@ void InitContrastDialog(wxWindow * parent)
// Zero dialog boxes. Do we need to do this here?
if( !gContrastDialog->bFGset )
{
gContrastDialog->mForegroundStartT->SetTimeValue(0.0);
gContrastDialog->mForegroundEndT->SetTimeValue(0.0);
gContrastDialog->mForegroundStartT->SetValue(0.0);
gContrastDialog->mForegroundEndT->SetValue(0.0);
}
if( !gContrastDialog->bBGset )
{
gContrastDialog->mBackgroundStartT->SetTimeValue(0.0);
gContrastDialog->mBackgroundEndT->SetTimeValue(0.0);
gContrastDialog->mBackgroundStartT->SetValue(0.0);
gContrastDialog->mBackgroundEndT->SetValue(0.0);
}
gContrastDialog->CentreOnParent();
@ -259,7 +260,7 @@ ContrastDialog::ContrastDialog(wxWindow * parent, wxWindowID id,
if (mForegroundStartT == NULL)
{
mForegroundStartT = new
TimeTextCtrl(this,
NumericTextCtrl(NumericConverter::TIME, this,
ID_FOREGROUNDSTART_T,
_("hh:mm:ss + hundredths"),
0.0,
@ -275,7 +276,7 @@ ContrastDialog::ContrastDialog(wxWindow * parent, wxWindowID id,
if (mForegroundEndT == NULL)
{
mForegroundEndT = new
TimeTextCtrl(this,
NumericTextCtrl(NumericConverter::TIME, this,
ID_FOREGROUNDEND_T,
_("hh:mm:ss + hundredths"),
0.0,
@ -297,7 +298,7 @@ ContrastDialog::ContrastDialog(wxWindow * parent, wxWindowID id,
if (mBackgroundStartT == NULL)
{
mBackgroundStartT = new
TimeTextCtrl(this,
NumericTextCtrl(NumericConverter::TIME, this,
ID_BACKGROUNDSTART_T,
_("hh:mm:ss + hundredths"),
0.0,
@ -313,7 +314,7 @@ ContrastDialog::ContrastDialog(wxWindow * parent, wxWindowID id,
if (mBackgroundEndT == NULL)
{
mBackgroundEndT = new
TimeTextCtrl(this,
NumericTextCtrl(NumericConverter::TIME, this,
ID_BACKGROUNDEND_T,
_("hh:mm:ss + hundredths"),
0.0,
@ -375,8 +376,8 @@ ContrastDialog::~ContrastDialog()
void ContrastDialog::OnGetForegroundDB( wxCommandEvent & WXUNUSED(event))
{
SetStartTime(mForegroundStartT->GetTimeValue());
SetEndTime(mForegroundEndT->GetTimeValue());
SetStartTime(mForegroundStartT->GetValue());
SetEndTime(mForegroundEndT->GetValue());
foregrounddB = GetDB();
m_pButton_UseCurrentF->SetFocus();
results();
@ -384,8 +385,8 @@ void ContrastDialog::OnGetForegroundDB( wxCommandEvent & WXUNUSED(event))
void ContrastDialog::OnGetBackgroundDB( wxCommandEvent & WXUNUSED(event))
{
SetStartTime(mBackgroundStartT->GetTimeValue());
SetEndTime(mBackgroundEndT->GetTimeValue());
SetStartTime(mBackgroundStartT->GetValue());
SetEndTime(mBackgroundEndT->GetValue());
backgrounddB = GetDB();
m_pButton_UseCurrentB->SetFocus();
results();
@ -410,8 +411,8 @@ void ContrastDialog::OnUseSelectionF(wxCommandEvent & event)
Track *t = iter.First();
while (t) {
if (t->GetSelected() && t->GetKind() == Track::Wave) {
mForegroundStartT->SetTimeValue(p->mViewInfo.selectedRegion.t0());
mForegroundEndT->SetTimeValue(p->mViewInfo.selectedRegion.t1());
mForegroundStartT->SetValue(p->mViewInfo.selectedRegion.t0());
mForegroundEndT->SetValue(p->mViewInfo.selectedRegion.t1());
break;
}
t = iter.Next();
@ -427,8 +428,8 @@ void ContrastDialog::OnUseSelectionB(wxCommandEvent & event)
Track *t = iter.First();
while (t) {
if (t->GetSelected() && t->GetKind() == Track::Wave) {
mBackgroundStartT->SetTimeValue(p->mViewInfo.selectedRegion.t0());
mBackgroundEndT->SetTimeValue(p->mViewInfo.selectedRegion.t1());
mBackgroundStartT->SetValue(p->mViewInfo.selectedRegion.t0());
mBackgroundEndT->SetValue(p->mViewInfo.selectedRegion.t1());
break;
}
t = iter.Next();
@ -521,12 +522,12 @@ void ContrastDialog::OnExport(wxCommandEvent & WXUNUSED(event))
f.AddLine(wxString::Format(_("Filename = %s."), project->GetFileName().c_str() ));
f.AddLine(wxT(""));
f.AddLine(_("Foreground"));
float t = (float)mForegroundStartT->GetTimeValue();
float t = (float)mForegroundStartT->GetValue();
int h = (int)(t/3600); // there must be a standard function for this!
int m = (int)((t - h*3600)/60);
float s = t - h*3600.0 - m*60.0;
f.AddLine(wxString::Format(_("Time started = %2d hour(s), %2d minute(s), %.2f seconds."), h, m, s ));
t = (float)mForegroundEndT->GetTimeValue();
t = (float)mForegroundEndT->GetValue();
h = (int)(t/3600);
m = (int)((t - h*3600)/60);
s = t - h*3600.0 - m*60.0;
@ -540,12 +541,12 @@ void ContrastDialog::OnExport(wxCommandEvent & WXUNUSED(event))
f.AddLine(wxString::Format(_("Average RMS = dB.")));
f.AddLine(wxT(""));
f.AddLine(_("Background"));
t = (float)mBackgroundStartT->GetTimeValue();
t = (float)mBackgroundStartT->GetValue();
h = (int)(t/3600);
m = (int)((t - h*3600)/60);
s = t - h*3600.0 - m*60.0;
f.AddLine(wxString::Format(_("Time started = %2d hour(s), %2d minute(s), %.2f seconds."), h, m, s ));
t = (float)mBackgroundEndT->GetTimeValue();
t = (float)mBackgroundEndT->GetValue();
h = (int)(t/3600);
m = (int)((t - h*3600)/60);
s = t - h*3600.0 - m*60.0;
@ -603,10 +604,10 @@ void ContrastDialog::OnReset(wxCommandEvent & event)
bFGset = false;
bBGset = false;
mForegroundStartT->SetTimeValue(0.0);
mForegroundEndT->SetTimeValue(0.0);
mBackgroundStartT->SetTimeValue(0.0);
mBackgroundEndT->SetTimeValue(0.0);
mForegroundStartT->SetValue(0.0);
mForegroundEndT->SetValue(0.0);
mBackgroundStartT->SetValue(0.0);
mBackgroundEndT->SetValue(0.0);
wxCommandEvent dummyEvt;
OnGetForegroundDB(event);

View File

@ -9,8 +9,6 @@
#ifndef __AUDACITY_CONTRAST_DIALOG__
#define __AUDACITY_CONTRAST_DIALOG__
#include "../widgets/TimeTextCtrl.h"
#include <wx/dialog.h>
#include <wx/slider.h>
@ -19,6 +17,7 @@ class wxSizer;
class wxString;
class Envelope;
class NumericTextCtrl;
class WaveTrack;
void InitContrastDialog(wxWindow * parent);
@ -48,10 +47,10 @@ public:
wxButton * m_pButton_Reset;
wxButton * m_pButton_Close;
TimeTextCtrl *mForegroundStartT;
TimeTextCtrl *mForegroundEndT;
TimeTextCtrl *mBackgroundStartT;
TimeTextCtrl *mBackgroundEndT;
NumericTextCtrl *mForegroundStartT;
NumericTextCtrl *mForegroundEndT;
NumericTextCtrl *mBackgroundStartT;
NumericTextCtrl *mBackgroundEndT;
bool bFGset;
bool bBGset;

View File

@ -27,6 +27,7 @@
#include "../Prefs.h"
#include "../ShuttleGui.h"
#include "../WaveTrack.h"
#include "../widgets/NumericTextCtrl.h"
#include <wx/slider.h>
#include <wx/button.h>
@ -456,7 +457,7 @@ void DtmfDialog::PopulateOrExchange( ShuttleGui & S )
if (mDtmfDurationT == NULL)
{
mDtmfDurationT = new
TimeTextCtrl(this,
NumericTextCtrl(NumericConverter::TIME, this,
ID_DTMF_DURATION_TEXT,
/* use this instead of "seconds" because if a selection is passed to the
* effect, I want it (dDuration) to be used as the duration, and with
@ -496,7 +497,7 @@ void DtmfDialog::PopulateOrExchange( ShuttleGui & S )
bool DtmfDialog::TransferDataToWindow()
{
mDtmfDutyS->SetValue((int)dDutyCycle);
mDtmfDurationT->SetTimeValue(dDuration);
mDtmfDurationT->SetValue(dDuration);
mDtmfStringT->SetValue(dString);
return true;
@ -523,7 +524,7 @@ void DtmfDialog::Recalculate(void) {
double slot;
dString = mDtmfStringT->GetValue();
dDuration = mDtmfDurationT->GetTimeValue();
dDuration = mDtmfDurationT->GetValue();
dNTones = wxStrlen(dString);
dDutyCycle = TrapLong(mDtmfDutyS->GetValue(), DUTY_MIN, DUTY_MAX);

View File

@ -23,10 +23,11 @@
#include "../ShuttleGui.h"
#include "../WaveTrack.h"
#include "../widgets/TimeTextCtrl.h"
#include "Generator.h"
class NumericTextCtrl;
#define __UNINITIALIZED__ (-1)
class EffectDtmf : public Generator {
@ -112,7 +113,7 @@ class DtmfDialog:public EffectDialog {
EffectDtmf *mEffect;
wxSlider *mDtmfDutyS;
wxTextCtrl *mDtmfStringT;
TimeTextCtrl *mDtmfDurationT;
NumericTextCtrl *mDtmfDurationT;
wxStaticText *mDtmfToneT;
wxStaticText *mDtmfSilenceT;
wxStaticText *mDtmfDutyT;

View File

@ -19,6 +19,7 @@
#include "../Prefs.h"
#include "../ShuttleGui.h"
#include "../WaveTrack.h"
#include "../widgets/NumericTextCtrl.h"
#include <math.h>
@ -197,7 +198,7 @@ void NoiseDialog::PopulateOrExchange( ShuttleGui & S )
if (mNoiseDurationT == NULL)
{
mNoiseDurationT = new
TimeTextCtrl(this,
NumericTextCtrl(NumericConverter::TIME, this,
wxID_ANY,
wxT(""),
nDuration,
@ -223,7 +224,7 @@ bool NoiseDialog::TransferDataToWindow()
EffectDialog::TransferDataToWindow();
// Must handle this ourselves since ShuttleGui doesn't know about it
mNoiseDurationT->SetTimeValue(nDuration);
mNoiseDurationT->SetValue(nDuration);
return true;
}
@ -235,7 +236,7 @@ bool NoiseDialog::TransferDataFromWindow()
nAmplitude = TrapDouble(nAmplitude, AMP_MIN, AMP_MAX);
// Must handle this ourselves since ShuttleGui doesn't know about it
nDuration = mNoiseDurationT->GetTimeValue();
nDuration = mNoiseDurationT->GetValue();
return true;
}

View File

@ -17,11 +17,11 @@
#include <wx/intl.h>
#include "Generator.h"
#include "../widgets/TimeTextCtrl.h"
class wxString;
class wxChoice;
class wxTextCtrl;
class NumericTextCtrl;
class ShuttleGui;
#define __UNINITIALIZED__ (-1)
@ -114,7 +114,7 @@ class NoiseDialog:public EffectDialog {
private:
EffectNoise *mEffect;
TimeTextCtrl *mNoiseDurationT;
NumericTextCtrl *mNoiseDurationT;
};
#endif

View File

@ -26,7 +26,7 @@
#include "../ShuttleGui.h"
#include "../WaveTrack.h"
#include "../LabelTrack.h"
#include "../widgets/TimeTextCtrl.h"
#include "../widgets/NumericTextCtrl.h"
#include "../Project.h"
#include <wx/button.h>
@ -261,7 +261,7 @@ void RepeatDialog::DisplayNewTime()
wxString str;
str = _("New selection length: ");
TimeTextCtrl tt(this,
NumericTextCtrl tt(NumericTextCtrl::TIME, this,
wxID_ANY,
wxT(""),
selectionTimeSecs * (repeatCount + 1),
@ -270,7 +270,7 @@ void RepeatDialog::DisplayNewTime()
wxDefaultSize,
true);
tt.SetFormatString(tt.GetBuiltinFormat(_("hh:mm:ss")));
str += tt.GetTimeString();
str += tt.GetString();
mTotalTime->SetLabel(str);
mTotalTime->SetName(str); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)

View File

@ -18,7 +18,6 @@
#include <wx/intl.h>
#include "Generator.h"
#include "../widgets/TimeTextCtrl.h"
class wxSizer;
class wxTextCtrl;

View File

@ -30,6 +30,7 @@ frequency changes smoothly during the tone.
#include "../ShuttleGui.h"
#include "../WaveTrack.h"
#include "../Prefs.h"
#include "../widgets/NumericTextCtrl.h"
#include <wx/choice.h>
#include <wx/intl.h>
@ -272,8 +273,8 @@ void ToneGenDialog::PopulateOrExchangeStandard( ShuttleGui & S )
S.AddPrompt(_("Duration") + wxString(wxT(":")));
if (mToneDurationT == NULL)
{
mToneDurationT =
new TimeTextCtrl(this,
mToneDurationT = new
NumericTextCtrl(NumericConverter::TIME, this,
wxID_ANY,
isSelection ? _("hh:mm:ss + samples") : _("hh:mm:ss + milliseconds"),
mDuration,
@ -320,7 +321,7 @@ void ToneGenDialog::PopulateOrExchangeExtended( ShuttleGui & S )
if (mToneDurationT == NULL)
{
mToneDurationT = new
TimeTextCtrl(this,
NumericTextCtrl(NumericConverter::TIME, this,
wxID_ANY,
isSelection ? _("hh:mm:ss + samples") : _("hh:mm:ss + milliseconds"),
mDuration,
@ -349,7 +350,7 @@ bool ToneGenDialog::TransferDataToWindow()
EffectDialog::TransferDataToWindow();
// Must handle this ourselves since ShuttleGui doesn't know about it
mToneDurationT->SetTimeValue(mDuration);
mToneDurationT->SetValue(mDuration);
return true;
}
@ -364,7 +365,7 @@ bool ToneGenDialog::TransferDataFromWindow()
frequency[1] = TrapDouble(frequency[1], FREQ_MIN, (float)(GetActiveProject()->GetRate())/2.);
// Must handle this ourselves since ShuttleGui doesn't know about it
mDuration = mToneDurationT->GetTimeValue();
mDuration = mToneDurationT->GetValue();
return true;
}

View File

@ -14,7 +14,6 @@
#define __AUDACITY_EFFECT_TONEGEN__
#include "Generator.h"
#include "../widgets/TimeTextCtrl.h"
#include "../Experimental.h"
#include <wx/dialog.h>
@ -22,6 +21,7 @@
class wxString;
class wxChoice;
class wxTextCtrl;
class NumericTextCtrl;
class ShuttleGui;
#define __UNINITIALIZED__ (-1)
@ -126,7 +126,7 @@ class ToneGenDialog:public EffectDialog {
wxArrayString *interpolations;
private:
TimeTextCtrl *mToneDurationT;
NumericTextCtrl *mToneDurationT;
};
#endif

View File

@ -51,7 +51,7 @@ with changes in the SelectionBar.
#include "../AColor.h"
#include "../Prefs.h"
#include "../Snap.h"
#include "../widgets/TimeTextCtrl.h"
#include "../widgets/NumericTextCtrl.h"
IMPLEMENT_CLASS(SelectionBar, ToolBar);
@ -89,10 +89,14 @@ SelectionBar::SelectionBar()
mListener(NULL), mRate(0.0), mStart(0.0), mEnd(0.0), mAudio(0.0),
mLeftTime(NULL), mRightTime(NULL), mAudioTime(NULL)
{
// Make sure we have a valid rate as the TimeTextCtrl()s created in Populate()
// depend on it. Otherwise, division-by-zero floating point exceptions will occur.
// Refer to bug #462 for a scenario where the division-by-zero causes Audacity to fail.
mRate = (double) gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleRate"), AudioIO::GetOptimalSupportedSampleRate());
// Make sure we have a valid rate as the NumericTextCtrl()s
// created in Populate()
// depend on it. Otherwise, division-by-zero floating point exceptions
// will occur.
// Refer to bug #462 for a scenario where the division-by-zero causes
// Audacity to fail.
mRate = (double) gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleRate"),
AudioIO::GetOptimalSupportedSampleRate());
}
SelectionBar::~SelectionBar()
@ -247,12 +251,14 @@ void SelectionBar::Populate()
NULL,
this);
mLeftTime = new TimeTextCtrl(this, OnLeftTimeID, formatName, 0.0, mRate);
mLeftTime = new NumericTextCtrl(
NumericConverter::TIME, this, OnLeftTimeID, formatName, 0.0, mRate);
mLeftTime->SetName(_("Selection Start:"));
mLeftTime->EnableMenu();
mainSizer->Add(mLeftTime, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5);
mRightTime = new TimeTextCtrl(this, OnRightTimeID, formatName, 0.0, mRate);
mRightTime = new NumericTextCtrl(
NumericConverter::TIME, this, OnRightTimeID, formatName, 0.0, mRate);
mRightTime->SetName(wxString(_("Selection ")) + (showSelectionLength ?
_("Length") :
_("End")));
@ -264,7 +270,8 @@ void SelectionBar::Populate()
wxLI_VERTICAL),
0, wxRIGHT, 5);
mAudioTime = new TimeTextCtrl(this, wxID_ANY, formatName, 0.0, mRate);
mAudioTime = new NumericTextCtrl(
NumericConverter::TIME, this, wxID_ANY, formatName, 0.0, mRate);
mAudioTime->SetName(_("Audio Position:"));
mAudioTime->EnableMenu();
mainSizer->Add(mAudioTime, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 0);
@ -308,8 +315,8 @@ void SelectionBar::OnSize(wxSizeEvent &evt)
void SelectionBar::ModifySelection(bool done)
{
mStart = mLeftTime->GetTimeValue();
double right = mRightTime->GetTimeValue();
mStart = mLeftTime->GetValue();
double right = mRightTime->GetValue();
if (mRightEndButton->GetValue()) {
if(mStart > right)
@ -406,10 +413,10 @@ void SelectionBar::OnUpdate(wxCommandEvent &evt)
void SelectionBar::ValuesToControls()
{
mLeftTime->SetTimeValue(mStart);
mLeftTime->SetValue(mStart);
if (mRightEndButton->GetValue())
mRightTime->SetTimeValue(mEnd);
mRightTime->SetValue(mEnd);
else
{ // mRightTime is the length.
// Be sure to take into account the sub-sample offset.
@ -417,10 +424,10 @@ void SelectionBar::ValuesToControls()
double t = (sampleCount)floor(mEnd * mRate + 0.5);
t -= (sampleCount)floor(mStart * mRate + 0.5);
t /= mRate;
mRightTime->SetTimeValue(t);
mRightTime->SetValue(t);
}
mAudioTime->SetTimeValue(mAudio);
mAudioTime->SetValue(mAudio);
}
void SelectionBar::SetTimes(double start, double end, double audio)
@ -434,20 +441,21 @@ void SelectionBar::SetTimes(double start, double end, double audio)
double SelectionBar::GetLeftTime()
{
return mLeftTime->GetTimeValue();
return mLeftTime->GetValue();
}
double SelectionBar::GetRightTime()
{
if (mRightEndButton->GetValue())
return mRightTime->GetTimeValue();
return mRightTime->GetValue();
else {
// What would be shown if we were showing the end time
TimeTextCtrl ttc(this, wxID_ANY, wxT(""), 0.0, mRate);
NumericTextCtrl ttc(
NumericConverter::TIME, this, wxID_ANY, wxT(""), 0.0, mRate);
ttc.SetFormatString(mRightTime->GetFormatString());
ttc.SetSampleRate(mRate);
ttc.SetTimeValue(mEnd);
return ttc.GetTimeValue();
ttc.SetValue(mEnd);
return ttc.GetValue();
}
}

View File

@ -25,7 +25,7 @@ class wxRadioButton;
class wxSizeEvent;
class SelectionBarListener;
class TimeTextCtrl;
class NumericTextCtrl;
class SelectionBar:public ToolBar {
@ -78,11 +78,11 @@ class SelectionBar:public ToolBar {
double mStart, mEnd, mAudio;
wxString mField[10];
TimeTextCtrl *mLeftTime;
TimeTextCtrl *mRightTime;
NumericTextCtrl *mLeftTime;
NumericTextCtrl *mRightTime;
wxRadioButton *mRightEndButton;
wxRadioButton *mRightLengthButton;
TimeTextCtrl *mAudioTime;
NumericTextCtrl *mAudioTime;
wxComboBox *mRateBox;
wxChoice *mSnapTo;

View File

@ -0,0 +1,308 @@
/**********************************************************************
Audacity: A Digital Audio Editor
SpectralSelectionBar.cpp
Copyright 2014 Dominic Mazzoni
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
*******************************************************************//**
\class SpectralSelectionBar
\brief (not quite a Toolbar) at foot of screen for setting and viewing the
frequency selection range.
*//****************************************************************//**
\class SpectralSelectionBarListener
\brief A class used to forward events to do
with changes in the SpectralSelectionBar.
*//*******************************************************************/
#include "../Audacity.h"
#include <algorithm>
// For compilers that support precompilation, includes "wx/wx.h".
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/button.h>
#include <wx/checkbox.h>
#include <wx/combobox.h>
#include <wx/intl.h>
#include <wx/radiobut.h>
#include <wx/settings.h>
#include <wx/sizer.h>
#include <wx/valtext.h>
#endif
#include <wx/statline.h>
#include "SpectralSelectionBarListener.h"
#include "SpectralSelectionBar.h"
#include "../AudacityApp.h"
#include "../SelectedRegion.h"
#include "../widgets/NumericTextCtrl.h"
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
IMPLEMENT_CLASS(SpectralSelectionBar, ToolBar);
enum {
SpectralSelectionBarFirstID = 2750,
OnCenterID,
OnWidthID
};
BEGIN_EVENT_TABLE(SpectralSelectionBar, ToolBar)
EVT_SIZE(SpectralSelectionBar::OnSize)
EVT_TEXT(OnCenterID, SpectralSelectionBar::OnCenter)
EVT_TEXT(OnWidthID, SpectralSelectionBar::OnWidth)
EVT_COMMAND(wxID_ANY, EVT_FREQUENCYTEXTCTRL_UPDATED, SpectralSelectionBar::OnUpdate)
EVT_COMMAND(wxID_ANY, EVT_LOGFREQUENCYTEXTCTRL_UPDATED, SpectralSelectionBar::OnUpdate)
END_EVENT_TABLE()
SpectralSelectionBar::SpectralSelectionBar()
: ToolBar(SpectralSelectionBarID, _("SpectralSelection"), wxT("SpectralSelection")),
mListener(NULL), mCenter(0.0), mWidth(0.0),
mCenterCtrl(NULL), mWidthCtrl(NULL)
{
}
SpectralSelectionBar::~SpectralSelectionBar()
{
}
void SpectralSelectionBar::Create(wxWindow * parent)
{
ToolBar::Create(parent);
}
void SpectralSelectionBar::Populate()
{
// This will be inherited by all children:
SetFont(wxFont(9, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
wxFlexGridSizer *mainSizer;
wxBoxSizer *hSizer;
/* we don't actually need a control yet, but we want to use its methods
* to do some look-ups, so we'll have to create one. We can't make the
* look-ups static because they depend on translations which are done at
* runtime */
wxString frequencyFormatName = mListener
? mListener->SSBL_GetFrequencySelectionFormatName()
: wxString(wxEmptyString);
wxString logFrequencyFormatName = mListener
? mListener->SSBL_GetLogFrequencySelectionFormatName()
: wxString(wxEmptyString);
mainSizer = new wxFlexGridSizer(2, 1, 1);
Add(mainSizer, 0, wxALIGN_CENTER_VERTICAL);
//
// Top row (labels)
//
mainSizer->Add(new wxStaticText(this, -1, _("Center:"),
wxDefaultPosition, wxDefaultSize),
0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5);
mainSizer->Add(new wxStaticText(this, -1, _("Bandwidth:")),
0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 0);
//
// Bottom row (controls)
//
mCenterCtrl = new NumericTextCtrl(
NumericConverter::FREQUENCY, this, OnCenterID, frequencyFormatName, 0.0);
mCenterCtrl->SetName(_("Center Frequency:"));
mCenterCtrl->EnableMenu();
mainSizer->Add(mCenterCtrl, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5);
mWidthCtrl = new NumericTextCtrl(
NumericConverter::LOG_FREQUENCY, this, OnWidthID, logFrequencyFormatName, 0.0);
mWidthCtrl->SetName(wxString(_("Bandwidth:")));
mWidthCtrl->EnableMenu();
mainSizer->Add(mWidthCtrl, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 0);
mainSizer->Layout();
Layout();
SetMinSize(GetSizer()->GetMinSize());
}
void SpectralSelectionBar::UpdatePrefs()
{
{
wxCommandEvent e(EVT_FREQUENCYTEXTCTRL_UPDATED);
e.SetInt(mCenterCtrl->GetFormatIndex());
OnUpdate(e);
}
{
wxCommandEvent e(EVT_LOGFREQUENCYTEXTCTRL_UPDATED);
e.SetInt(mWidthCtrl->GetFormatIndex());
OnUpdate(e);
}
// Set label to pull in language change
SetLabel(_("SpectralSelection"));
// Give base class a chance
ToolBar::UpdatePrefs();
}
void SpectralSelectionBar::SetListener(SpectralSelectionBarListener *l)
{
mListener = l;
SetFrequencySelectionFormatName(mListener->SSBL_GetFrequencySelectionFormatName());
SetLogFrequencySelectionFormatName(mListener->SSBL_GetLogFrequencySelectionFormatName());
};
void SpectralSelectionBar::OnSize(wxSizeEvent &evt)
{
Refresh(true);
evt.Skip();
}
void SpectralSelectionBar::ModifySpectralSelection(bool done)
{
const double nyq = mListener->SSBL_GetRate() / 2.0;
mCenter = mCenterCtrl->GetValue();
mWidth = mWidthCtrl->GetValue();
double bottom, top;
if (mCenter < 0 && mWidth < 0)
bottom = top = SelectedRegion::UndefinedFrequency;
else {
if (mCenter < 0) {
mWidth = log(std::min(nyq, exp(mWidth)));
// Choose arbitrary center for the width
mCenter = sqrt(nyq);
}
else if (mWidth < 0) {
mCenter = std::max(1.0, std::min(nyq, mCenter));
// Choose arbitrary width for the center
const double ratio = std::min(mCenter, nyq / mCenter);
mWidth = log(ratio * ratio);
}
else {
mCenter = std::max(1.0, std::min(nyq, mCenter));
double ratio = std::min(mCenter, nyq / mCenter);
mWidth = std::min(2 * log(ratio), mWidth);
}
const double ratio = exp(mWidth / 2);
bottom = mCenter / ratio, top = mCenter * ratio;
}
// Notify project and track panel, which may change
// the values again, and call back to us in SetFrequencies()
mListener->SSBL_ModifySpectralSelection(bottom, top, done);
}
void SpectralSelectionBar::OnCenter(wxCommandEvent & event)
{
ModifySpectralSelection(event.GetInt() != 0);
}
void SpectralSelectionBar::OnWidth(wxCommandEvent & event)
{
ModifySpectralSelection(event.GetInt() != 0);
}
void SpectralSelectionBar::OnUpdate(wxCommandEvent &evt)
{
int index = evt.GetInt();
wxWindow *w = FindFocus();
bool centerFocus = (w == mCenterCtrl);
bool widthFocus = (w == mWidthCtrl);
evt.Skip(false);
// Save formats before recreating the controls so they resize properly
wxEventType type = evt.GetEventType();
int frequencyFormatIndex = mCenterCtrl->GetFormatIndex();
int widthFormatIndex = mWidthCtrl->GetFormatIndex();
if (type == EVT_FREQUENCYTEXTCTRL_UPDATED) {
frequencyFormatIndex = index;
mListener->SSBL_SetFrequencySelectionFormatName
(mCenterCtrl->GetBuiltinName(index));
}
else if (type == EVT_LOGFREQUENCYTEXTCTRL_UPDATED) {
widthFormatIndex = index;
mListener->SSBL_SetLogFrequencySelectionFormatName
(mWidthCtrl->GetBuiltinName(index));
}
// ToolBar::ReCreateButtons() will get rid of our sizers and controls
// so reset pointers first.
mCenterCtrl = mWidthCtrl = NULL;
ToolBar::ReCreateButtons();
ValuesToControls();
mCenterCtrl->SetFormatName
(mCenterCtrl->GetBuiltinName(frequencyFormatIndex));
mWidthCtrl->SetFormatName
(mWidthCtrl->GetBuiltinName(widthFormatIndex));
if (centerFocus) {
mCenterCtrl->SetFocus();
}
else if (widthFocus) {
mWidthCtrl->SetFocus();
}
Updated();
}
void SpectralSelectionBar::ValuesToControls()
{
mCenterCtrl->SetValue(mCenter);
mWidthCtrl->SetValue(mWidth);
}
void SpectralSelectionBar::SetFrequencies(double bottom, double top)
{
if (bottom > 0 && top >= bottom)
mWidth = log(top / bottom), mCenter = sqrt(top * bottom);
else
mWidth = mCenter = -1.0;
ValuesToControls();
}
void SpectralSelectionBar::SetFrequencySelectionFormatName(const wxString & formatName)
{
mCenterCtrl->SetFormatName(formatName);
wxCommandEvent e(EVT_FREQUENCYTEXTCTRL_UPDATED);
e.SetInt(mCenterCtrl->GetFormatIndex());
OnUpdate(e);
}
void SpectralSelectionBar::SetLogFrequencySelectionFormatName(const wxString & formatName)
{
mWidthCtrl->SetFormatName(formatName);
wxCommandEvent e(EVT_LOGFREQUENCYTEXTCTRL_UPDATED);
e.SetInt(mWidthCtrl->GetFormatIndex());
OnUpdate(e);
}
#endif // #ifdef EXPERIMENTAL_SPECTRAL_EDITING

View File

@ -0,0 +1,73 @@
/**********************************************************************
Audacity: A Digital Audio Editor
SpectralSelectionBar.h
Paul Licameli
**********************************************************************/
#ifndef __AUDACITY_SPECTRAL_SELECTION_BAR__
#define __AUDACITY_SPECTRAL_SELECTION_BAR__
#include <wx/defs.h>
#include "ToolBar.h"
class wxBitmap;
class wxCheckBox;
class wxChoice;
class wxComboBox;
class wxCommandEvent;
class wxDC;
class wxRadioButton;
class wxSizeEvent;
class SpectralSelectionBarListener;
class NumericTextCtrl;
class SpectralSelectionBar :public ToolBar {
public:
SpectralSelectionBar();
virtual ~SpectralSelectionBar();
void Create(wxWindow *parent);
virtual void Populate();
virtual void Repaint(wxDC * WXUNUSED(dc)) {};
virtual void EnableDisableButtons() {};
virtual void UpdatePrefs();
void SetFrequencies(double bottom, double top);
void SetFrequencySelectionFormatName(const wxString & formatName);
void SetLogFrequencySelectionFormatName(const wxString & formatName);
void SetListener(SpectralSelectionBarListener *l);
private:
void ValuesToControls();
void OnUpdate(wxCommandEvent &evt);
void OnCenter(wxCommandEvent &evt);
void OnWidth(wxCommandEvent &evt);
void OnSize(wxSizeEvent &evt);
void ModifySpectralSelection(bool done = false);
SpectralSelectionBarListener * mListener;
double mCenter, mWidth;
NumericTextCtrl *mCenterCtrl;
NumericTextCtrl *mWidthCtrl;
public:
DECLARE_CLASS(SpectralSelectionBar);
DECLARE_EVENT_TABLE();
};
#endif

View File

@ -0,0 +1,37 @@
/**********************************************************************
Audacity: A Digital Audio Editor
SpectralSelectionBarListener.h
Paul Licameli
**********************************************************************/
#ifndef __AUDACITY_SPECTRAL_SELECTION_BAR_LISTENER__
#define __AUDACITY_SPECTRAL_SELECTION_BAR_LISTENER__
#include "../Audacity.h"
class wxString;
class SelectedRegion;
class AUDACITY_DLL_API SpectralSelectionBarListener {
public:
SpectralSelectionBarListener(){};
virtual ~SpectralSelectionBarListener(){};
virtual double SSBL_GetRate() const = 0;
virtual const wxString & SSBL_GetFrequencySelectionFormatName() = 0;
virtual void SSBL_SetFrequencySelectionFormatName(const wxString & formatName) = 0;
virtual const wxString & SSBL_GetLogFrequencySelectionFormatName() = 0;
virtual void SSBL_SetLogFrequencySelectionFormatName(const wxString & formatName) = 0;
virtual void SSBL_ModifySpectralSelection(double &bottom, double &top, bool done) = 0;
};
#endif

View File

@ -13,6 +13,8 @@
#ifndef __AUDACITY_TOOLBAR__
#define __AUDACITY_TOOLBAR__
#include "../Experimental.h"
#include <wx/defs.h>
#include <wx/panel.h>
#include <wx/sizer.h>
@ -69,6 +71,9 @@ enum
TranscriptionBarID,
SelectionBarID,
DeviceBarID,
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
SpectralSelectionBarID,
#endif
ToolBarCount
};

View File

@ -54,6 +54,7 @@
#include "MeterToolBar.h"
#include "MixerToolBar.h"
#include "SelectionBar.h"
#include "SpectralSelectionBar.h"
#include "ToolsToolBar.h"
#include "TranscriptionToolBar.h"
@ -412,6 +413,9 @@ ToolManager::ToolManager( AudacityProject *parent )
mBars[ TranscriptionBarID ] = new TranscriptionToolBar();
mBars[ SelectionBarID ] = new SelectionBar();
mBars[ DeviceBarID ] = new DeviceToolBar();
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
mBars[SpectralSelectionBarID] = new SpectralSelectionBar();
#endif
// We own the timer
mTimer.SetOwner( this );
@ -486,7 +490,11 @@ void ToolManager::Reset()
floater = bar->GetParent();
}
if( ndx == SelectionBarID )
if (ndx == SelectionBarID
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
|| ndx == SpectralSelectionBarID
#endif
)
{
dock = mBotDock;
@ -598,7 +606,12 @@ void ToolManager::ReadConfig()
gPrefs->SetPath( bar->GetSection() );
int defaultDock = ndx == SelectionBarID ? BotDockID : TopDockID;
int defaultDock = (ndx == SelectionBarID
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
|| ndx == SpectralSelectionBarID
#endif
)
? BotDockID : TopDockID;
if( ndx == MeterBarID )
defaultDock = 0;
// Read in all the settings

View File

@ -24,7 +24,7 @@
#include <wx/toplevel.h>
#include "Grid.h"
#include "TimeTextCtrl.h"
#include "NumericTextCtrl.h"
TimeEditor::TimeEditor()
{
@ -44,7 +44,7 @@ TimeEditor::~TimeEditor()
void TimeEditor::Create(wxWindow *parent, wxWindowID id, wxEvtHandler *handler)
{
m_control = new TimeTextCtrl(parent,
m_control = new NumericTextCtrl(NumericConverter::TIME, parent,
wxID_ANY,
mFormat,
mOld,
@ -73,7 +73,7 @@ void TimeEditor::BeginEdit(int row, int col, wxGrid *grid)
table->GetValue(row, col).ToDouble(&mOld);
GetTimeCtrl()->SetTimeValue(mOld);
GetTimeCtrl()->SetValue(mOld);
GetTimeCtrl()->EnableMenu();
GetTimeCtrl()->SetFocus();
@ -103,7 +103,7 @@ void TimeEditor::ApplyEdit(int row, int col, wxGrid *grid)
bool TimeEditor::EndEdit(int row, int col, wxGrid *grid)
{
double newtime = GetTimeCtrl()->GetTimeValue();
double newtime = GetTimeCtrl()->GetValue();
bool changed = newtime != mOld;
if (changed) {
@ -117,7 +117,7 @@ bool TimeEditor::EndEdit(int row, int col, wxGrid *grid)
void TimeEditor::Reset()
{
GetTimeCtrl()->SetTimeValue(mOld);
GetTimeCtrl()->SetValue(mOld);
}
bool TimeEditor::IsAcceptedKey(wxKeyEvent &event)
@ -138,7 +138,7 @@ wxGridCellEditor *TimeEditor::Clone() const
wxString TimeEditor::GetValue() const
{
return wxString::Format(wxT("%g"), GetTimeCtrl()->GetTimeValue());
return wxString::Format(wxT("%g"), GetTimeCtrl()->GetValue());
}
wxString TimeEditor::GetFormat()
@ -180,7 +180,7 @@ void TimeRenderer::Draw(wxGrid &grid,
table->GetValue(row, col).ToDouble(&value);
TimeTextCtrl tt(&grid,
NumericTextCtrl tt(NumericConverter::TIME, &grid,
wxID_ANY,
te->GetFormat(),
value,
@ -188,7 +188,7 @@ void TimeRenderer::Draw(wxGrid &grid,
wxPoint(10000, 10000), // create offscreen
wxDefaultSize,
true);
tstr = tt.GetTimeString();
tstr = tt.GetString();
te->DecRef();
}
@ -236,7 +236,7 @@ wxSize TimeRenderer::GetBestSize(wxGrid &grid,
if (te) {
double value;
table->GetValue(row, col).ToDouble(&value);
TimeTextCtrl tt(&grid,
NumericTextCtrl tt(NumericConverter::TIME, &grid,
wxID_ANY,
te->GetFormat(),
value,
@ -790,7 +790,7 @@ wxAccStatus GridAx::GetName(int childId, wxString *name)
double value;
v.ToDouble(&value);
TimeTextCtrl tt(mGrid,
NumericTextCtrl tt(NumericConverter::TIME, mGrid,
wxID_ANY,
c->GetFormat(),
value,
@ -798,7 +798,7 @@ wxAccStatus GridAx::GetName(int childId, wxString *name)
wxPoint(10000, 10000), // create offscreen
wxDefaultSize,
true);
v = tt.GetTimeString();
v = tt.GetString();
}
if (c)

View File

@ -26,12 +26,12 @@ class GridAx;
#endif
class TimeTextCtrl;
class NumericTextCtrl;
// ----------------------------------------------------------------------------
// TimeEditor
//
// wxGridCellEditor for the TimeTextCtrl.
// wxGridCellEditor for the NumericTextCtrl.
// ----------------------------------------------------------------------------
#define GRID_VALUE_TIME wxT("Time")
@ -71,7 +71,7 @@ class TimeEditor:public wxGridCellEditor
wxGridCellEditor *Clone() const;
wxString GetValue() const;
TimeTextCtrl *GetTimeCtrl() const { return (TimeTextCtrl *)m_control; };
NumericTextCtrl *GetTimeCtrl() const { return (NumericTextCtrl *)m_control; }
private:
@ -84,7 +84,7 @@ class TimeEditor:public wxGridCellEditor
// ----------------------------------------------------------------------------
// TimeRenderer
//
// wxGridCellRenderer for the TimeTextCtrl.
// wxGridCellRenderer for the NumericTextCtrl.
// ----------------------------------------------------------------------------
class TimeRenderer : public wxGridCellRenderer

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,286 @@
/**********************************************************************
Audacity: A Digital Audio Editor
NumericTextCtrl.h
Dominic Mazzoni
See NumericTextCtrl.cpp for documentation on how to use the
format string to specify how a NumericTextCtrl's fields are
laid out.
**********************************************************************/
#ifndef __AUDACITY_TIME_TEXT_CTRL__
#define __AUDACITY_TIME_TEXT_CTRL__
#include <wx/defs.h>
#include <wx/dynarray.h>
#include <wx/event.h>
#include <wx/panel.h>
#include <wx/stattext.h>
#include <wx/string.h>
#include <wx/textctrl.h>
#if wxUSE_ACCESSIBILITY
#include <wx/access.h>
#endif
// One event type for each type of control. Event is raised when a control
// changes its format. Owners of controls of the same type can listen and
// update their formats to agree.
DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_TIMETEXTCTRL_UPDATED, -1);
DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_FREQUENCYTEXTCTRL_UPDATED, -1);
DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_LOGFREQUENCYTEXTCTRL_UPDATED,
-1);
/** \brief struct to hold a formatting control string and it's user facing name
* Used in an array to hold the built-in time formats that are always available
* to the user */
struct BuiltinFormatString;
class NumericField;
WX_DECLARE_OBJARRAY(NumericField, NumericFieldArray);
class DigitInfo;
WX_DECLARE_OBJARRAY(DigitInfo, DigitInfoArray);
class NumericConverter
{
public:
enum Type {
TIME,
FREQUENCY,
LOG_FREQUENCY,
};
NumericConverter(Type type,
const wxString & formatName = wxEmptyString,
double value = 0.0f,
double sampleRate = 1.0f /* to prevent div by 0 */);
virtual void ValueToControls();
virtual void ValueToControls(double rawValue, bool nearest = true);
virtual void ControlsToValue();
virtual void ParseFormatString(const wxString & format);
void PrintDebugInfo();
void SetFormatName(const wxString & formatName);
void SetFormatString(const wxString & formatString);
void SetSampleRate(double sampleRate);
void SetValue(double newValue);
double GetValue();
wxString GetString();
wxString GetFormatString();
int GetFormatIndex();
int GetNumBuiltins();
wxString GetBuiltinName(const int index);
wxString GetBuiltinFormat(const int index);
wxString GetBuiltinFormat(const wxString & name);
// Adjust the value by the number "steps" in the active format.
// Increment if "dir" is 1, decrement if "dir" is -1.
void Adjust(int steps, int dir);
void Increment();
void Decrement();
protected:
Type mType;
double mValue;
wxString mFormatString;
NumericFieldArray mFields;
wxString mPrefix;
wxString mValueTemplate;
wxString mValueMask;
wxString mValueString;
double mScalingFactor;
double mSampleRate;
bool mNtscDrop;
int mFocusedDigit;
DigitInfoArray mDigits;
const BuiltinFormatString *mBuiltinFormatStrings;
int mNBuiltins;
int mDefaultNdx;
};
class NumericTextCtrl: public wxControl, public NumericConverter
{
friend class NumericTextCtrlAx;
public:
DECLARE_DYNAMIC_CLASS(NumericTextCtrl);
NumericTextCtrl(NumericConverter::Type type,
wxWindow *parent,
wxWindowID id,
wxString formatName = wxEmptyString,
double value = 0.0,
double sampleRate = 44100,
const wxPoint &pos = wxDefaultPosition,
const wxSize &size = wxDefaultSize,
bool autoPos = false);
virtual ~NumericTextCtrl();
virtual bool Layout();
virtual void Fit();
void SetSampleRate(double sampleRate);
void SetValue(double newValue);
void SetFormatString(const wxString & formatString);
void SetFormatName(const wxString & formatName);
void SetFieldFocus(int digit);
void EnableMenu(bool enable = true);
int GetFocusedField() { return mLastField; }
int GetFocusedDigit() { return mFocusedDigit; }
private:
void OnCaptureKey(wxCommandEvent &event);
void OnKeyDown(wxKeyEvent &event);
void OnKeyUp(wxKeyEvent &event);
void OnMouse(wxMouseEvent &event);
void OnErase(wxEraseEvent &event);
void OnPaint(wxPaintEvent &event);
void OnFocus(wxFocusEvent &event);
void OnContext(wxContextMenuEvent &event);
void OnMenu(wxCommandEvent &event);
void ValueToControls();
void ControlsToValue();
// If autoPos was enabled, focus the first non-zero digit
void UpdateAutoFocus();
void Updated(bool keyup = false);
private:
bool mMenuEnabled;
wxBitmap *mBackgroundBitmap;
wxFont *mDigitFont;
wxFont *mLabelFont;
int mDigitBoxW;
int mDigitBoxH;
int mDigitW;
int mDigitH;
int mBorderLeft;
int mBorderTop;
int mBorderRight;
int mBorderBottom;
int mWidth;
int mHeight;
int mButtonWidth;
int mLastField;
// If true, the focus will be set to the first non-zero digit
bool mAutoPos;
// Keeps track of extra fractional scrollwheel steps
double mScrollRemainder;
NumericConverter::Type mType;
DECLARE_EVENT_TABLE()
};
#if wxUSE_ACCESSIBILITY
class NumericTextCtrlAx: public wxWindowAccessible
{
public:
NumericTextCtrlAx(NumericTextCtrl * ctrl);
virtual ~ NumericTextCtrlAx();
// Performs the default action. childId is 0 (the action for this object)
// or > 0 (the action for a child).
// Return wxACC_NOT_SUPPORTED if there is no default action for this
// window (e.g. an edit control).
virtual wxAccStatus DoDefaultAction(int childId);
// Retrieves the address of an IDispatch interface for the specified child.
// All objects must support this property.
virtual wxAccStatus GetChild(int childId, wxAccessible **child);
// Gets the number of children.
virtual wxAccStatus GetChildCount(int *childCount);
// Gets the default action for this object (0) or > 0 (the action for a child).
// Return wxACC_OK even if there is no action. actionName is the action, or the empty
// string if there is no action.
// The retrieved string describes the action that is performed on an object,
// not what the object does as a result. For example, a toolbar button that prints
// a document has a default action of "Press" rather than "Prints the current document."
virtual wxAccStatus GetDefaultAction(int childId, wxString *actionName);
// Returns the description for this object or a child.
virtual wxAccStatus GetDescription(int childId, wxString *description);
// Gets the window with the keyboard focus.
// If childId is 0 and child is NULL, no object in
// this subhierarchy has the focus.
// If this object has the focus, child should be 'this'.
virtual wxAccStatus GetFocus(int *childId, wxAccessible **child);
// Returns help text for this object or a child, similar to tooltip text.
virtual wxAccStatus GetHelpText(int childId, wxString *helpText);
// Returns the keyboard shortcut for this object or child.
// Return e.g. ALT+K
virtual wxAccStatus GetKeyboardShortcut(int childId, wxString *shortcut);
// Returns the rectangle for this object (id = 0) or a child element (id > 0).
// rect is in screen coordinates.
virtual wxAccStatus GetLocation(wxRect & rect, int elementId);
// Gets the name of the specified object.
virtual wxAccStatus GetName(int childId, wxString *name);
// Returns a role constant.
virtual wxAccStatus GetRole(int childId, wxAccRole *role);
// Gets a variant representing the selected children
// of this object.
// Acceptable values:
// - a null variant (IsNull() returns TRUE)
// - a list variant (GetType() == wxT("list"))
// - an integer representing the selected child element,
// or 0 if this object is selected (GetType() == wxT("long"))
// - a "void*" pointer to a wxAccessible child object
virtual wxAccStatus GetSelections(wxVariant *selections);
// Returns a state constant.
virtual wxAccStatus GetState(int childId, long *state);
// Returns a localized string representing the value for the object
// or child.
virtual wxAccStatus GetValue(int childId, wxString *strValue);
private:
NumericTextCtrl *mCtrl;
int mLastField;
int mLastDigit;
};
#endif // wxUSE_ACCESSIBILITY
#endif // __AUDACITY_TIME_TEXT_CTRL__

File diff suppressed because it is too large Load Diff

View File

@ -1,273 +0,0 @@
/**********************************************************************
Audacity: A Digital Audio Editor
TimeTextCtrl.h
Dominic Mazzoni
See TimeTextCtrl.cpp for documentation on how to use the
format string to specify how a TimeTextCtrl's fields are
laid out.
**********************************************************************/
#ifndef __AUDACITY_TIME_TEXT_CTRL__
#define __AUDACITY_TIME_TEXT_CTRL__
#include <wx/defs.h>
#include <wx/dynarray.h>
#include <wx/event.h>
#include <wx/panel.h>
#include <wx/stattext.h>
#include <wx/string.h>
#include <wx/textctrl.h>
#if wxUSE_ACCESSIBILITY
#include <wx/access.h>
#endif
DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_TIMETEXTCTRL_UPDATED, -1);
/** \brief struct to hold a formatting control string and it's user facing name
* Used in an array to hold the built-in time formats that are always available
* to the user */
struct BuiltinFormatString
{
wxString name;
wxString formatStr;
};
class TimeField;
WX_DECLARE_OBJARRAY(TimeField, TimeFieldArray);
class DigitInfo;
WX_DECLARE_OBJARRAY(DigitInfo, DigitInfoArray);
class TimeConverter
{
public:
TimeConverter(const wxString & formatName = wxEmptyString,
double timeValue = 0.0f,
double sampleRate = 1.0f /* to prevent div by 0 */);
virtual void ValueToControls();
virtual void ValueToControls(double RawTime, bool nearest = true);
virtual void ControlsToValue();
virtual void ParseFormatString(const wxString & format);
void PrintDebugInfo();
void SetFormatName(const wxString & formatName);
void SetFormatString(const wxString & formatString);
void SetSampleRate(double sampleRate);
void SetTimeValue(double newTime);
double GetTimeValue();
wxString GetTimeString();
wxString GetFormatString();
int GetFormatIndex();
int GetNumBuiltins();
wxString GetBuiltinName(const int index);
wxString GetBuiltinFormat(const int index);
wxString GetBuiltinFormat(const wxString & name);
// Adjust the value by the number "steps" in the active format.
// Increment if "dir" is 1, descrement if "dir" is -1.
void Adjust(int steps, int dir);
void Increment();
void Decrement();
protected:
/** \brief array of formats the control knows about internally
* array of string pairs for name of the format and the format string
* needed to create that format output. This is used for the pop-up
* list of formats to choose from in the control. Note that the size will
* need adjusting if new time formats are added */
BuiltinFormatString BuiltinFormatStrings[16];
double mTimeValue;
wxString mFormatString;
TimeFieldArray mFields;
wxString mPrefix;
wxString mValueTemplate;
wxString mValueMask;
wxString mValueString;
double mScalingFactor;
double mSampleRate;
bool mNtscDrop;
int mFocusedDigit;
DigitInfoArray mDigits;
};
class TimeTextCtrl: public wxControl, public TimeConverter
{
friend class TimeTextCtrlAx;
public:
DECLARE_DYNAMIC_CLASS(TimeTextCtrl);
TimeTextCtrl(wxWindow *parent,
wxWindowID id,
wxString formatName = wxEmptyString,
double timeValue = 0.0,
double sampleRate = 44100,
const wxPoint &pos = wxDefaultPosition,
const wxSize &size = wxDefaultSize,
bool autoPos = false);
virtual ~TimeTextCtrl();
virtual bool Layout();
virtual void Fit();
void SetSampleRate(double sampleRate);
void SetTimeValue(double newTime);
void SetFormatString(const wxString & formatString);
void SetFormatName(const wxString & formatName);
void SetFieldFocus(int digit);
void EnableMenu(bool enable = true);
int GetFocusedField() { return mLastField; };
int GetFocusedDigit() { return mFocusedDigit; };
private:
void OnCaptureKey(wxCommandEvent &event);
void OnKeyDown(wxKeyEvent &event);
void OnKeyUp(wxKeyEvent &event);
void OnMouse(wxMouseEvent &event);
void OnErase(wxEraseEvent &event);
void OnPaint(wxPaintEvent &event);
void OnFocus(wxFocusEvent &event);
void OnContext(wxContextMenuEvent &event);
void OnMenu(wxCommandEvent &event);
void ValueToControls();
void ControlsToValue();
// If autoPos was enabled, focus the first non-zero digit
void UpdateAutoFocus();
void Updated(bool keyup = false);
private:
bool mMenuEnabled;
wxBitmap *mBackgroundBitmap;
wxFont *mDigitFont;
wxFont *mLabelFont;
int mDigitBoxW;
int mDigitBoxH;
int mDigitW;
int mDigitH;
int mBorderLeft;
int mBorderTop;
int mBorderRight;
int mBorderBottom;
int mWidth;
int mHeight;
int mButtonWidth;
int mLastField;
// If true, the focus will be set to the first non-zero digit
bool mAutoPos;
// Keeps track of extra fractional scrollwheel steps
double mScrollRemainder;
DECLARE_EVENT_TABLE()
};
#if wxUSE_ACCESSIBILITY
class TimeTextCtrlAx: public wxWindowAccessible
{
public:
TimeTextCtrlAx(TimeTextCtrl * ctrl);
virtual ~ TimeTextCtrlAx();
// Performs the default action. childId is 0 (the action for this object)
// or > 0 (the action for a child).
// Return wxACC_NOT_SUPPORTED if there is no default action for this
// window (e.g. an edit control).
virtual wxAccStatus DoDefaultAction(int childId);
// Retrieves the address of an IDispatch interface for the specified child.
// All objects must support this property.
virtual wxAccStatus GetChild(int childId, wxAccessible **child);
// Gets the number of children.
virtual wxAccStatus GetChildCount(int *childCount);
// Gets the default action for this object (0) or > 0 (the action for a child).
// Return wxACC_OK even if there is no action. actionName is the action, or the empty
// string if there is no action.
// The retrieved string describes the action that is performed on an object,
// not what the object does as a result. For example, a toolbar button that prints
// a document has a default action of "Press" rather than "Prints the current document."
virtual wxAccStatus GetDefaultAction(int childId, wxString *actionName);
// Returns the description for this object or a child.
virtual wxAccStatus GetDescription(int childId, wxString *description);
// Gets the window with the keyboard focus.
// If childId is 0 and child is NULL, no object in
// this subhierarchy has the focus.
// If this object has the focus, child should be 'this'.
virtual wxAccStatus GetFocus(int *childId, wxAccessible **child);
// Returns help text for this object or a child, similar to tooltip text.
virtual wxAccStatus GetHelpText(int childId, wxString *helpText);
// Returns the keyboard shortcut for this object or child.
// Return e.g. ALT+K
virtual wxAccStatus GetKeyboardShortcut(int childId, wxString *shortcut);
// Returns the rectangle for this object (id = 0) or a child element (id > 0).
// rect is in screen coordinates.
virtual wxAccStatus GetLocation(wxRect & rect, int elementId);
// Gets the name of the specified object.
virtual wxAccStatus GetName(int childId, wxString *name);
// Returns a role constant.
virtual wxAccStatus GetRole(int childId, wxAccRole *role);
// Gets a variant representing the selected children
// of this object.
// Acceptable values:
// - a null variant (IsNull() returns TRUE)
// - a list variant (GetType() == wxT("list"))
// - an integer representing the selected child element,
// or 0 if this object is selected (GetType() == wxT("long"))
// - a "void*" pointer to a wxAccessible child object
virtual wxAccStatus GetSelections(wxVariant *selections);
// Returns a state constant.
virtual wxAccStatus GetState(int childId, long *state);
// Returns a localized string representing the value for the object
// or child.
virtual wxAccStatus GetValue(int childId, wxString *strValue);
private:
TimeTextCtrl *mCtrl;
int mLastField;
int mLastDigit;
};
#endif // wxUSE_ACCESSIBILITY
#endif // __AUDACITY_TIME_TEXT_CTRL__