diff --git a/plugins/base/macro-condition-audio.cpp b/plugins/base/macro-condition-audio.cpp index 2686a5d4..221eb0e3 100644 --- a/plugins/base/macro-condition-audio.cpp +++ b/plugins/base/macro-condition-audio.cpp @@ -294,6 +294,7 @@ bool MacroConditionAudio::Load(obs_data_t *obj) _volumeCondition = static_cast( obs_data_get_int(obj, "volumeCondition")); _volmeter = AddVolmeterToSource(this, _audioSource.GetSource()); + if (obs_data_get_int(obj, "version") != 2) { _useDb = false; _volumeDB = 0.0; @@ -416,7 +417,7 @@ MacroConditionAudioEdit::MacroConditionAudioEdit( _checkTypes(new QComboBox()), _sources(new SourceSelectionWidget(this, QStringList(), true)), _condition(new QComboBox()), - _volumePercent(new VariableSpinBox()), + _volumePercent(new VariableDoubleSpinBox()), _volumeDB(new VariableDoubleSpinBox), _percentDBToggle(new QPushButton), _syncOffset(new VariableSpinBox()), @@ -444,8 +445,9 @@ MacroConditionAudioEdit::MacroConditionAudioEdit( SLOT(CheckTypeChanged(int))); QWidget::connect( _volumePercent, - SIGNAL(NumberVariableChanged(const NumberVariable &)), - this, SLOT(VolumePercentChanged(const NumberVariable &))); + SIGNAL(NumberVariableChanged(const NumberVariable &)), + this, + SLOT(VolumePercentChanged(const NumberVariable &))); QWidget::connect( _syncOffset, SIGNAL(NumberVariableChanged(const NumberVariable &)), @@ -506,11 +508,12 @@ void MacroConditionAudioEdit::UpdateVolmeterSource() auto layout = this->layout(); layout->addWidget(_volMeter); - QWidget::connect(_volMeter->GetSlider(), &QSlider::valueChanged, - [=](int) { SyncSliderAndValueSelection(true); }); + QWidget::connect(_volMeter->GetSlider(), + &DoubleSlider::DoubleValChanged, + [=](double) { SyncSliderAndValueSelection(true); }); // Slider will default to 0 so set it manually once - _volMeter->GetSlider()->setValue(_entryData->_volumePercent); + SyncSliderAndValueSelection(false); } void MacroConditionAudioEdit::SourceChanged(const SourceSelection &source) @@ -531,7 +534,7 @@ void MacroConditionAudioEdit::SourceChanged(const SourceSelection &source) } void MacroConditionAudioEdit::VolumePercentChanged( - const NumberVariable &vol) + const NumberVariable &vol) { if (_loading || !_entryData) { return; @@ -600,35 +603,35 @@ void MacroConditionAudioEdit::PercentDBClicked() void MacroConditionAudioEdit::SyncSliderAndValueSelection(bool sliderMoved) { - if (_loading || !_entryData) { + if (!_entryData) { return; } if (sliderMoved) { + auto sliderPosition = _volMeter->GetSlider()->DoubleValue(); + // Adjust to the dB scale on the volume meter widget + auto dBScaleValue = ((sliderPosition * 3.0) / 5.0) - 60.0; + if (_entryData->_useDb) { - _volumeDB->SetFixedValue(PercentToDecibel( - (float)_volMeter->GetSlider()->value() / - 100.0)); + _volumeDB->SetFixedValue(dBScaleValue); const QSignalBlocker blocker(this); _volumePercent->SetFixedValue( - _volMeter->GetSlider()->value()); + DecibelToPercent(dBScaleValue) * 100); } else { _volumePercent->SetFixedValue( - _volMeter->GetSlider()->value()); + DecibelToPercent(dBScaleValue) * 100); const QSignalBlocker blocker(this); - _volumeDB->SetFixedValue(PercentToDecibel( - (float)_volMeter->GetSlider()->value() / - 100.0)); + _volumeDB->SetFixedValue(dBScaleValue); } } else { const QSignalBlocker blocker(this); - if (_entryData->_useDb) { - _volMeter->GetSlider()->setValue( - DecibelToPercent(_entryData->_volumeDB) * 100); - } else { - _volMeter->GetSlider()->setValue( - _entryData->_volumePercent); - } + double dBValue = + _entryData->_useDb + ? _entryData->_volumeDB.GetFixedValue() + : PercentToDecibel(_entryData->_volumePercent / + 100.0); + auto sliderPosition = (dBValue + 60.0) * 5 / 3.0; + _volMeter->GetSlider()->SetDoubleVal(sliderPosition); } } diff --git a/plugins/base/macro-condition-audio.hpp b/plugins/base/macro-condition-audio.hpp index 2ffd3b41..217089a5 100644 --- a/plugins/base/macro-condition-audio.hpp +++ b/plugins/base/macro-condition-audio.hpp @@ -55,11 +55,11 @@ public: SourceSelection _audioSource; bool _useDb = false; - NumberVariable _volumePercent = 0; - NumberVariable _volumeDB = 0.0; - NumberVariable _syncOffset = 0; + DoubleVariable _volumePercent = 0; + DoubleVariable _volumeDB = 0.0; + IntVariable _syncOffset = 0; obs_monitoring_type _monitorType = OBS_MONITORING_TYPE_NONE; - NumberVariable _balance = 0.5; + DoubleVariable _balance = 0.5; OutputCondition _outputCondition = OutputCondition::ABOVE; VolumeCondition _volumeCondition = VolumeCondition::ABOVE; obs_volmeter_t *_volmeter = nullptr; @@ -97,7 +97,7 @@ public: private slots: void SourceChanged(const SourceSelection &); - void VolumePercentChanged(const NumberVariable &vol); + void VolumePercentChanged(const NumberVariable &vol); void ConditionChanged(int cond); void CheckTypeChanged(int cond); void SyncOffsetChanged(const NumberVariable &value); @@ -117,7 +117,7 @@ private: QComboBox *_checkTypes; SourceSelectionWidget *_sources; QComboBox *_condition; - VariableSpinBox *_volumePercent; + VariableDoubleSpinBox *_volumePercent; VariableDoubleSpinBox *_volumeDB; QPushButton *_percentDBToggle; VariableSpinBox *_syncOffset;