1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-10 16:43:33 +02:00

Bug 2418 - Time toolbar displays incorrect time if project rate isn't 44100

This commit is contained in:
Leland Lucius
2020-05-31 03:22:53 -05:00
parent 419e152ebd
commit c43c757bce
4 changed files with 40 additions and 10 deletions

View File

@@ -163,6 +163,20 @@ const NumericFormatSymbol & ProjectSettings::GetAudioTimeFormat() const
return mAudioTimeFormat; return mAudioTimeFormat;
} }
double ProjectSettings::GetRate() const
{
return mRate;
}
void ProjectSettings::SetRate(double rate)
{
auto &project = mProject;
if (rate != mRate) {
mRate = rate;
Notify( project, ChangedProjectRate );
}
}
void ProjectSettings::SetSnapTo(int snap) void ProjectSettings::SetSnapTo(int snap)
{ {
mSnapTo = snap; mSnapTo = snap;

View File

@@ -58,14 +58,13 @@ public:
// Values retrievable from GetInt() of the event for settings change // Values retrievable from GetInt() of the event for settings change
enum EventCode : int { enum EventCode : int {
ChangedSyncLock, ChangedSyncLock,
ChangedProjectRate
}; };
explicit ProjectSettings( AudacityProject &project ); explicit ProjectSettings( AudacityProject &project );
ProjectSettings( const ProjectSettings & ) PROHIBITED; ProjectSettings( const ProjectSettings & ) PROHIBITED;
ProjectSettings &operator=( const ProjectSettings & ) PROHIBITED; ProjectSettings &operator=( const ProjectSettings & ) PROHIBITED;
double GetRate() const { return mRate; }
void SetRate( double value ) { mRate = value; }
bool GetTracksFitVerticallyZoomed() const { return mTracksFitVerticallyZoomed; } //lda bool GetTracksFitVerticallyZoomed() const { return mTracksFitVerticallyZoomed; } //lda
void SetTracksFitVerticallyZoomed(bool flag) { mTracksFitVerticallyZoomed = flag; } //lda void SetTracksFitVerticallyZoomed(bool flag) { mTracksFitVerticallyZoomed = flag; } //lda
@@ -76,6 +75,11 @@ public:
bool IsSyncLocked() const; bool IsSyncLocked() const;
void SetSyncLock(bool flag); void SetSyncLock(bool flag);
// Rate
void SetRate(double rate);
double GetRate() const;
// Snap To // Snap To
void SetSnapTo(int snap); void SetSnapTo(int snap);

View File

@@ -23,12 +23,13 @@
#include <wx/sizer.h> #include <wx/sizer.h>
#endif #endif
#include "SelectionBarListener.h"
#include "TimeToolBar.h" #include "TimeToolBar.h"
#include "ToolManager.h" #include "ToolManager.h"
#include "SelectionBarListener.h"
#include "../AudioIO.h" #include "../AudioIO.h"
#include "../ProjectAudioIO.h" #include "../ProjectAudioIO.h"
#include "../ProjectSettings.h"
#include "../ViewInfo.h" #include "../ViewInfo.h"
IMPLEMENT_CLASS(TimeToolBar, ToolBar); IMPLEMENT_CLASS(TimeToolBar, ToolBar);
@@ -51,6 +52,7 @@ TimeToolBar::TimeToolBar(AudacityProject &project)
mListener(NULL), mListener(NULL),
mAudioTime(NULL) mAudioTime(NULL)
{ {
project.Bind(EVT_PROJECT_SETTINGS_CHANGE, &TimeToolBar::OnSettingsChanged, this);
} }
TimeToolBar::~TimeToolBar() TimeToolBar::~TimeToolBar()
@@ -70,16 +72,13 @@ const TimeToolBar &TimeToolBar::Get(const AudacityProject &project)
void TimeToolBar::Populate() void TimeToolBar::Populate()
{ {
const auto &settings = ProjectSettings::Get(mProject);
// Get the default sample rate // Get the default sample rate
auto rate = gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleRate"), auto rate = settings.GetRate();
AudioIO::GetOptimalSupportedSampleRate());
// Get the default time format // Get the default time format
auto format = NumericConverter::HoursMinsSecondsFormat(); auto format = settings.GetAudioTimeFormat();
if (mListener)
{
format = mListener->TT_GetAudioTimeFormat();
}
// Create the read-only time control // Create the read-only time control
mAudioTime = safenew NumericTextCtrl(this, AudioPositionID, NumericConverter::TIME, format, 0.0, rate); mAudioTime = safenew NumericTextCtrl(this, AudioPositionID, NumericConverter::TIME, format, 0.0, rate);
@@ -261,6 +260,18 @@ void TimeToolBar::SetResizingLimits()
SetMaxSize(maxSize); SetMaxSize(maxSize);
} }
// Called when the project settings change
void TimeToolBar::OnSettingsChanged(wxCommandEvent &evt)
{
evt.Skip(false);
if (evt.GetInt() == ProjectSettings::ChangedProjectRate && mAudioTime)
{
const auto &settings = ProjectSettings::Get(mProject);
mAudioTime->SetSampleRate(settings.GetRate());
}
}
// Called when the format drop downs is changed. // Called when the format drop downs is changed.
// This causes recreation of the toolbar contents. // This causes recreation of the toolbar contents.
void TimeToolBar::OnUpdate(wxCommandEvent &evt) void TimeToolBar::OnUpdate(wxCommandEvent &evt)

View File

@@ -46,6 +46,7 @@ private:
void SetResizingLimits(); void SetResizingLimits();
wxSize ComputeSizing(int digitH); wxSize ComputeSizing(int digitH);
void OnSettingsChanged(wxCommandEvent &evt);
void OnUpdate(wxCommandEvent &evt); void OnUpdate(wxCommandEvent &evt);
void OnSize(wxSizeEvent &evt); void OnSize(wxSizeEvent &evt);
void OnIdle(wxIdleEvent &evt); void OnIdle(wxIdleEvent &evt);