From ae5f5f90ff20f00e584a5d4a4c96c03fcbb83556 Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Sun, 12 Mar 2023 22:29:05 +0100 Subject: [PATCH] Add variable support for audio condition spinbox controls --- src/macro-core/macro-condition-audio.cpp | 57 +++++++++++++++--------- src/macro-core/macro-condition-audio.hpp | 16 +++---- 2 files changed, 44 insertions(+), 29 deletions(-) diff --git a/src/macro-core/macro-condition-audio.cpp b/src/macro-core/macro-condition-audio.cpp index 680a1a3e..d5527eb6 100644 --- a/src/macro-core/macro-condition-audio.cpp +++ b/src/macro-core/macro-condition-audio.cpp @@ -205,15 +205,16 @@ bool MacroConditionAudio::Save(obs_data_t *obj) const { MacroCondition::Save(obj); _audioSource.Save(obj, "audioSource"); - obs_data_set_int(obj, "volume", _volume); - obs_data_set_int(obj, "syncOffset", _syncOffset); obs_data_set_int(obj, "monitor", _monitorType); - obs_data_set_double(obj, "balance", _balance); + _volume.Save(obj, "volume"); + _syncOffset.Save(obj, "syncOffset"); + _balance.Save(obj, "balance"); obs_data_set_int(obj, "checkType", static_cast(_checkType)); obs_data_set_int(obj, "outputCondition", static_cast(_outputCondition)); obs_data_set_int(obj, "volumeCondition", static_cast(_volumeCondition)); + obs_data_set_int(obj, "version", 1); return true; } @@ -238,11 +239,17 @@ bool MacroConditionAudio::Load(obs_data_t *obj) { MacroCondition::Load(obj); _audioSource.Load(obj, "audioSource"); - _volume = obs_data_get_int(obj, "volume"); - _syncOffset = obs_data_get_int(obj, "syncOffset"); _monitorType = static_cast( obs_data_get_int(obj, "monitor")); - _balance = obs_data_get_double(obj, "balance"); + if (!obs_data_has_user_value(obj, "version")) { + _volume = obs_data_get_int(obj, "volume"); + _syncOffset = obs_data_get_int(obj, "syncOffset"); + _balance = obs_data_get_double(obj, "balance"); + } else { + _volume.Load(obj, "volume"); + _syncOffset.Load(obj, "syncOffset"); + _balance.Load(obj, "balance"); + } _checkType = static_cast(obs_data_get_int(obj, "checkType")); _outputCondition = static_cast( obs_data_get_int(obj, "outputCondition")); @@ -320,8 +327,8 @@ MacroConditionAudioEdit::MacroConditionAudioEdit( _checkTypes(new QComboBox()), _sources(new SourceSelectionWidget(this, QStringList(), true)), _condition(new QComboBox()), - _volume(new QSpinBox()), - _syncOffset(new QSpinBox()), + _volume(new VariableSpinBox()), + _syncOffset(new VariableSpinBox()), _monitorTypes(new QComboBox), _balance(new SliderSpinBox(0., 1., "")) { @@ -339,14 +346,21 @@ MacroConditionAudioEdit::MacroConditionAudioEdit( QWidget::connect(_checkTypes, SIGNAL(currentIndexChanged(int)), this, SLOT(CheckTypeChanged(int))); - QWidget::connect(_volume, SIGNAL(valueChanged(int)), this, - SLOT(VolumeThresholdChanged(int))); - QWidget::connect(_syncOffset, SIGNAL(valueChanged(int)), this, - SLOT(SyncOffsetChanged(int))); + QWidget::connect( + _volume, + SIGNAL(NumberVariableChanged(const NumberVariable &)), + this, + SLOT(VolumeThresholdChanged(const NumberVariable &))); + QWidget::connect( + _syncOffset, + SIGNAL(NumberVariableChanged(const NumberVariable &)), + this, SLOT(SyncOffsetChanged(const NumberVariable &))); QWidget::connect(_monitorTypes, SIGNAL(currentIndexChanged(int)), this, SLOT(MonitorTypeChanged(int))); - QWidget::connect(_balance, SIGNAL(DoubleValueChanged(double)), this, - SLOT(BalanceChanged(double))); + QWidget::connect( + _balance, + SIGNAL(DoubleValueChanged(const NumberVariable &)), + this, SLOT(BalanceChanged(const NumberVariable &))); QWidget::connect(_condition, SIGNAL(currentIndexChanged(int)), this, SLOT(ConditionChanged(int))); QWidget::connect(_sources, @@ -391,8 +405,8 @@ void MacroConditionAudioEdit::UpdateVolmeterSource() layout->addWidget(_volMeter); QWidget::connect(_volMeter->GetSlider(), SIGNAL(valueChanged(int)), - _volume, SLOT(setValue(int))); - QWidget::connect(_volume, SIGNAL(valueChanged(int)), + _volume, SLOT(SetFixedValue(int))); + QWidget::connect(_volume, SIGNAL(FixedValueChanged(int)), _volMeter->GetSlider(), SLOT(setValue(int))); // Slider will default to 0 so set it manually once @@ -414,7 +428,8 @@ void MacroConditionAudioEdit::SourceChanged(const SourceSelection &source) QString::fromStdString(_entryData->GetShortDesc())); } -void MacroConditionAudioEdit::VolumeThresholdChanged(int vol) +void MacroConditionAudioEdit::VolumeThresholdChanged( + const NumberVariable &vol) { if (_loading || !_entryData) { return; @@ -424,7 +439,7 @@ void MacroConditionAudioEdit::VolumeThresholdChanged(int vol) _entryData->_volume = vol; } -void MacroConditionAudioEdit::SyncOffsetChanged(int value) +void MacroConditionAudioEdit::SyncOffsetChanged(const NumberVariable &value) { if (_loading || !_entryData) { return; @@ -444,7 +459,7 @@ void MacroConditionAudioEdit::MonitorTypeChanged(int value) _entryData->_monitorType = static_cast(value); } -void MacroConditionAudioEdit::BalanceChanged(double value) +void MacroConditionAudioEdit::BalanceChanged(const NumberVariable &value) { if (_loading || !_entryData) { return; @@ -504,8 +519,8 @@ void MacroConditionAudioEdit::UpdateEntryData() } _sources->SetSource(_entryData->_audioSource); - _volume->setValue(_entryData->_volume); - _syncOffset->setValue(_entryData->_syncOffset); + _volume->SetValue(_entryData->_volume); + _syncOffset->SetValue(_entryData->_syncOffset); _monitorTypes->setCurrentIndex(_entryData->_monitorType); _balance->SetDoubleValue(_entryData->_balance); _checkTypes->setCurrentIndex(_checkTypes->findData( diff --git a/src/macro-core/macro-condition-audio.hpp b/src/macro-core/macro-condition-audio.hpp index d5242392..b8a10b09 100644 --- a/src/macro-core/macro-condition-audio.hpp +++ b/src/macro-core/macro-condition-audio.hpp @@ -50,10 +50,10 @@ public: }; SourceSelection _audioSource; - int _volume = 0; - int64_t _syncOffset = 0; + NumberVariable _volume = 0; + NumberVariable _syncOffset = 0; obs_monitoring_type _monitorType = OBS_MONITORING_TYPE_NONE; - double _balance = 0.5; + NumberVariable _balance = 0.5; Type _checkType = Type::OUTPUT_VOLUME; OutputCondition _outputCondition = OutputCondition::ABOVE; VolumeCondition _volumeCondition = VolumeCondition::ABOVE; @@ -90,12 +90,12 @@ public: private slots: void SourceChanged(const SourceSelection &); - void VolumeThresholdChanged(int vol); + void VolumeThresholdChanged(const NumberVariable &vol); void ConditionChanged(int cond); void CheckTypeChanged(int cond); - void SyncOffsetChanged(int value); + void SyncOffsetChanged(const NumberVariable &value); void MonitorTypeChanged(int value); - void BalanceChanged(double value); + void BalanceChanged(const NumberVariable &value); signals: void HeaderInfoChanged(const QString &); @@ -104,8 +104,8 @@ protected: QComboBox *_checkTypes; SourceSelectionWidget *_sources; QComboBox *_condition; - QSpinBox *_volume; - QSpinBox *_syncOffset; + VariableSpinBox *_volume; + VariableSpinBox *_syncOffset; QComboBox *_monitorTypes; SliderSpinBox *_balance; VolControl *_volMeter = nullptr;