Compare commits

..

1 Commits

Author SHA1 Message Date
WarmUpTill
81c069f87e Convert dock window name field into a combo box
Should make it easier to combine docks into a single dock window without
having to know the exact dock window titles beforehand
2026-09-08 22:46:34 +02:00
9 changed files with 36 additions and 136 deletions

View File

@@ -383,18 +383,8 @@ target_precompile_headers(${LIB_NAME} PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/lib/pch.hpp")
target_include_directories(
${LIB_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/deps/obs-websocket/lib")
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/deps/exprtk/exprtk.hpp")
target_include_directories(${LIB_NAME}
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/deps/exprtk")
target_compile_definitions(${LIB_NAME} PRIVATE EXPRTK_SUPPORT=1)
else()
message(
STATUS
"${PROJECT_NAME}: deps/exprtk not found - math expression support disabled"
)
endif()
${LIB_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/deps/obs-websocket/lib"
"${CMAKE_CURRENT_SOURCE_DIR}/deps/exprtk")
if(NOT nlohmann_json_DIR
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/deps/json/CMakeLists.txt")

View File

@@ -986,7 +986,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"

View File

@@ -2,16 +2,13 @@
#include "obs-module-helper.hpp"
#include <climits>
#ifdef EXPRTK_SUPPORT
#include <exprtk.hpp>
#include <random>
#endif
namespace advss {
std::variant<double, std::string> EvalMathExpression(const std::string &expr)
{
#ifdef EXPRTK_SUPPORT
static auto randomFunc = []() {
thread_local std::mt19937 gen(std::random_device{}());
thread_local std::uniform_real_distribution<double> dis(0.0,
@@ -29,7 +26,6 @@ std::variant<double, std::string> EvalMathExpression(const std::string &expr)
if (parser.compile(expr, expression)) {
return expression.value();
}
#endif
return std::string(obs_module_text(
"AdvSceneSwitcher.math.expressionFail")) +
" \"" + expr + "\"";

View File

@@ -127,10 +127,9 @@ void RegisterWebsocketRequest(
void SendWebsocketVendorEvent(const std::string &eventName, obs_data_t *data)
{
if (OBSIsShuttingDown() || !obs_get_module("obs-websocket")) {
if (OBSIsShuttingDown()) {
return;
}
obs_websocket_vendor_emit_event(vendor, eventName.c_str(), data);
}

View File

@@ -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

View File

@@ -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;

View File

@@ -233,12 +233,7 @@ void TwitchToken::Load(obs_data_t *obj)
{
Item::Load(obj);
_token = obs_data_get_string(obj, "token");
if (obs_data_has_user_value(obj, "userID") &&
*obs_data_get_string(obj, "userID") != '\0') {
_userID = obs_data_get_string(obj, "userID");
} else {
_userID = {};
}
_userID = obs_data_get_string(obj, "userID");
obs_data_set_default_bool(obj, "validateEventSubTimestamps", true);
_validateEventSubTimestamps =
obs_data_get_bool(obj, "validateEventSubTimestamps");
@@ -260,7 +255,7 @@ void TwitchToken::Save(obs_data_t *obj) const
{
Item::Save(obj);
obs_data_set_string(obj, "token", _token.c_str());
if (_userID && !_userID->empty()) {
if (_userID) {
obs_data_set_string(obj, "userID", _userID->c_str());
}
obs_data_set_bool(obj, "validateEventSubTimestamps",
@@ -315,7 +310,7 @@ bool TwitchToken::AnyOptionIsEnabled(
return false;
}
bool TwitchToken::SetToken(const std::string &value)
void TwitchToken::SetToken(const std::string &value)
{
_token = value;
auto res =
@@ -323,34 +318,21 @@ bool TwitchToken::SetToken(const std::string &value)
if (res.status != 200) {
blog(LOG_WARNING, "failed to get Twitch user id from token!");
_userID = {};
return false;
return;
}
bool gotUserID = false;
OBSDataArrayAutoRelease array = obs_data_get_array(res.data, "data");
size_t count = obs_data_array_count(array);
for (size_t i = 0; i < count; i++) {
OBSDataAutoRelease arrayObj = obs_data_array_item(array, i);
std::string id = obs_data_get_string(arrayObj, "id");
if (id.empty()) {
blog(LOG_WARNING,
"Twitch /helix/users response did not contain a user id!");
continue;
}
_userID = id;
_userID = obs_data_get_string(arrayObj, "id");
_name = obs_data_get_string(arrayObj, "display_name");
gotUserID = true;
}
if (!gotUserID) {
return false;
}
// Trigger resubscribes with new token
if (_eventSub) {
_eventSub->ClearActiveSubscriptions();
}
return true;
}
std::optional<std::string> TwitchToken::GetToken() const
@@ -406,7 +388,7 @@ bool TwitchToken::IsValid(bool forceUpdate) const
return false;
}
if (_userID && !_userID->empty() && _userID != id) {
if (_userID && _userID != id) {
blog(LOG_INFO,
"Twitch token %s does not match expected user (got %s, expected %s)!",
_name.c_str(), id, _userID->c_str());
@@ -414,10 +396,6 @@ bool TwitchToken::IsValid(bool forceUpdate) const
return false;
}
if (!_userID || _userID->empty()) {
_userID = id;
}
_lastValidityCheckResult = true;
return true;
};
@@ -841,9 +819,9 @@ void TwitchTokenSettingsDialog::GotToken(const std::optional<QString> &value)
return;
}
bool success = _currentToken.SetToken(value.value().toStdString());
_currentToken.SetToken(value.value().toStdString());
auto name = QString::fromStdString(_currentToken._name);
if (!success || name.isEmpty()) {
if (name.isEmpty()) {
_tokenStatus->setText(obs_module_text(
"AdvSceneSwitcher.twitchToken.request.fail"));
_name->setText("");

View File

@@ -48,7 +48,7 @@ public:
bool OptionIsActive(const TokenOption &option) const;
bool OptionIsEnabled(const TokenOption &option) const;
bool AnyOptionIsEnabled(const std::vector<TokenOption> &options) const;
bool SetToken(const std::string &);
void SetToken(const std::string &);
bool IsEmpty() const { return _token.empty(); }
std::optional<std::string> GetToken() const;
std::optional<std::string> GetUserID() const { return _userID; }
@@ -65,7 +65,7 @@ private:
mutable std::string _lastValidityCheckValue;
mutable bool _lastValidityCheckResult = false;
mutable std::chrono::system_clock::time_point _lastValidityCheckTime;
mutable std::optional<std::string> _userID;
std::optional<std::string> _userID;
std::set<TokenOption> _tokenOptions = TokenOption::GetAllTokenOptions();
std::shared_ptr<EventSub> _eventSub;
bool _validateEventSubTimestamps = false;

View File

@@ -85,11 +85,8 @@ target_sources(
${PROJECT_NAME}
PRIVATE test-math.cpp ${ADVSS_SOURCE_DIR}/lib/utils/math-helpers.cpp
${ADVSS_SOURCE_DIR}/lib/utils/obs-module-helper.cpp)
if(EXISTS "${ADVSS_SOURCE_DIR}/deps/exprtk/exprtk.hpp")
target_include_directories(${PROJECT_NAME}
PRIVATE ${ADVSS_SOURCE_DIR}/deps/exprtk)
target_compile_definitions(${PROJECT_NAME} PRIVATE EXPRTK_SUPPORT=1)
endif()
target_include_directories(${PROJECT_NAME}
PRIVATE ${ADVSS_SOURCE_DIR}/deps/exprtk)
if(MSVC)
target_compile_options(${PROJECT_NAME} PUBLIC /MP /d2FH4- /wd4267 /bigobj)