mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-08-21 16:55:29 -05:00
audio up / down draft (signals still not working)
This commit is contained in:
@@ -3593,103 +3593,6 @@
|
||||
<string>Audio</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_9">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="audioControlLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_52">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_66">
|
||||
<property name="text">
|
||||
<string>When the volume of</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="audioSources">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_67">
|
||||
<property name="text">
|
||||
<string>is above</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="audioVolumeThreshold">
|
||||
<property name="suffix">
|
||||
<string>%</string>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>100</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_68">
|
||||
<property name="text">
|
||||
<string>switch to</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="audioScenes">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_69">
|
||||
<property name="text">
|
||||
<string>using</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="audioTransitions"/>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_54">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="audioPlaceholder" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="audioSwitches">
|
||||
<property name="sizePolicy">
|
||||
|
||||
@@ -24,7 +24,6 @@ class SceneSwitcher : public QDialog {
|
||||
|
||||
public:
|
||||
std::unique_ptr<Ui_SceneSwitcher> ui;
|
||||
VolControl *volMeter = nullptr;
|
||||
bool loading = true;
|
||||
|
||||
SceneSwitcher(QWidget *parent);
|
||||
@@ -47,14 +46,12 @@ public:
|
||||
int IgnoreIdleWindowsFindByData(const QString &window);
|
||||
int randomFindByData(const QString &scene);
|
||||
int timeFindByData(const timeTrigger &trigger, const QTime &time);
|
||||
int audioFindByData(const QString &source, const int &volume);
|
||||
|
||||
void UpdateNonMatchingScene(const QString &name);
|
||||
void UpdateAutoStopScene(const QString &name);
|
||||
void UpdateAutoStartScene(const QString &name);
|
||||
void UpdateIdleDataTransition(const QString &name);
|
||||
void UpdateIdleDataScene(const QString &name);
|
||||
void SetAudioVolumeMeter(const QString &name);
|
||||
|
||||
void loadUI();
|
||||
void setupGeneralTab();
|
||||
@@ -197,8 +194,6 @@ public slots:
|
||||
void on_audioRemove_clicked();
|
||||
void on_audioUp_clicked();
|
||||
void on_audioDown_clicked();
|
||||
void on_audioSwitches_currentRowChanged(int idx);
|
||||
void on_audioSources_currentTextChanged(const QString &text);
|
||||
|
||||
void on_priorityUp_clicked();
|
||||
void on_priorityDown_clicked();
|
||||
|
||||
@@ -15,7 +15,6 @@ struct AudioSwitch : virtual SceneSwitcherEntry {
|
||||
OBSWeakSource audioSource = nullptr;
|
||||
int volumeThreshold = 0;
|
||||
float peak = -1;
|
||||
std::string audioSwitchStr;
|
||||
obs_volmeter_t *volmeter = nullptr;
|
||||
|
||||
const char *getType() { return "audio"; }
|
||||
@@ -30,26 +29,22 @@ struct AudioSwitch : virtual SceneSwitcherEntry {
|
||||
inline AudioSwitch(){};
|
||||
inline AudioSwitch(OBSWeakSource scene_, OBSWeakSource transition_,
|
||||
OBSWeakSource audioSource_, int volumeThreshold_,
|
||||
bool usePreviousScene_, std::string audioSwitchStr_);
|
||||
bool usePreviousScene_);
|
||||
AudioSwitch(const AudioSwitch &other);
|
||||
AudioSwitch(AudioSwitch &&other);
|
||||
inline ~AudioSwitch();
|
||||
AudioSwitch &operator=(const AudioSwitch &other);
|
||||
AudioSwitch &operator=(AudioSwitch &&other) noexcept;
|
||||
friend void swap(AudioSwitch &first, AudioSwitch &second);
|
||||
};
|
||||
|
||||
static inline QString MakeAudioSwitchName(const QString &scene,
|
||||
const QString &transition,
|
||||
const QString &audioSrouce,
|
||||
const int &volume);
|
||||
|
||||
class AudioSwitchWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
AudioSwitchWidget(AudioSwitch *s);
|
||||
void UpdateVolmeterSource();
|
||||
AudioSwitch& getSwitchData();
|
||||
AudioSwitch *getSwitchData();
|
||||
|
||||
private slots:
|
||||
void SceneChanged(const QString &text);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <condition_variable>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
#include <mutex>
|
||||
#include <QDateTime>
|
||||
#include <QThread>
|
||||
@@ -19,6 +20,7 @@
|
||||
#include "switch-window.hpp"
|
||||
#include "swtich-sequence.hpp"
|
||||
|
||||
|
||||
constexpr auto default_interval = 300;
|
||||
constexpr auto previous_scene_name = "Previous Scene";
|
||||
|
||||
@@ -97,7 +99,7 @@ struct SwitcherData {
|
||||
std::vector<TimeSwitch> timeSwitches;
|
||||
QDateTime liveTime;
|
||||
|
||||
std::vector<AudioSwitch> audioSwitches;
|
||||
std::deque<AudioSwitch> audioSwitches;
|
||||
|
||||
std::vector<int> functionNamesByPriority = std::vector<int>{
|
||||
default_priority_0, default_priority_1, default_priority_2,
|
||||
|
||||
@@ -4,60 +4,6 @@
|
||||
#include "headers/advanced-scene-switcher.hpp"
|
||||
#include "headers/volume-control.hpp"
|
||||
|
||||
void SceneSwitcher::on_audioSwitches_currentRowChanged(int idx)
|
||||
{
|
||||
if (loading)
|
||||
return;
|
||||
if (idx == -1)
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
void SceneSwitcher::on_audioSources_currentTextChanged(const QString &text)
|
||||
{
|
||||
SetAudioVolumeMeter(text);
|
||||
}
|
||||
|
||||
void SceneSwitcher::SetAudioVolumeMeter(const QString &name)
|
||||
{
|
||||
obs_source_t *soruce =
|
||||
obs_get_source_by_name(name.toUtf8().constData());
|
||||
if (!soruce) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (volMeter) {
|
||||
ui->audioControlLayout->removeWidget(volMeter);
|
||||
delete volMeter;
|
||||
}
|
||||
|
||||
volMeter = new VolControl(soruce);
|
||||
ui->audioControlLayout->addWidget(volMeter);
|
||||
obs_source_release(soruce);
|
||||
|
||||
QWidget::connect(volMeter->GetSlider(), SIGNAL(valueChanged(int)),
|
||||
ui->audioVolumeThreshold, SLOT(setValue(int)));
|
||||
QWidget::connect(ui->audioVolumeThreshold, SIGNAL(valueChanged(int)),
|
||||
volMeter->GetSlider(), SLOT(setValue(int)));
|
||||
}
|
||||
|
||||
int SceneSwitcher::audioFindByData(const QString &source, const int &volume)
|
||||
{
|
||||
QRegExp rx(MakeAudioSwitchName(QStringLiteral(".*"),
|
||||
QStringLiteral(".*"), source, volume));
|
||||
int count = ui->audioSwitches->count();
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
QListWidgetItem *item = ui->audioSwitches->item(i);
|
||||
QString str = item->data(Qt::UserRole).toString();
|
||||
|
||||
if (rx.exactMatch(str))
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void SceneSwitcher::on_audioAdd_clicked()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
@@ -92,14 +38,22 @@ void SceneSwitcher::on_audioUp_clicked()
|
||||
{
|
||||
int index = ui->audioSwitches->currentRow();
|
||||
if (index != -1 && index != 0) {
|
||||
delete ui->audioSwitches->itemWidget(
|
||||
ui->audioSwitches->item(index));
|
||||
AudioSwitchWidget *sw =
|
||||
new AudioSwitchWidget(&switcher->audioSwitches[index]);
|
||||
|
||||
ui->audioSwitches->insertItem(
|
||||
index - 1, ui->audioSwitches->takeItem(index));
|
||||
ui->audioSwitches->setItemWidget(
|
||||
ui->audioSwitches->item(index - 1), sw);
|
||||
|
||||
ui->audioSwitches->setCurrentRow(index - 1);
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
|
||||
iter_swap(switcher->audioSwitches.begin() + index,
|
||||
switcher->audioSwitches.begin() + index - 1);
|
||||
std::swap(switcher->audioSwitches[index],
|
||||
switcher->audioSwitches[index - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,14 +61,22 @@ void SceneSwitcher::on_audioDown_clicked()
|
||||
{
|
||||
int index = ui->audioSwitches->currentRow();
|
||||
if (index != -1 && index != ui->audioSwitches->count() - 1) {
|
||||
delete ui->audioSwitches->itemWidget(
|
||||
ui->audioSwitches->item(index));
|
||||
AudioSwitchWidget *sw =
|
||||
new AudioSwitchWidget(&switcher->audioSwitches[index]);
|
||||
|
||||
ui->audioSwitches->insertItem(
|
||||
index + 1, ui->audioSwitches->takeItem(index));
|
||||
ui->audioSwitches->setItemWidget(
|
||||
ui->audioSwitches->item(index + 1), sw);
|
||||
|
||||
ui->audioSwitches->setCurrentRow(index + 1);
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
|
||||
iter_swap(switcher->audioSwitches.begin() + index,
|
||||
switcher->audioSwitches.begin() + index + 1);
|
||||
std::swap(switcher->audioSwitches[index],
|
||||
switcher->audioSwitches[index + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,6 +87,9 @@ void SwitcherData::checkAudioSwitch(bool &match, OBSWeakSource &scene,
|
||||
return;
|
||||
|
||||
for (AudioSwitch &s : audioSwitches) {
|
||||
if (!s.initialized())
|
||||
continue;
|
||||
|
||||
obs_source_t *as = obs_weak_source_get_source(s.audioSource);
|
||||
bool audioActive = obs_source_active(as);
|
||||
obs_source_release(as);
|
||||
@@ -202,17 +167,11 @@ void SwitcherData::loadAudioSwitches(obs_data_t *obj)
|
||||
obs_data_get_string(array_obj, "audioSource");
|
||||
int vol = obs_data_get_int(array_obj, "volume");
|
||||
|
||||
std::string audioSwitchStr =
|
||||
MakeAudioSwitchName(scene, transition, audioSource, vol)
|
||||
.toUtf8()
|
||||
.constData();
|
||||
|
||||
switcher->audioSwitches.emplace_back(
|
||||
GetWeakSourceByName(scene),
|
||||
GetWeakTransitionByName(transition),
|
||||
GetWeakSourceByName(audioSource), vol,
|
||||
(strcmp(scene, previous_scene_name) == 0),
|
||||
audioSwitchStr);
|
||||
(strcmp(scene, previous_scene_name) == 0));
|
||||
|
||||
obs_data_release(array_obj);
|
||||
}
|
||||
@@ -221,10 +180,6 @@ void SwitcherData::loadAudioSwitches(obs_data_t *obj)
|
||||
|
||||
void SceneSwitcher::setupAudioTab()
|
||||
{
|
||||
populateSceneSelection(ui->audioScenes, true);
|
||||
populateTransitionSelection(ui->audioTransitions);
|
||||
populateAudioSelection(ui->audioSources);
|
||||
|
||||
for (auto &s : switcher->audioSwitches) {
|
||||
std::string sceneName = (s.usePreviousScene)
|
||||
? previous_scene_name
|
||||
@@ -286,12 +241,10 @@ bool AudioSwitch::valid()
|
||||
|
||||
inline AudioSwitch::AudioSwitch(OBSWeakSource scene_, OBSWeakSource transition_,
|
||||
OBSWeakSource audioSource_,
|
||||
int volumeThreshold_, bool usePreviousScene_,
|
||||
std::string audioSwitchStr_)
|
||||
int volumeThreshold_, bool usePreviousScene_)
|
||||
: SceneSwitcherEntry(scene_, transition_, usePreviousScene_),
|
||||
audioSource(audioSource_),
|
||||
volumeThreshold(volumeThreshold_),
|
||||
audioSwitchStr(audioSwitchStr_)
|
||||
volumeThreshold(volumeThreshold_)
|
||||
{
|
||||
volmeter = obs_volmeter_create(OBS_FADER_LOG);
|
||||
obs_volmeter_add_callback(volmeter, setVolumeLevel, this);
|
||||
@@ -308,8 +261,7 @@ AudioSwitch::AudioSwitch(const AudioSwitch &other)
|
||||
: SceneSwitcherEntry(other.scene, other.transition,
|
||||
other.usePreviousScene),
|
||||
audioSource(other.audioSource),
|
||||
volumeThreshold(other.volumeThreshold),
|
||||
audioSwitchStr(other.audioSwitchStr)
|
||||
volumeThreshold(other.volumeThreshold)
|
||||
{
|
||||
volmeter = obs_volmeter_create(OBS_FADER_LOG);
|
||||
obs_volmeter_add_callback(volmeter, setVolumeLevel, this);
|
||||
@@ -327,7 +279,6 @@ AudioSwitch::AudioSwitch(AudioSwitch &&other)
|
||||
other.usePreviousScene),
|
||||
audioSource(other.audioSource),
|
||||
volumeThreshold(other.volumeThreshold),
|
||||
audioSwitchStr(other.audioSwitchStr),
|
||||
volmeter(other.volmeter)
|
||||
{
|
||||
other.volmeter = nullptr;
|
||||
@@ -341,6 +292,8 @@ inline AudioSwitch::~AudioSwitch()
|
||||
|
||||
AudioSwitch &AudioSwitch::operator=(const AudioSwitch &other)
|
||||
{
|
||||
AudioSwitch t(other);
|
||||
swap(*this, t);
|
||||
return *this = AudioSwitch(other);
|
||||
}
|
||||
|
||||
@@ -349,23 +302,27 @@ AudioSwitch &AudioSwitch::operator=(AudioSwitch &&other) noexcept
|
||||
if (this == &other) {
|
||||
return *this;
|
||||
}
|
||||
obs_volmeter_destroy(volmeter);
|
||||
volmeter = other.volmeter;
|
||||
|
||||
swap(*this, other);
|
||||
|
||||
obs_volmeter_remove_callback(other.volmeter, setVolumeLevel, this);
|
||||
obs_volmeter_destroy(other.volmeter);
|
||||
other.volmeter = nullptr;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
static inline QString MakeAudioSwitchName(const QString &scene,
|
||||
const QString &transition,
|
||||
const QString &audioSrouce,
|
||||
const int &volume)
|
||||
void swap(AudioSwitch &first, AudioSwitch &second)
|
||||
{
|
||||
QString switchName = QStringLiteral("When volume of ") + audioSrouce +
|
||||
QStringLiteral(" is above ") +
|
||||
QString::number(volume) +
|
||||
QStringLiteral("% switch to ") + scene +
|
||||
QStringLiteral(" using ") + transition;
|
||||
return switchName;
|
||||
std::swap(first.scene, second.scene);
|
||||
std::swap(first.transition, second.transition);
|
||||
std::swap(first.usePreviousScene, second.usePreviousScene);
|
||||
std::swap(first.audioSource, second.audioSource);
|
||||
std::swap(first.volumeThreshold, second.volumeThreshold);
|
||||
std::swap(first.peak, second.peak);
|
||||
std::swap(first.volmeter, second.volmeter);
|
||||
first.resetVolmeter();
|
||||
second.resetVolmeter();
|
||||
}
|
||||
|
||||
AudioSwitchWidget::AudioSwitchWidget(AudioSwitch *s)
|
||||
@@ -448,7 +405,6 @@ AudioSwitchWidget::AudioSwitchWidget(AudioSwitch *s)
|
||||
|
||||
void AudioSwitchWidget::SceneChanged(const QString &text)
|
||||
{
|
||||
// WRONG SIGNAL!
|
||||
if (loading || !switchData)
|
||||
return;
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
@@ -475,9 +431,9 @@ void AudioSwitchWidget::UpdateVolmeterSource()
|
||||
volMeter->GetSlider()->setValue(switchData->volumeThreshold);
|
||||
}
|
||||
|
||||
AudioSwitch &AudioSwitchWidget::getSwitchData()
|
||||
AudioSwitch *AudioSwitchWidget::getSwitchData()
|
||||
{
|
||||
return *switchData;
|
||||
return switchData;
|
||||
}
|
||||
|
||||
void AudioSwitchWidget::TransitionChanged(const QString &text)
|
||||
|
||||
Reference in New Issue
Block a user