audiomonitor: fix param sync issue that caused crashes
This commit is contained in:
@@ -164,9 +164,9 @@ void AudioManager::SetOutputParams(const AudioParams ¶ms)
|
||||
|
||||
// Refresh output device
|
||||
SetOutputDevice(output_device_info_);
|
||||
|
||||
emit AudioParamsChanged(output_params_);
|
||||
}
|
||||
|
||||
emit AudioParamsChanged(output_params_);
|
||||
}
|
||||
|
||||
void AudioManager::SetInputDevice(const QAudioDeviceInfo &info)
|
||||
|
||||
@@ -35,6 +35,11 @@ class AudioMonitorPanel : public PanelWidget
|
||||
public:
|
||||
AudioMonitorPanel(QWidget* parent = nullptr);
|
||||
|
||||
bool IsPlaying() const
|
||||
{
|
||||
return audio_monitor_->IsPlaying();
|
||||
}
|
||||
|
||||
void SetParams(const AudioParams& params)
|
||||
{
|
||||
audio_monitor_->SetParams(params);
|
||||
|
||||
@@ -49,17 +49,19 @@ AudioMonitor::AudioMonitor(QWidget *parent) :
|
||||
|
||||
void AudioMonitor::SetParams(const AudioParams ¶ms)
|
||||
{
|
||||
params_ = params;
|
||||
if (params_ != params) {
|
||||
params_ = params;
|
||||
|
||||
for (int i=0;i<values_.size();i++) {
|
||||
values_[i].resize(params_.channel_count());
|
||||
values_[i].fill(0);
|
||||
for (int i=0;i<values_.size();i++) {
|
||||
values_[i].resize(params_.channel_count());
|
||||
values_[i].fill(0);
|
||||
}
|
||||
|
||||
peaked_.resize(params_.channel_count());
|
||||
peaked_.fill(false);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
peaked_.resize(params_.channel_count());
|
||||
peaked_.fill(false);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void AudioMonitor::OutputDeviceSet(AudioPlaybackCache *cache, qint64 offset, int playback_speed)
|
||||
@@ -241,7 +243,7 @@ void AudioMonitor::paintGL()
|
||||
|
||||
QVector<double> v(params_.channel_count(), 0);
|
||||
|
||||
if (file_ || waveform_) {
|
||||
if (IsPlaying()) {
|
||||
// Determines how many milliseconds have passed since last update
|
||||
qint64 current_time = QDateTime::currentMSecsSinceEpoch();
|
||||
qint64 delta_time = current_time - last_time_;
|
||||
@@ -308,7 +310,7 @@ void AudioMonitor::paintGL()
|
||||
}
|
||||
}
|
||||
|
||||
if (all_zeroes && !file_ && !waveform_) {
|
||||
if (all_zeroes && !IsPlaying()) {
|
||||
// Optimize by disabling the update loop
|
||||
SetUpdateLoop(false);
|
||||
}
|
||||
|
||||
@@ -38,6 +38,11 @@ class AudioMonitor : public QOpenGLWidget
|
||||
public:
|
||||
AudioMonitor(QWidget* parent = nullptr);
|
||||
|
||||
bool IsPlaying() const
|
||||
{
|
||||
return file_ || waveform_;
|
||||
}
|
||||
|
||||
public slots:
|
||||
void SetParams(const AudioParams& params);
|
||||
|
||||
|
||||
@@ -692,7 +692,9 @@ void MainWindow::SaveCustomShortcuts()
|
||||
|
||||
void MainWindow::UpdateAudioMonitorParams(ViewerOutput *viewer)
|
||||
{
|
||||
audio_monitor_panel_->SetParams(viewer ? viewer->GetAudioParams() : AudioParams());
|
||||
if (!audio_monitor_panel_->IsPlaying()) {
|
||||
audio_monitor_panel_->SetParams(viewer ? viewer->GetAudioParams() : AudioParams());
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::FocusedPanelChanged(PanelWidget *panel)
|
||||
|
||||
Reference in New Issue
Block a user