1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-02 08:59:28 +02:00

Revised fix for Bug 1977 - Using Spectrogram Settings in TCP causes Audacity to reset Project Rate to default 44100 Hz

This revised fix:
- No longer attempts to drive "Default sample rate" from the selection toolbar.
- No longer drives 'Project rate' direct from prefs.  It's usual it comes from the project.
- Instead 'Project rate' in the project might change if 'Default sample rate' pref is updated, but ONLY if the project has no tracks.
- When 'Project rate' in the project is updated, that is now always signaled to the selection toolbar.  Previously it wasn't.
This commit is contained in:
James Crook 2018-09-11 12:48:03 +01:00
parent e990fd4f18
commit 993cea506d
2 changed files with 20 additions and 6 deletions

View File

@ -1351,7 +1351,16 @@ void AudacityProject::UpdatePrefsVariables()
gPrefs->Read(wxT("/GUI/TracksFitVerticallyZoomed"), &mTracksFitVerticallyZoomed, false); gPrefs->Read(wxT("/GUI/TracksFitVerticallyZoomed"), &mTracksFitVerticallyZoomed, false);
// gPrefs->Read(wxT("/GUI/UpdateSpectrogram"), &mViewInfo.bUpdateSpectrogram, true); // gPrefs->Read(wxT("/GUI/UpdateSpectrogram"), &mViewInfo.bUpdateSpectrogram, true);
gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleRate"), &mRate, AudioIO::GetOptimalSupportedSampleRate()); // The DefaultProjectSample rate is the rate for new projects.
// Do not change this project's rate, unless there are no tracks.
if( GetTrackCount() == 0){
gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleRate"), &mRate, AudioIO::GetOptimalSupportedSampleRate());
// If necessary, we change this rate in the selection toolbar too.
auto bar = GetSelectionBar();
if( bar ){
bar->SetRate( mRate );
}
}
mDefaultFormat = QualityPrefs::SampleFormatChoice(); mDefaultFormat = QualityPrefs::SampleFormatChoice();
gPrefs->Read(wxT("/AudioIO/SeekShortPeriod"), &mSeekShort, 1.0); gPrefs->Read(wxT("/AudioIO/SeekShortPeriod"), &mSeekShort, 1.0);
@ -1559,6 +1568,8 @@ double AudacityProject::AS_GetRate()
return mRate; return mRate;
} }
// Typically this came from the SelectionToolbar and does not need to
// be communicated back to it.
void AudacityProject::AS_SetRate(double rate) void AudacityProject::AS_SetRate(double rate)
{ {
mRate = rate; mRate = rate;

View File

@ -116,6 +116,8 @@ SelectionBar::SelectionBar()
// will occur. // will occur.
// Refer to bug #462 for a scenario where the division-by-zero causes // Refer to bug #462 for a scenario where the division-by-zero causes
// Audacity to fail. // Audacity to fail.
// We expect mRate to be set from the project later.
// We could just use AudioIO::GetOptimalSupportedSampleRate() here.
mRate = (double) gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleRate"), mRate = (double) gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleRate"),
AudioIO::GetOptimalSupportedSampleRate()); AudioIO::GetOptimalSupportedSampleRate());
@ -341,7 +343,12 @@ void SelectionBar::Populate()
void SelectionBar::UpdatePrefs() void SelectionBar::UpdatePrefs()
{ {
mRate = (double) gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleRate"), AudioIO::GetOptimalSupportedSampleRate()); // The project rate is no longer driven from here.
// IF /SamplingRate/DefaultProjectSampleRate has changed, that is sent to the project.
// IF the project has no tracks, then the project updates its sample rate, and
// signals that back to the SelectionBar via SetRate().
// Usually though there are tracks, and changes to that pref will only affect new
// or empty projects.
wxCommandEvent e; wxCommandEvent e;
e.SetInt(mStartTime->GetFormatIndex()); e.SetInt(mStartTime->GetFormatIndex());
@ -658,9 +665,6 @@ void SelectionBar::SetRate(double rate)
// if the rate is actually being changed // if the rate is actually being changed
mRate = rate; // update the stored rate mRate = rate; // update the stored rate
mRateBox->SetValue(wxString::Format(wxT("%d"), (int)rate)); mRateBox->SetValue(wxString::Format(wxT("%d"), (int)rate));
// Update rate in stored prefs.
// This will also update rate in preferences dialog.
gPrefs->Write(wxT("/SamplingRate/DefaultProjectSampleRate"), mRate);
// update the TimeTextCtrls if they exist // update the TimeTextCtrls if they exist
NumericTextCtrl ** Ctrls[5] = { &mStartTime, &mEndTime, &mLengthTime, &mCenterTime, &mAudioTime }; NumericTextCtrl ** Ctrls[5] = { &mStartTime, &mEndTime, &mLengthTime, &mCenterTime, &mAudioTime };
@ -676,7 +680,6 @@ void SelectionBar::OnRate(wxCommandEvent & WXUNUSED(event))
if (mRateBox->GetValue().ToDouble(&mRate) && // is a numeric value if (mRateBox->GetValue().ToDouble(&mRate) && // is a numeric value
(mRate != 0.0)) (mRate != 0.0))
{ {
gPrefs->Write(wxT("/SamplingRate/DefaultProjectSampleRate"), mRate);
NumericTextCtrl ** Ctrls[5] = { &mStartTime, &mEndTime, &mLengthTime, &mCenterTime, &mAudioTime }; NumericTextCtrl ** Ctrls[5] = { &mStartTime, &mEndTime, &mLengthTime, &mCenterTime, &mAudioTime };
int i; int i;
for(i=0;i<5;i++) for(i=0;i<5;i++)