mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-16 16:10:06 +02:00
Use wxWeakRef to avoid dangling pointer
This commit is contained in:
parent
94b97f5c95
commit
12983e1685
@ -1210,7 +1210,6 @@ AudioIO::AudioIO()
|
||||
mUpdatingMeters = false;
|
||||
|
||||
mOwningProject = NULL;
|
||||
mInputMeter = NULL;
|
||||
mOutputMeter = NULL;
|
||||
|
||||
PaError err = Pa_Initialize();
|
||||
@ -1662,7 +1661,7 @@ bool AudioIO::StartPortAudioStream(double sampleRate,
|
||||
if (!mOwningProject)
|
||||
return false;
|
||||
|
||||
mInputMeter = NULL;
|
||||
mInputMeter.Release();
|
||||
mOutputMeter = NULL;
|
||||
|
||||
mLastPaError = paNoError;
|
||||
@ -1751,7 +1750,7 @@ bool AudioIO::StartPortAudioStream(double sampleRate,
|
||||
else
|
||||
captureParameters.suggestedLatency = latencyDuration/1000.0;
|
||||
|
||||
mInputMeter = mOwningProject->GetCaptureMeter();
|
||||
SetCaptureMeter( mOwningProject, mOwningProject->GetCaptureMeter() );
|
||||
}
|
||||
|
||||
SetMeters();
|
||||
@ -2479,11 +2478,13 @@ void AudioIO::SetCaptureMeter(AudacityProject *project, MeterPanel *meter)
|
||||
{
|
||||
if (!mOwningProject || mOwningProject == project)
|
||||
{
|
||||
mInputMeter = meter;
|
||||
if (mInputMeter)
|
||||
if (meter)
|
||||
{
|
||||
mInputMeter = meter;
|
||||
mInputMeter->Reset(mRate, true);
|
||||
}
|
||||
else
|
||||
mInputMeter.Release();
|
||||
}
|
||||
}
|
||||
|
||||
@ -2499,10 +2500,6 @@ void AudioIO::SetPlaybackMeter(AudacityProject *project, MeterPanel *meter)
|
||||
}
|
||||
}
|
||||
|
||||
MeterPanel * AudioIO::GetCaptureMeter(){
|
||||
return mInputMeter;
|
||||
}
|
||||
|
||||
void AudioIO::SetMeters()
|
||||
{
|
||||
if (mInputMeter)
|
||||
@ -2817,7 +2814,7 @@ void AudioIO::StopStream()
|
||||
if (pMixerBoard)
|
||||
pMixerBoard->ResetMeters(false);
|
||||
|
||||
mInputMeter = NULL;
|
||||
mInputMeter.Release();
|
||||
mOutputMeter = NULL;
|
||||
mOwningProject = NULL;
|
||||
|
||||
@ -4506,7 +4503,7 @@ double AudioIO::AILAGetLastDecisionTime() {
|
||||
void AudioIO::AILAProcess(double maxPeak) {
|
||||
AudacityProject *proj = GetActiveProject();
|
||||
if (proj && mAILAActive) {
|
||||
if (mInputMeter->IsClipping()) {
|
||||
if (mInputMeter && mInputMeter->IsClipping()) {
|
||||
mAILAClipped = true;
|
||||
wxPrintf("clipped");
|
||||
}
|
||||
@ -4515,7 +4512,7 @@ void AudioIO::AILAProcess(double maxPeak) {
|
||||
|
||||
if ((mAILATotalAnalysis == 0 || mAILAAnalysisCounter < mAILATotalAnalysis) && mTime - mAILALastStartTime >= mAILAAnalysisTime) {
|
||||
putchar('\n');
|
||||
mAILAMax = mInputMeter->ToLinearIfDB(mAILAMax);
|
||||
mAILAMax = mInputMeter ? mInputMeter->ToLinearIfDB(mAILAMax) : 0.0;
|
||||
double iv = (double) Px_GetInputVolume(mPortMixer);
|
||||
unsigned short changetype = 0; //0 - no change, 1 - increase change, 2 - decrease change
|
||||
wxPrintf("mAILAAnalysisCounter:%d\n", mAILAAnalysisCounter);
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <wx/atomic.h>
|
||||
#include <wx/weakref.h>
|
||||
|
||||
#ifdef USE_MIDI
|
||||
|
||||
@ -410,7 +411,6 @@ class AUDACITY_DLL_API AudioIO final {
|
||||
bool IsAvailable(AudacityProject *projecT);
|
||||
void SetCaptureMeter(AudacityProject *project, MeterPanel *meter);
|
||||
void SetPlaybackMeter(AudacityProject *project, MeterPanel *meter);
|
||||
MeterPanel * GetCaptureMeter();
|
||||
|
||||
private:
|
||||
/** \brief Set the current VU meters - this should be done once after
|
||||
@ -694,7 +694,7 @@ private:
|
||||
PaError mLastPaError;
|
||||
|
||||
AudacityProject *mOwningProject;
|
||||
MeterPanel *mInputMeter;
|
||||
wxWeakRef<MeterPanel> mInputMeter{};
|
||||
MeterPanel *mOutputMeter;
|
||||
bool mUpdateMeters;
|
||||
volatile bool mUpdatingMeters;
|
||||
|
@ -367,12 +367,6 @@ MeterPanel::~MeterPanel()
|
||||
wxCommandEventHandler(MeterPanel::OnMeterPrefsUpdated),
|
||||
NULL,
|
||||
this);
|
||||
|
||||
// LLL: This prevents a crash during termination if monitoring
|
||||
// is active.
|
||||
if (gAudioIO && gAudioIO->IsMonitoring())
|
||||
if( gAudioIO->GetCaptureMeter() == this )
|
||||
gAudioIO->StopStream();
|
||||
}
|
||||
|
||||
void MeterPanel::UpdatePrefs()
|
||||
|
Loading…
x
Reference in New Issue
Block a user