mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-09-07 17:16:00 -05:00
Minor style changes (#114)
* use GetWeakSourceName() where possible * add getCurrentScene() to scene group * silence OBS warning log and fix typo in audio switch * extract showing initial status of widgets to function in generic switch
This commit is contained in:
@@ -23,8 +23,9 @@ void AdvSceneSwitcher::on_audioAdd_clicked()
|
||||
void AdvSceneSwitcher::on_audioRemove_clicked()
|
||||
{
|
||||
QListWidgetItem *item = ui->audioSwitches->currentItem();
|
||||
if (!item)
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
@@ -39,8 +40,9 @@ void AdvSceneSwitcher::on_audioRemove_clicked()
|
||||
void AdvSceneSwitcher::on_audioUp_clicked()
|
||||
{
|
||||
int index = ui->audioSwitches->currentRow();
|
||||
if (!listMoveUp(ui->audioSwitches))
|
||||
if (!listMoveUp(ui->audioSwitches)) {
|
||||
return;
|
||||
}
|
||||
|
||||
AudioSwitchWidget *s1 =
|
||||
(AudioSwitchWidget *)ui->audioSwitches->itemWidget(
|
||||
@@ -60,8 +62,9 @@ void AdvSceneSwitcher::on_audioDown_clicked()
|
||||
{
|
||||
int index = ui->audioSwitches->currentRow();
|
||||
|
||||
if (!listMoveDown(ui->audioSwitches))
|
||||
if (!listMoveDown(ui->audioSwitches)) {
|
||||
return;
|
||||
}
|
||||
|
||||
AudioSwitchWidget *s1 =
|
||||
(AudioSwitchWidget *)ui->audioSwitches->itemWidget(
|
||||
@@ -79,8 +82,10 @@ void AdvSceneSwitcher::on_audioDown_clicked()
|
||||
|
||||
void AdvSceneSwitcher::on_audioFallback_toggled(bool on)
|
||||
{
|
||||
if (loading || !switcher)
|
||||
if (loading || !switcher) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
switcher->audioFallback.enable = on;
|
||||
}
|
||||
@@ -98,8 +103,9 @@ void SwitcherData::checkAudioSwitchFallback(OBSWeakSource &scene,
|
||||
scene = audioFallback.getScene();
|
||||
transition = audioFallback.transition;
|
||||
|
||||
if (verbose)
|
||||
if (verbose) {
|
||||
audioFallback.logMatch();
|
||||
}
|
||||
}
|
||||
|
||||
audioFallback.matchCount++;
|
||||
@@ -108,14 +114,16 @@ void SwitcherData::checkAudioSwitchFallback(OBSWeakSource &scene,
|
||||
void SwitcherData::checkAudioSwitch(bool &match, OBSWeakSource &scene,
|
||||
OBSWeakSource &transition)
|
||||
{
|
||||
if (AudioSwitch::pause)
|
||||
if (AudioSwitch::pause) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool fallbackChecked = false; // false if one or no match
|
||||
bool fallbackChecked = false; // false if only one or no match
|
||||
|
||||
for (AudioSwitch &s : audioSwitches) {
|
||||
if (!s.initialized())
|
||||
if (!s.initialized()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
obs_source_t *as = obs_weak_source_get_source(s.audioSource);
|
||||
bool audioActive = obs_source_active(as);
|
||||
@@ -124,14 +132,15 @@ void SwitcherData::checkAudioSwitch(bool &match, OBSWeakSource &scene,
|
||||
// peak will have a value from -60 db to 0 db
|
||||
bool volumeThresholdreached = false;
|
||||
|
||||
if (s.condition == ABOVE)
|
||||
if (s.condition == ABOVE) {
|
||||
volumeThresholdreached = ((double)s.peak + 60) * 1.7 >
|
||||
s.volumeThreshold;
|
||||
else
|
||||
} else {
|
||||
volumeThresholdreached = ((double)s.peak + 60) * 1.7 <
|
||||
s.volumeThreshold;
|
||||
}
|
||||
|
||||
// reset for next check
|
||||
// Reset for next check
|
||||
s.peak = -FLT_MAX;
|
||||
|
||||
if (volumeThresholdreached) {
|
||||
@@ -156,16 +165,19 @@ void SwitcherData::checkAudioSwitch(bool &match, OBSWeakSource &scene,
|
||||
transition = s.transition;
|
||||
match = true;
|
||||
|
||||
if (verbose)
|
||||
if (verbose) {
|
||||
s.logMatch();
|
||||
}
|
||||
|
||||
if (!audioFallback.enable)
|
||||
if (!audioFallback.enable) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!fallbackChecked)
|
||||
if (!fallbackChecked) {
|
||||
audioFallback.matchCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void SwitcherData::saveAudioSwitches(obs_data_t *obj)
|
||||
@@ -238,9 +250,11 @@ void AudioSwitch::setVolumeLevel(void *data,
|
||||
UNUSED_PARAMETER(inputPeak);
|
||||
AudioSwitch *s = static_cast<AudioSwitch *>(data);
|
||||
|
||||
for (int i = 1; i < MAX_AUDIO_CHANNELS; i++)
|
||||
if (peak[i] > s->peak)
|
||||
for (int i = 1; i < MAX_AUDIO_CHANNELS; i++) {
|
||||
if (peak[i] > s->peak) {
|
||||
s->peak = peak[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
obs_volmeter_t *AddVolmeterToSource(AudioSwitch *entry, obs_weak_source *source)
|
||||
@@ -281,10 +295,8 @@ void AudioSwitch::save(obs_data_t *obj)
|
||||
{
|
||||
SceneSwitcherEntry::save(obj);
|
||||
|
||||
obs_source_t *source = obs_weak_source_get_source(audioSource);
|
||||
const char *audioSourceName = obs_source_get_name(source);
|
||||
obs_data_set_string(obj, "audioSource", audioSourceName);
|
||||
obs_source_release(source);
|
||||
obs_data_set_string(obj, "audioSource",
|
||||
GetWeakSourceName(audioSource).c_str());
|
||||
|
||||
obs_data_set_int(obj, "volume", volumeThreshold);
|
||||
obs_data_set_int(obj, "condition", condition);
|
||||
@@ -294,13 +306,15 @@ void AudioSwitch::save(obs_data_t *obj)
|
||||
// To be removed in future version
|
||||
bool loadOldAudio(obs_data_t *obj, AudioSwitch *s)
|
||||
{
|
||||
if (!s)
|
||||
if (!s) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const char *scene = obs_data_get_string(obj, "scene");
|
||||
|
||||
if (strcmp(scene, "") == 0)
|
||||
if (strcmp(scene, "") == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
s->scene = GetWeakSourceByName(scene);
|
||||
|
||||
@@ -320,8 +334,9 @@ bool loadOldAudio(obs_data_t *obj, AudioSwitch *s)
|
||||
|
||||
void AudioSwitch::load(obs_data_t *obj)
|
||||
{
|
||||
if (loadOldAudio(obj, this))
|
||||
if (loadOldAudio(obj, this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SceneSwitcherEntry::load(obj);
|
||||
|
||||
@@ -439,11 +454,12 @@ AudioSwitchWidget::AudioSwitchWidget(QWidget *parent, AudioSwitch *s)
|
||||
audioVolumeThreshold = new QSpinBox();
|
||||
duration = new QDoubleSpinBox();
|
||||
|
||||
obs_source_t *soruce = nullptr;
|
||||
if (s)
|
||||
soruce = obs_weak_source_get_source(s->audioSource);
|
||||
volMeter = new VolControl(soruce);
|
||||
obs_source_release(soruce);
|
||||
obs_source_t *source = nullptr;
|
||||
if (s) {
|
||||
source = obs_weak_source_get_source(s->audioSource);
|
||||
}
|
||||
volMeter = new VolControl(source);
|
||||
obs_source_release(source);
|
||||
|
||||
audioVolumeThreshold->setSuffix("%");
|
||||
audioVolumeThreshold->setMaximum(100);
|
||||
@@ -543,8 +559,10 @@ void AudioSwitchWidget::UpdateVolmeterSource()
|
||||
|
||||
void AudioSwitchWidget::SourceChanged(const QString &text)
|
||||
{
|
||||
if (loading || !switchData)
|
||||
if (loading || !switchData) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
switchData->audioSource = GetWeakSourceByQString(text);
|
||||
switchData->resetVolmeter();
|
||||
@@ -553,24 +571,30 @@ void AudioSwitchWidget::SourceChanged(const QString &text)
|
||||
|
||||
void AudioSwitchWidget::VolumeThresholdChanged(int vol)
|
||||
{
|
||||
if (loading || !switchData)
|
||||
if (loading || !switchData) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
switchData->volumeThreshold = vol;
|
||||
}
|
||||
|
||||
void AudioSwitchWidget::ConditionChanged(int cond)
|
||||
{
|
||||
if (loading || !switchData)
|
||||
if (loading || !switchData) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
switchData->condition = (audioCondition)cond;
|
||||
}
|
||||
|
||||
void AudioSwitchWidget::DurationChanged(double dur)
|
||||
{
|
||||
if (loading || !switchData)
|
||||
if (loading || !switchData) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
switchData->duration = dur;
|
||||
}
|
||||
@@ -609,8 +633,10 @@ AudioSwitchFallbackWidget::AudioSwitchFallbackWidget(QWidget *parent,
|
||||
|
||||
void AudioSwitchFallbackWidget::DurationChanged(double dur)
|
||||
{
|
||||
if (loading || !switchData)
|
||||
if (loading || !switchData) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
switchData->duration = dur;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user