@@ -62,17 +62,17 @@ MacroConditionAudio::~MacroConditionAudio()
62
62
bool MacroConditionAudio::CheckOutputCondition ()
63
63
{
64
64
bool ret = false ;
65
- auto s = obs_weak_source_get_source (_audioSource.GetSource ());
65
+ OBSSourceAutoRelease source =
66
+ obs_weak_source_get_source (_audioSource.GetSource ());
66
67
68
+ // peak will have a value from -60 db to 0 db so we need to scale it
67
69
double curVolume = ((double )_peak + 60 ) * 1.7 ;
68
70
69
71
switch (_outputCondition) {
70
72
case OutputCondition::ABOVE:
71
- // peak will have a value from -60 db to 0 db
72
73
ret = curVolume > _volume;
73
74
break ;
74
75
case OutputCondition::BELOW:
75
- // peak will have a value from -60 db to 0 db
76
76
ret = curVolume < _volume;
77
77
break ;
78
78
default :
@@ -84,21 +84,21 @@ bool MacroConditionAudio::CheckOutputCondition()
84
84
85
85
// Reset for next check
86
86
_peak = -std::numeric_limits<float >::infinity ();
87
- obs_source_release (s);
88
87
if (_audioSource.GetType () == SourceSelection::Type::VARIABLE) {
89
88
ResetVolmeter ();
90
89
}
91
90
92
- return ret;
91
+ return ret && source ;
93
92
}
94
93
95
94
bool MacroConditionAudio::CheckVolumeCondition ()
96
95
{
97
96
bool ret = false ;
98
- auto s = obs_weak_source_get_source (_audioSource.GetSource ());
97
+ OBSSourceAutoRelease source =
98
+ obs_weak_source_get_source (_audioSource.GetSource ());
99
99
100
- float curVolume = obs_source_get_volume (s );
101
- bool muted = obs_source_muted (s );
100
+ float curVolume = obs_source_get_volume (source );
101
+ bool muted = obs_source_muted (source );
102
102
103
103
switch (_volumeCondition) {
104
104
case VolumeCondition::ABOVE:
@@ -126,10 +126,9 @@ bool MacroConditionAudio::CheckVolumeCondition()
126
126
}
127
127
128
128
SetTempVarValue (" configured_volume" , std::to_string (curVolume));
129
- SetTempVarValue (" muted" , muted ? " true" : " false" );
129
+ SetTempVarValue (" muted" , (source && muted) ? " true" : " false" );
130
130
131
- obs_source_release (s);
132
- return ret;
131
+ return ret && source;
133
132
}
134
133
135
134
bool MacroConditionAudio::CheckSyncOffset ()
@@ -139,17 +138,17 @@ bool MacroConditionAudio::CheckSyncOffset()
139
138
}
140
139
141
140
bool ret = false ;
142
- auto s = obs_weak_source_get_source (_audioSource.GetSource ());
143
- auto curOffset = obs_source_get_sync_offset (s) / nsPerMs;
141
+ OBSSourceAutoRelease source =
142
+ obs_weak_source_get_source (_audioSource.GetSource ());
143
+ auto curOffset = obs_source_get_sync_offset (source) / nsPerMs;
144
144
if (_outputCondition == OutputCondition::ABOVE) {
145
145
ret = curOffset > _syncOffset;
146
146
} else {
147
147
ret = curOffset < _syncOffset;
148
148
}
149
149
SetVariableValue (std::to_string (curOffset));
150
150
SetTempVarValue (" sync_offset" , std::to_string (curOffset));
151
- obs_source_release (s);
152
- return ret;
151
+ return ret && source;
153
152
}
154
153
155
154
bool MacroConditionAudio::CheckMonitor ()
@@ -159,13 +158,13 @@ bool MacroConditionAudio::CheckMonitor()
159
158
}
160
159
161
160
bool ret = false ;
162
- auto s = obs_weak_source_get_source (_audioSource.GetSource ());
163
- ret = obs_source_get_monitoring_type (s) == _monitorType;
161
+ OBSSourceAutoRelease source =
162
+ obs_weak_source_get_source (_audioSource.GetSource ());
163
+ ret = obs_source_get_monitoring_type (source) == _monitorType;
164
164
SetVariableValue (" " );
165
165
SetTempVarValue (" monitor" ,
166
- std::to_string (obs_source_get_monitoring_type (s)));
167
- obs_source_release (s);
168
- return ret;
166
+ std::to_string (obs_source_get_monitoring_type (source)));
167
+ return ret && source;
169
168
}
170
169
171
170
bool MacroConditionAudio::CheckBalance ()
@@ -175,17 +174,17 @@ bool MacroConditionAudio::CheckBalance()
175
174
}
176
175
177
176
bool ret = false ;
178
- auto s = obs_weak_source_get_source (_audioSource.GetSource ());
179
- auto curBalance = obs_source_get_balance_value (s);
177
+ OBSSourceAutoRelease source =
178
+ obs_weak_source_get_source (_audioSource.GetSource ());
179
+ auto curBalance = obs_source_get_balance_value (source);
180
180
if (_outputCondition == OutputCondition::ABOVE) {
181
181
ret = curBalance > _balance;
182
182
} else {
183
183
ret = curBalance < _balance;
184
184
}
185
185
SetVariableValue (std::to_string (curBalance));
186
186
SetTempVarValue (" balance" , std::to_string (curBalance));
187
- obs_source_release (s);
188
- return ret;
187
+ return ret && source;
189
188
}
190
189
191
190
bool MacroConditionAudio::CheckCondition ()
@@ -239,13 +238,12 @@ obs_volmeter_t *AddVolmeterToSource(MacroConditionAudio *entry,
239
238
obs_volmeter_t *volmeter = obs_volmeter_create (OBS_FADER_LOG);
240
239
obs_volmeter_add_callback (volmeter, MacroConditionAudio::SetVolumeLevel,
241
240
entry);
242
- obs_source_t *as = obs_weak_source_get_source (source);
243
- if (!obs_volmeter_attach_source (volmeter, as )) {
244
- const char *name = obs_source_get_name (as );
241
+ OBSSourceAutoRelease audioSource = obs_weak_source_get_source (source);
242
+ if (!obs_volmeter_attach_source (volmeter, audioSource )) {
243
+ const char *name = obs_source_get_name (audioSource );
245
244
blog (LOG_WARNING, " failed to attach volmeter to source %s" ,
246
245
name);
247
246
}
248
- obs_source_release (as);
249
247
250
248
return volmeter;
251
249
}
@@ -455,10 +453,9 @@ MacroConditionAudioEdit::MacroConditionAudioEdit(
455
453
void MacroConditionAudioEdit::UpdateVolmeterSource ()
456
454
{
457
455
delete _volMeter;
458
- obs_source_t * soruce = obs_weak_source_get_source (
456
+ OBSSourceAutoRelease soruce = obs_weak_source_get_source (
459
457
_entryData->_audioSource .GetSource ());
460
- _volMeter = new VolControl (soruce);
461
- obs_source_release (soruce);
458
+ _volMeter = new VolControl (soruce.Get ());
462
459
463
460
QLayout *layout = this ->layout ();
464
461
layout->addWidget (_volMeter);
0 commit comments