mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-08-30 05:06:14 -05:00
Compare commits
1 Commits
play-mono
...
audio-trac
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
28d7bfc32e |
@@ -342,7 +342,9 @@ AdvSceneSwitcher.condition.audio.type.volume="Configured volume level"
|
||||
AdvSceneSwitcher.condition.audio.type.syncOffset="Sync offset"
|
||||
AdvSceneSwitcher.condition.audio.type.monitor="Audio monitoring"
|
||||
AdvSceneSwitcher.condition.audio.type.balance="Audio balance"
|
||||
AdvSceneSwitcher.condition.audio.type.track="Audio track"
|
||||
AdvSceneSwitcher.condition.audio.entry="{{checkType}}of{{audioSources}}is{{condition}}{{volume}}{{volumeDB}}{{percentDBToggle}}{{syncOffset}}{{monitorTypes}}"
|
||||
AdvSceneSwitcher.condition.audio.layout.track="{{audioSources}}is enabled on{{checkType}}{{track}}"
|
||||
AdvSceneSwitcher.condition.cursor="Cursor"
|
||||
AdvSceneSwitcher.condition.cursor.type.region="is in region"
|
||||
AdvSceneSwitcher.condition.cursor.type.moving="is moving"
|
||||
@@ -973,7 +975,6 @@ AdvSceneSwitcher.action.playAudio.monitorUnavailable="Audio monitoring not avail
|
||||
AdvSceneSwitcher.action.playAudio.tracks="Tracks"
|
||||
AdvSceneSwitcher.action.playAudio.layout.startOffset="{{useStartOffset}}Start at{{startOffset}}"
|
||||
AdvSceneSwitcher.action.playAudio.layout.playbackDuration="{{useDuration}}Play for{{playbackDuration}}(0 = until end)"
|
||||
AdvSceneSwitcher.action.playAudio.mono="Mono"
|
||||
AdvSceneSwitcher.action.recording="Recording"
|
||||
AdvSceneSwitcher.action.recording.type.stop="Stop recording"
|
||||
AdvSceneSwitcher.action.recording.type.start="Start recording"
|
||||
@@ -2365,6 +2366,7 @@ AdvSceneSwitcher.tempVar.audio.muted="Source muted"
|
||||
AdvSceneSwitcher.tempVar.audio.sync_offset="Source audio sync offset"
|
||||
AdvSceneSwitcher.tempVar.audio.monitor="Source audio monitor type"
|
||||
AdvSceneSwitcher.tempVar.audio.balance="Source audio balance"
|
||||
AdvSceneSwitcher.tempVar.audio.trackEnabled="Audio track enabled"
|
||||
|
||||
AdvSceneSwitcher.tempVar.clipboard.mimeType.primary="Primary clipboard item MIME type"
|
||||
AdvSceneSwitcher.tempVar.clipboard.mimeType.primary.description="Highest priority MIME type of the current item stored in clipboard, if available."
|
||||
|
||||
@@ -2,64 +2,18 @@
|
||||
#include "audio-helpers.hpp"
|
||||
#include "layout-helpers.hpp"
|
||||
#include "macro-helpers.hpp"
|
||||
#include "plugin-state-helpers.hpp"
|
||||
#include "sync-helpers.hpp"
|
||||
|
||||
#include <obs-frontend-api.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
#include <QFileInfo>
|
||||
#include <QLabel>
|
||||
|
||||
namespace advss {
|
||||
|
||||
// Use a high output channel index that is unlikely to be claimed by OBS or
|
||||
// other plugins. OBS supports channels 0-63; channel 0 is the main scene.
|
||||
static constexpr uint32_t kPlaybackOutputChannel = 63;
|
||||
|
||||
// Tracks rawSource handles held by background cleanup threads so they can be
|
||||
// stopped early when OBS begins shutdown, before audio is freed.
|
||||
static std::mutex g_activeSourcesMutex;
|
||||
static std::set<obs_source_t *> g_activeSources;
|
||||
|
||||
static void registerActiveSource(obs_source_t *source)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_activeSourcesMutex);
|
||||
g_activeSources.insert(source);
|
||||
}
|
||||
|
||||
static void unregisterActiveSource(obs_source_t *source)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_activeSourcesMutex);
|
||||
g_activeSources.erase(source);
|
||||
}
|
||||
|
||||
static void stopAllActiveSources()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_activeSourcesMutex);
|
||||
for (auto *source : g_activeSources) {
|
||||
obs_source_media_stop(source);
|
||||
}
|
||||
}
|
||||
|
||||
static void handleObsEvent(enum obs_frontend_event event, void *)
|
||||
{
|
||||
if (event == OBS_FRONTEND_EVENT_SCRIPTING_SHUTDOWN ||
|
||||
event == OBS_FRONTEND_EVENT_EXIT) {
|
||||
stopAllActiveSources();
|
||||
}
|
||||
}
|
||||
|
||||
static bool setup()
|
||||
{
|
||||
AddPluginPostLoadStep([]() {
|
||||
obs_frontend_add_event_callback(handleObsEvent, nullptr);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool setupDone = setup();
|
||||
|
||||
const std::string MacroActionPlayAudio::id = "play_audio";
|
||||
|
||||
bool MacroActionPlayAudio::_registered = MacroActionFactory::Register(
|
||||
@@ -69,7 +23,6 @@ bool MacroActionPlayAudio::_registered = MacroActionFactory::Register(
|
||||
|
||||
static void deactivatePlayback(obs_source_t *source, bool wantsOutput)
|
||||
{
|
||||
obs_source_media_stop(source);
|
||||
if (wantsOutput) {
|
||||
obs_set_output_source(kPlaybackOutputChannel, nullptr);
|
||||
} else {
|
||||
@@ -85,7 +38,8 @@ static void waitForPlaybackToEnd(Macro *macro, obs_source_t *source,
|
||||
std::unique_lock<std::mutex> lock(*GetMutex());
|
||||
SetMacroAbortWait(false);
|
||||
|
||||
// Poll until the source starts playing or the macro is stopped.
|
||||
// The media source needs time to open and decode before reaching
|
||||
// PLAYING state. Poll until it starts (or the macro is stopped).
|
||||
while (!MacroWaitShouldAbort() && !MacroIsStopped(macro)) {
|
||||
if (obs_source_media_get_state(source) ==
|
||||
OBS_MEDIA_STATE_PLAYING) {
|
||||
@@ -94,8 +48,9 @@ static void waitForPlaybackToEnd(Macro *macro, obs_source_t *source,
|
||||
GetMacroWaitCV().wait_for(lock, 10ms);
|
||||
}
|
||||
|
||||
// Wait for playback to end. Two consecutive non-playing samples are
|
||||
// required to avoid false positives on brief state transitions.
|
||||
// Now wait for playback to end. Require two consecutive non-playing
|
||||
// samples to avoid false positives on brief state transitions.
|
||||
// If maxMs > 0, also stop once that many milliseconds have elapsed.
|
||||
const auto playbackStart = std::chrono::steady_clock::now();
|
||||
static const int kStopThreshold = 2;
|
||||
int stoppedCount = 0;
|
||||
@@ -140,6 +95,7 @@ bool MacroActionPlayAudio::PerformAction()
|
||||
obs_data_set_string(settings, "local_file", path.c_str());
|
||||
obs_data_set_bool(settings, "is_local_file", true);
|
||||
obs_data_set_bool(settings, "looping", false);
|
||||
// Disable automatic restart on activate so we control start explicitly.
|
||||
obs_data_set_bool(settings, "restart_on_activate", false);
|
||||
obs_data_set_bool(settings, "close_when_inactive", true);
|
||||
|
||||
@@ -157,11 +113,10 @@ bool MacroActionPlayAudio::PerformAction()
|
||||
DecibelToPercent(static_cast<float>(_volumeDB.GetValue()));
|
||||
obs_source_set_volume(source, vol);
|
||||
obs_source_set_monitoring_type(source, _monitorType);
|
||||
if (_mono) {
|
||||
obs_source_set_flags(source, OBS_SOURCE_FLAG_FORCE_MONO);
|
||||
}
|
||||
|
||||
// Fall back to monitor-only if all output tracks are deselected.
|
||||
// Fall back to monitor-only if all output tracks are deselected —
|
||||
// there is no point routing through the output channel if the mixer
|
||||
// mask would silence every track.
|
||||
const bool wantsOutput =
|
||||
(_monitorType != OBS_MONITORING_TYPE_MONITOR_ONLY) &&
|
||||
(_audioMixers != 0);
|
||||
@@ -173,8 +128,10 @@ bool MacroActionPlayAudio::PerformAction()
|
||||
|
||||
if (wantsOutput) {
|
||||
obs_source_set_audio_mixers(source, _audioMixers);
|
||||
// Route through a private scene positioned off-screen so the
|
||||
// audio mixes into the output without video appearing on screen.
|
||||
// Route through a private scene so we can position the scene
|
||||
// item far off-screen. This keeps the item "visible" (so audio
|
||||
// is still mixed) while ensuring its video never intersects the
|
||||
// output frame.
|
||||
OBSSceneAutoRelease audioScene =
|
||||
obs_scene_create_private("advss_audio_scene");
|
||||
obs_sceneitem_t *item = obs_scene_add(audioScene, source);
|
||||
@@ -184,7 +141,8 @@ bool MacroActionPlayAudio::PerformAction()
|
||||
}
|
||||
obs_set_output_source(kPlaybackOutputChannel,
|
||||
obs_scene_get_source(audioScene));
|
||||
// audioScene is released here; the output channel keeps the scene alive.
|
||||
// audioScene released here; the output channel holds the
|
||||
// remaining reference and keeps the scene alive.
|
||||
} else {
|
||||
obs_source_set_audio_mixers(source, 0);
|
||||
obs_source_inc_active(source);
|
||||
@@ -209,15 +167,15 @@ bool MacroActionPlayAudio::PerformAction()
|
||||
return true;
|
||||
}
|
||||
|
||||
// Keep the source alive until playback ends via a background thread.
|
||||
// Keep the source alive in a background thread that cleans up
|
||||
// once playback finishes. Grab an extra strong reference so the
|
||||
// source survives beyond this stack frame.
|
||||
auto rawSource = obs_source_get_ref(source);
|
||||
registerActiveSource(rawSource);
|
||||
auto macro = GetMacro();
|
||||
|
||||
std::thread cleanupThread([rawSource, wantsOutput, macro, maxMs]() {
|
||||
waitForPlaybackToEnd(macro, rawSource, maxMs);
|
||||
deactivatePlayback(rawSource, wantsOutput);
|
||||
unregisterActiveSource(rawSource);
|
||||
obs_source_release(rawSource);
|
||||
});
|
||||
AddMacroHelperThread(macro, std::move(cleanupThread));
|
||||
@@ -246,7 +204,6 @@ bool MacroActionPlayAudio::Save(obs_data_t *obj) const
|
||||
obs_data_set_bool(obj, "useDuration", _useDuration);
|
||||
_playbackDuration.Save(obj, "playbackDuration");
|
||||
obs_data_set_bool(obj, "waitForCompletion", _waitForCompletion);
|
||||
obs_data_set_bool(obj, "mono", _mono);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -264,7 +221,6 @@ bool MacroActionPlayAudio::Load(obs_data_t *obj)
|
||||
_useDuration = obs_data_get_bool(obj, "useDuration");
|
||||
_playbackDuration.Load(obj, "playbackDuration");
|
||||
_waitForCompletion = obs_data_get_bool(obj, "waitForCompletion");
|
||||
_mono = obs_data_get_bool(obj, "mono");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -306,9 +262,7 @@ MacroActionPlayAudioEdit::MacroActionPlayAudioEdit(
|
||||
_useDuration(new QCheckBox(this)),
|
||||
_playbackDuration(new DurationSelection(this, true, 0.0)),
|
||||
_waitForCompletion(new QCheckBox(
|
||||
obs_module_text("AdvSceneSwitcher.action.playAudio.wait"))),
|
||||
_mono(new QCheckBox(
|
||||
obs_module_text("AdvSceneSwitcher.action.playAudio.mono")))
|
||||
obs_module_text("AdvSceneSwitcher.action.playAudio.wait")))
|
||||
{
|
||||
_volumeDB->setMinimum(-100.0);
|
||||
_volumeDB->setMaximum(0.0);
|
||||
@@ -349,8 +303,6 @@ MacroActionPlayAudioEdit::MacroActionPlayAudioEdit(
|
||||
SLOT(PlaybackDurationChanged(const Duration &)));
|
||||
QWidget::connect(_waitForCompletion, SIGNAL(stateChanged(int)), this,
|
||||
SLOT(WaitChanged(int)));
|
||||
QWidget::connect(_mono, SIGNAL(stateChanged(int)), this,
|
||||
SLOT(MonoChanged(int)));
|
||||
|
||||
auto tracksLayout = new QHBoxLayout;
|
||||
tracksLayout->setContentsMargins(0, 0, 0, 0);
|
||||
@@ -394,7 +346,6 @@ MacroActionPlayAudioEdit::MacroActionPlayAudioEdit(
|
||||
mainLayout->addLayout(startOffsetLayout);
|
||||
mainLayout->addLayout(playbackDurationLayout);
|
||||
mainLayout->addWidget(_waitForCompletion);
|
||||
mainLayout->addWidget(_mono);
|
||||
setLayout(mainLayout);
|
||||
|
||||
_entryData = entryData;
|
||||
@@ -424,7 +375,6 @@ void MacroActionPlayAudioEdit::UpdateEntryData()
|
||||
_playbackDuration->SetDuration(_entryData->_playbackDuration);
|
||||
_playbackDuration->setEnabled(_entryData->_useDuration);
|
||||
_waitForCompletion->setChecked(_entryData->_waitForCompletion);
|
||||
_mono->setChecked(_entryData->_mono);
|
||||
}
|
||||
|
||||
void MacroActionPlayAudioEdit::FilePathChanged(const QString &path)
|
||||
@@ -493,10 +443,4 @@ void MacroActionPlayAudioEdit::WaitChanged(int value)
|
||||
_entryData->_waitForCompletion = value;
|
||||
}
|
||||
|
||||
void MacroActionPlayAudioEdit::MonoChanged(int value)
|
||||
{
|
||||
GUARD_LOADING_AND_LOCK();
|
||||
_entryData->_mono = value;
|
||||
}
|
||||
|
||||
} // namespace advss
|
||||
|
||||
@@ -37,7 +37,6 @@ public:
|
||||
bool _useDuration = false;
|
||||
Duration _playbackDuration;
|
||||
bool _waitForCompletion = false;
|
||||
bool _mono = false;
|
||||
|
||||
static bool _registered;
|
||||
static const std::string id;
|
||||
@@ -69,7 +68,6 @@ private slots:
|
||||
void UseDurationChanged(int);
|
||||
void PlaybackDurationChanged(const Duration &);
|
||||
void WaitChanged(int value);
|
||||
void MonoChanged(int value);
|
||||
|
||||
signals:
|
||||
void HeaderInfoChanged(const QString &);
|
||||
@@ -85,7 +83,6 @@ private:
|
||||
QCheckBox *_useDuration;
|
||||
DurationSelection *_playbackDuration;
|
||||
QCheckBox *_waitForCompletion;
|
||||
QCheckBox *_mono;
|
||||
|
||||
std::shared_ptr<MacroActionPlayAudio> _entryData;
|
||||
bool _loading = true;
|
||||
|
||||
@@ -25,6 +25,8 @@ const static std::map<MacroConditionAudio::Type, std::string> checkTypes = {
|
||||
"AdvSceneSwitcher.condition.audio.type.monitor"},
|
||||
{MacroConditionAudio::Type::BALANCE,
|
||||
"AdvSceneSwitcher.condition.audio.type.balance"},
|
||||
{MacroConditionAudio::Type::TRACK,
|
||||
"AdvSceneSwitcher.condition.audio.type.track"},
|
||||
};
|
||||
|
||||
const static std::map<MacroConditionAudio::OutputCondition, std::string>
|
||||
@@ -245,6 +247,20 @@ bool MacroConditionAudio::CheckBalance()
|
||||
return ret && source;
|
||||
}
|
||||
|
||||
bool MacroConditionAudio::CheckTrack()
|
||||
{
|
||||
if (!_audioSource.GetSource()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
OBSSourceAutoRelease source =
|
||||
obs_weak_source_get_source(_audioSource.GetSource());
|
||||
uint32_t mixers = obs_source_get_audio_mixers(source);
|
||||
bool enabled = (mixers >> (uint32_t)(_track - 1)) & 1u;
|
||||
SetTempVarValue("track_enabled", enabled ? "true" : "false");
|
||||
return enabled && source;
|
||||
}
|
||||
|
||||
bool MacroConditionAudio::CheckCondition()
|
||||
{
|
||||
bool ret = false;
|
||||
@@ -264,6 +280,9 @@ bool MacroConditionAudio::CheckCondition()
|
||||
case Type::BALANCE:
|
||||
ret = CheckBalance();
|
||||
break;
|
||||
case Type::TRACK:
|
||||
ret = CheckTrack();
|
||||
break;
|
||||
}
|
||||
|
||||
if (GetVariableValue().empty()) {
|
||||
@@ -281,6 +300,7 @@ bool MacroConditionAudio::Save(obs_data_t *obj) const
|
||||
_volumePercent.Save(obj, "volume");
|
||||
_syncOffset.Save(obj, "syncOffset");
|
||||
_balance.Save(obj, "balance");
|
||||
_track.Save(obj, "track");
|
||||
obs_data_set_int(obj, "checkType", static_cast<int>(_checkType));
|
||||
obs_data_set_int(obj, "outputCondition",
|
||||
static_cast<int>(_outputCondition));
|
||||
@@ -346,6 +366,7 @@ bool MacroConditionAudio::Load(obs_data_t *obj)
|
||||
_useDb = obs_data_get_bool(obj, "useDb");
|
||||
_volumeDB.Load(obj, "volumeDB");
|
||||
}
|
||||
_track.Load(obj, "track");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -421,6 +442,12 @@ void MacroConditionAudio::SetupTempVars()
|
||||
obs_module_text(
|
||||
"AdvSceneSwitcher.tempVar.audio.balance"));
|
||||
break;
|
||||
case Type::TRACK:
|
||||
AddTempvar(
|
||||
"track_enabled",
|
||||
obs_module_text(
|
||||
"AdvSceneSwitcher.tempVar.audio.trackEnabled"));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -468,6 +495,7 @@ static QStringList getAudioSourcesList()
|
||||
MacroConditionAudioEdit::MacroConditionAudioEdit(
|
||||
QWidget *parent, std::shared_ptr<MacroConditionAudio> entryData)
|
||||
: QWidget(parent),
|
||||
_layout(new QHBoxLayout),
|
||||
_checkTypes(new QComboBox()),
|
||||
_sources(new SourceSelectionWidget(this, getAudioSourcesList, true)),
|
||||
_condition(new QComboBox()),
|
||||
@@ -476,7 +504,8 @@ MacroConditionAudioEdit::MacroConditionAudioEdit(
|
||||
_percentDBToggle(new QPushButton),
|
||||
_syncOffset(new VariableSpinBox()),
|
||||
_monitorTypes(new QComboBox),
|
||||
_balance(new SliderSpinBox(0., 1., ""))
|
||||
_balance(new SliderSpinBox(0., 1., "")),
|
||||
_track(new VariableSpinBox())
|
||||
{
|
||||
_volumePercent->setSuffix("%");
|
||||
_volumePercent->setMaximum(100);
|
||||
@@ -491,6 +520,9 @@ MacroConditionAudioEdit::MacroConditionAudioEdit(
|
||||
_syncOffset->setMaximum(20000);
|
||||
_syncOffset->setSuffix("ms");
|
||||
|
||||
_track->setMinimum(1);
|
||||
_track->setMaximum(32);
|
||||
|
||||
QWidget::connect(_checkTypes, SIGNAL(currentIndexChanged(int)), this,
|
||||
SLOT(CheckTypeChanged(int)));
|
||||
QWidget::connect(
|
||||
@@ -519,27 +551,16 @@ MacroConditionAudioEdit::MacroConditionAudioEdit(
|
||||
this, SLOT(VolumeDBChanged(const NumberVariable<double> &)));
|
||||
QWidget::connect(_percentDBToggle, SIGNAL(clicked()), this,
|
||||
SLOT(PercentDBClicked()));
|
||||
QWidget::connect(
|
||||
_track,
|
||||
SIGNAL(NumberVariableChanged(const NumberVariable<int> &)),
|
||||
this, SLOT(TrackChanged(const NumberVariable<int> &)));
|
||||
|
||||
populateCheckTypes(_checkTypes);
|
||||
PopulateMonitorTypeSelection(_monitorTypes);
|
||||
|
||||
QHBoxLayout *switchLayout = new QHBoxLayout;
|
||||
std::unordered_map<std::string, QWidget *> widgetPlaceholders = {
|
||||
{"{{checkType}}", _checkTypes},
|
||||
{"{{audioSources}}", _sources},
|
||||
{"{{volume}}", _volumePercent},
|
||||
{"{{syncOffset}}", _syncOffset},
|
||||
{"{{monitorTypes}}", _monitorTypes},
|
||||
{"{{balance}}", _balance},
|
||||
{"{{condition}}", _condition},
|
||||
{"{{volumeDB}}", _volumeDB},
|
||||
{"{{percentDBToggle}}", _percentDBToggle},
|
||||
};
|
||||
PlaceWidgets(obs_module_text("AdvSceneSwitcher.condition.audio.entry"),
|
||||
switchLayout, widgetPlaceholders);
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||
mainLayout->addLayout(switchLayout);
|
||||
mainLayout->addLayout(_layout);
|
||||
mainLayout->addWidget(_balance);
|
||||
setLayout(mainLayout);
|
||||
|
||||
@@ -608,6 +629,12 @@ void MacroConditionAudioEdit::BalanceChanged(const NumberVariable<double> &value
|
||||
_entryData->_balance = value;
|
||||
}
|
||||
|
||||
void MacroConditionAudioEdit::TrackChanged(const NumberVariable<int> &value)
|
||||
{
|
||||
GUARD_LOADING_AND_LOCK();
|
||||
_entryData->_track = value;
|
||||
}
|
||||
|
||||
void MacroConditionAudioEdit::VolumeDBChanged(
|
||||
const NumberVariable<double> &value)
|
||||
{
|
||||
@@ -692,6 +719,8 @@ void MacroConditionAudioEdit::CheckTypeChanged(int idx)
|
||||
} else if (_entryData->GetType() ==
|
||||
MacroConditionAudio::Type::CONFIGURED_VOLUME) {
|
||||
populateVolumeConditionSelection(_condition);
|
||||
} else if (_entryData->GetType() == MacroConditionAudio::Type::TRACK) {
|
||||
_condition->clear();
|
||||
}
|
||||
SetWidgetVisibility();
|
||||
}
|
||||
@@ -708,6 +737,7 @@ void MacroConditionAudioEdit::UpdateEntryData()
|
||||
_syncOffset->SetValue(_entryData->_syncOffset);
|
||||
_monitorTypes->setCurrentIndex(_entryData->_monitorType);
|
||||
_balance->SetDoubleValue(_entryData->_balance);
|
||||
_track->SetValue(_entryData->_track);
|
||||
_checkTypes->setCurrentIndex(
|
||||
_checkTypes->findData(static_cast<int>(_entryData->GetType())));
|
||||
|
||||
@@ -748,26 +778,63 @@ void MacroConditionAudioEdit::SetWidgetVisibility()
|
||||
return;
|
||||
}
|
||||
|
||||
_layout->removeWidget(_checkTypes);
|
||||
_layout->removeWidget(_sources);
|
||||
_layout->removeWidget(_condition);
|
||||
_layout->removeWidget(_volumePercent);
|
||||
_layout->removeWidget(_volumeDB);
|
||||
_layout->removeWidget(_percentDBToggle);
|
||||
_layout->removeWidget(_syncOffset);
|
||||
_layout->removeWidget(_monitorTypes);
|
||||
_layout->removeWidget(_track);
|
||||
ClearLayout(_layout);
|
||||
|
||||
const std::unordered_map<std::string, QWidget *> placeholders = {
|
||||
{"{{checkType}}", _checkTypes},
|
||||
{"{{audioSources}}", _sources},
|
||||
{"{{condition}}", _condition},
|
||||
{"{{volume}}", _volumePercent},
|
||||
{"{{volumeDB}}", _volumeDB},
|
||||
{"{{percentDBToggle}}", _percentDBToggle},
|
||||
{"{{syncOffset}}", _syncOffset},
|
||||
{"{{monitorTypes}}", _monitorTypes},
|
||||
{"{{track}}", _track},
|
||||
};
|
||||
|
||||
const bool isTrack = _entryData->GetType() ==
|
||||
MacroConditionAudio::Type::TRACK;
|
||||
PlaceWidgets(
|
||||
obs_module_text(
|
||||
isTrack ? "AdvSceneSwitcher.condition.audio.layout.track"
|
||||
: "AdvSceneSwitcher.condition.audio.entry"),
|
||||
_layout, placeholders);
|
||||
|
||||
_condition->setVisible(
|
||||
_entryData->GetType() ==
|
||||
MacroConditionAudio::Type::OUTPUT_VOLUME ||
|
||||
_entryData->GetType() ==
|
||||
MacroConditionAudio::Type::CONFIGURED_VOLUME ||
|
||||
_entryData->GetType() == MacroConditionAudio::Type::BALANCE ||
|
||||
_entryData->GetType() ==
|
||||
MacroConditionAudio::Type::SYNC_OFFSET);
|
||||
_syncOffset->setVisible(_entryData->GetType() ==
|
||||
MacroConditionAudio::Type::SYNC_OFFSET);
|
||||
_monitorTypes->setVisible(_entryData->GetType() ==
|
||||
MacroConditionAudio::Type::MONITOR);
|
||||
!isTrack &&
|
||||
(_entryData->GetType() ==
|
||||
MacroConditionAudio::Type::OUTPUT_VOLUME ||
|
||||
_entryData->GetType() ==
|
||||
MacroConditionAudio::Type::CONFIGURED_VOLUME ||
|
||||
_entryData->GetType() == MacroConditionAudio::Type::BALANCE ||
|
||||
_entryData->GetType() ==
|
||||
MacroConditionAudio::Type::SYNC_OFFSET));
|
||||
_syncOffset->setVisible(!isTrack &&
|
||||
_entryData->GetType() ==
|
||||
MacroConditionAudio::Type::SYNC_OFFSET);
|
||||
_monitorTypes->setVisible(!isTrack &&
|
||||
_entryData->GetType() ==
|
||||
MacroConditionAudio::Type::MONITOR);
|
||||
_track->setVisible(isTrack);
|
||||
_volumePercent->setVisible(!isTrack && HasVolumeControl() &&
|
||||
!_entryData->_useDb);
|
||||
_volumeDB->setVisible(!isTrack && HasVolumeControl() &&
|
||||
_entryData->_useDb);
|
||||
_percentDBToggle->setText(_entryData->_useDb ? "dB" : "%");
|
||||
_percentDBToggle->setVisible(!isTrack && HasVolumeControl());
|
||||
_balance->setVisible(_entryData->GetType() ==
|
||||
MacroConditionAudio::Type::BALANCE);
|
||||
_volMeter->setVisible(_entryData->GetType() ==
|
||||
MacroConditionAudio::Type::OUTPUT_VOLUME);
|
||||
_volumePercent->setVisible(HasVolumeControl() && !_entryData->_useDb);
|
||||
_volumeDB->setVisible(HasVolumeControl() && _entryData->_useDb);
|
||||
_percentDBToggle->setText(_entryData->_useDb ? "dB" : "%");
|
||||
_percentDBToggle->setVisible(HasVolumeControl());
|
||||
adjustSize();
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "source-selection.hpp"
|
||||
|
||||
#include <limits>
|
||||
#include <QHBoxLayout>
|
||||
#include <QWidget>
|
||||
#include <QComboBox>
|
||||
#include <chrono>
|
||||
@@ -36,6 +37,7 @@ public:
|
||||
SYNC_OFFSET,
|
||||
MONITOR,
|
||||
BALANCE,
|
||||
TRACK,
|
||||
};
|
||||
void SetType(const Type &);
|
||||
Type GetType() const { return _checkType; }
|
||||
@@ -60,6 +62,7 @@ public:
|
||||
IntVariable _syncOffset = 0;
|
||||
obs_monitoring_type _monitorType = OBS_MONITORING_TYPE_NONE;
|
||||
DoubleVariable _balance = 0.5;
|
||||
IntVariable _track = 1;
|
||||
OutputCondition _outputCondition = OutputCondition::ABOVE;
|
||||
VolumeCondition _volumeCondition = VolumeCondition::ABOVE;
|
||||
obs_volmeter_t *_volmeter = nullptr;
|
||||
@@ -70,6 +73,7 @@ private:
|
||||
bool CheckSyncOffset();
|
||||
bool CheckMonitor();
|
||||
bool CheckBalance();
|
||||
bool CheckTrack();
|
||||
void SetupTempVars();
|
||||
float GetVolumePeak();
|
||||
|
||||
@@ -111,6 +115,7 @@ private slots:
|
||||
void VolumeDBChanged(const NumberVariable<double> &value);
|
||||
void PercentDBClicked();
|
||||
void SyncSliderAndValueSelection(bool sliderMoved);
|
||||
void TrackChanged(const NumberVariable<int> &value);
|
||||
|
||||
signals:
|
||||
void HeaderInfoChanged(const QString &);
|
||||
@@ -119,6 +124,7 @@ private:
|
||||
void SetWidgetVisibility();
|
||||
bool HasVolumeControl() const;
|
||||
|
||||
QHBoxLayout *_layout;
|
||||
QComboBox *_checkTypes;
|
||||
SourceSelectionWidget *_sources;
|
||||
QComboBox *_condition;
|
||||
@@ -128,6 +134,7 @@ private:
|
||||
VariableSpinBox *_syncOffset;
|
||||
QComboBox *_monitorTypes;
|
||||
SliderSpinBox *_balance;
|
||||
VariableSpinBox *_track;
|
||||
VolControl *_volMeter = nullptr;
|
||||
|
||||
std::shared_ptr<MacroConditionAudio> _entryData;
|
||||
|
||||
Reference in New Issue
Block a user