mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-10 16:43:33 +02:00
Persist meter state across toolbar resets and fix clipping indicator
This will fix the clipping indicator turning on after a toolbar reset and, as a bonus, the timers now only run if playing, capturing, or monitoring. Will (slightly) reduce the CPU consumption.
This commit is contained in:
@@ -81,6 +81,36 @@ void MeterToolBar::Create(wxWindow * parent)
|
|||||||
OnSize(dummy);
|
OnSize(dummy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MeterToolBar::ReCreateButtons()
|
||||||
|
{
|
||||||
|
void *playState = NULL;
|
||||||
|
void *recordState = NULL;
|
||||||
|
|
||||||
|
if (mPlayMeter && mProject->GetPlaybackMeter() == mPlayMeter)
|
||||||
|
{
|
||||||
|
mProject->SetPlaybackMeter( NULL );
|
||||||
|
playState = mPlayMeter->SaveState();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mRecordMeter && mProject->GetCaptureMeter() == mRecordMeter)
|
||||||
|
{
|
||||||
|
mProject->SetCaptureMeter( NULL );
|
||||||
|
recordState = mRecordMeter->SaveState();
|
||||||
|
}
|
||||||
|
|
||||||
|
ToolBar::ReCreateButtons();
|
||||||
|
|
||||||
|
if (playState)
|
||||||
|
{
|
||||||
|
mPlayMeter->RestoreState(playState);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (recordState)
|
||||||
|
{
|
||||||
|
mRecordMeter->RestoreState(recordState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MeterToolBar::Populate()
|
void MeterToolBar::Populate()
|
||||||
{
|
{
|
||||||
mSizer = new wxGridBagSizer();
|
mSizer = new wxGridBagSizer();
|
||||||
|
@@ -39,6 +39,7 @@ class MeterToolBar:public ToolBar {
|
|||||||
void Create(wxWindow *parent);
|
void Create(wxWindow *parent);
|
||||||
|
|
||||||
virtual void Populate();
|
virtual void Populate();
|
||||||
|
virtual void ReCreateButtons();
|
||||||
virtual void Repaint(wxDC * WXUNUSED(dc)) {};
|
virtual void Repaint(wxDC * WXUNUSED(dc)) {};
|
||||||
virtual void EnableDisableButtons() {};
|
virtual void EnableDisableButtons() {};
|
||||||
virtual void UpdatePrefs();
|
virtual void UpdatePrefs();
|
||||||
|
@@ -248,7 +248,6 @@ Meter::Meter(AudacityProject *project,
|
|||||||
this);
|
this);
|
||||||
|
|
||||||
if (mIsInput) {
|
if (mIsInput) {
|
||||||
// Register for AudioIO Monitor events
|
|
||||||
wxTheApp->Connect(EVT_AUDIOIO_MONITOR,
|
wxTheApp->Connect(EVT_AUDIOIO_MONITOR,
|
||||||
wxCommandEventHandler(Meter::OnAudioIOStatus),
|
wxCommandEventHandler(Meter::OnAudioIOStatus),
|
||||||
NULL,
|
NULL,
|
||||||
@@ -266,6 +265,12 @@ Meter::Meter(AudacityProject *project,
|
|||||||
// mDarkPen = wxPen( theTheme.Colour( clrMeterInputDarkPen ), 1, wxSOLID);
|
// mDarkPen = wxPen( theTheme.Colour( clrMeterInputDarkPen ), 1, wxSOLID);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// Register for AudioIO events
|
||||||
|
wxTheApp->Connect(EVT_AUDIOIO_PLAYBACK,
|
||||||
|
wxCommandEventHandler(Meter::OnAudioIOStatus),
|
||||||
|
NULL,
|
||||||
|
this);
|
||||||
|
|
||||||
mPen = wxPen( theTheme.Colour( clrMeterOutputPen ), 1, wxSOLID);
|
mPen = wxPen( theTheme.Colour( clrMeterOutputPen ), 1, wxSOLID);
|
||||||
mBrush = wxBrush( theTheme.Colour( clrMeterOutputBrush ), wxSOLID);
|
mBrush = wxBrush( theTheme.Colour( clrMeterOutputBrush ), wxSOLID);
|
||||||
mRMSBrush = wxBrush( theTheme.Colour( clrMeterOutputRMSBrush ), wxSOLID);
|
mRMSBrush = wxBrush( theTheme.Colour( clrMeterOutputRMSBrush ), wxSOLID);
|
||||||
@@ -313,7 +318,7 @@ Meter::~Meter()
|
|||||||
{
|
{
|
||||||
if (mIsInput)
|
if (mIsInput)
|
||||||
{
|
{
|
||||||
// Unregister for AudioIO Monitor events
|
// Unregister for AudioIO events
|
||||||
wxTheApp->Disconnect(EVT_AUDIOIO_MONITOR,
|
wxTheApp->Disconnect(EVT_AUDIOIO_MONITOR,
|
||||||
wxCommandEventHandler(Meter::OnAudioIOStatus),
|
wxCommandEventHandler(Meter::OnAudioIOStatus),
|
||||||
NULL,
|
NULL,
|
||||||
@@ -323,6 +328,13 @@ Meter::~Meter()
|
|||||||
NULL,
|
NULL,
|
||||||
this);
|
this);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxTheApp->Disconnect(EVT_AUDIOIO_PLAYBACK,
|
||||||
|
wxCommandEventHandler(Meter::OnAudioIOStatus),
|
||||||
|
NULL,
|
||||||
|
this);
|
||||||
|
}
|
||||||
|
|
||||||
// Unregister for our preference update event
|
// Unregister for our preference update event
|
||||||
wxTheApp->Disconnect(EVT_METER_PREFERENCES_CHANGED,
|
wxTheApp->Disconnect(EVT_METER_PREFERENCES_CHANGED,
|
||||||
@@ -379,8 +391,6 @@ void Meter::UpdatePrefs()
|
|||||||
|
|
||||||
Reset(mRate, false);
|
Reset(mRate, false);
|
||||||
|
|
||||||
mTimer.Start(1000 / mMeterRefreshRate);
|
|
||||||
|
|
||||||
mLayoutValid = false;
|
mLayoutValid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -674,7 +684,6 @@ void Meter::OnMouse(wxMouseEvent &evt)
|
|||||||
else {
|
else {
|
||||||
Reset(mRate, true);
|
Reset(mRate, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -701,14 +710,14 @@ void Meter::Reset(double sampleRate, bool resetClipping)
|
|||||||
|
|
||||||
// wxTimers seem to be a little unreliable - sometimes they stop for
|
// wxTimers seem to be a little unreliable - sometimes they stop for
|
||||||
// no good reason, so this "primes" it every now and then...
|
// no good reason, so this "primes" it every now and then...
|
||||||
mTimer.Stop();
|
// mTimer.Stop();
|
||||||
|
|
||||||
// While it's stopped, empty the queue
|
// While it's stopped, empty the queue
|
||||||
mQueue.Clear();
|
mQueue.Clear();
|
||||||
|
|
||||||
mLayoutValid = false;
|
mLayoutValid = false;
|
||||||
|
|
||||||
mTimer.Start(1000 / mMeterRefreshRate);
|
// mTimer.Start(1000 / mMeterRefreshRate);
|
||||||
|
|
||||||
Refresh(false);
|
Refresh(false);
|
||||||
}
|
}
|
||||||
@@ -755,14 +764,8 @@ void Meter::UpdateDisplay(int numChannels, int numFrames, float *sampleData)
|
|||||||
int num = intmin(numChannels, mNumBars);
|
int num = intmin(numChannels, mNumBars);
|
||||||
MeterUpdateMsg msg;
|
MeterUpdateMsg msg;
|
||||||
|
|
||||||
|
memset(&msg, 0, sizeof(msg));
|
||||||
msg.numFrames = numFrames;
|
msg.numFrames = numFrames;
|
||||||
for(j=0; j<mNumBars; j++) {
|
|
||||||
msg.peak[j] = 0;
|
|
||||||
msg.rms[j] = 0;
|
|
||||||
msg.clipping[j] = false;
|
|
||||||
msg.headPeakCount[j] = 0;
|
|
||||||
msg.tailPeakCount[j] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(i=0; i<numFrames; i++) {
|
for(i=0; i<numFrames; i++) {
|
||||||
for(j=0; j<num; j++) {
|
for(j=0; j<num; j++) {
|
||||||
@@ -1718,6 +1721,8 @@ void Meter::OnAudioIOStatus(wxCommandEvent &evt)
|
|||||||
{
|
{
|
||||||
mActive = true;
|
mActive = true;
|
||||||
|
|
||||||
|
mTimer.Start(1000 / mMeterRefreshRate);
|
||||||
|
|
||||||
if (evt.GetEventType() == EVT_AUDIOIO_MONITOR)
|
if (evt.GetEventType() == EVT_AUDIOIO_MONITOR)
|
||||||
{
|
{
|
||||||
mMonitoring = mActive;
|
mMonitoring = mActive;
|
||||||
@@ -1725,11 +1730,15 @@ void Meter::OnAudioIOStatus(wxCommandEvent &evt)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
mTimer.Stop();
|
||||||
|
|
||||||
mMonitoring = false;
|
mMonitoring = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
mTimer.Stop();
|
||||||
|
|
||||||
mMonitoring = false;
|
mMonitoring = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1740,6 +1749,31 @@ void Meter::OnAudioIOStatus(wxCommandEvent &evt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SaveState() and RestoreState() exist solely for purpose of recreating toolbars
|
||||||
|
// They should really be quering the project for current audio I/O state, but there
|
||||||
|
// isn't a clear way of doing that just yet. (It should NOT query AudioIO.)
|
||||||
|
void *Meter::SaveState()
|
||||||
|
{
|
||||||
|
bool *state = new bool[2];
|
||||||
|
state[0] = mMonitoring;
|
||||||
|
state[1] = mActive;
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Meter::RestoreState(void *state)
|
||||||
|
{
|
||||||
|
mMonitoring = ((bool *)state)[0];
|
||||||
|
mActive = ((bool *)state)[1];
|
||||||
|
|
||||||
|
if (mActive)
|
||||||
|
{
|
||||||
|
mTimer.Start(1000 / mMeterRefreshRate);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete [] state;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Pop-up menu handlers
|
// Pop-up menu handlers
|
||||||
//
|
//
|
||||||
|
@@ -171,6 +171,10 @@ class Meter : public wxPanel
|
|||||||
|
|
||||||
void StartMonitoring();
|
void StartMonitoring();
|
||||||
|
|
||||||
|
// These exist solely for the purpose of reseting the toolbars
|
||||||
|
void *SaveState();
|
||||||
|
void RestoreState(void *state);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//
|
//
|
||||||
// Event handlers
|
// Event handlers
|
||||||
|
Reference in New Issue
Block a user