mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-09-10 18:46:11 -05:00
Compare commits
5 Commits
dock-windo
...
mac-proc-f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fe7e020243 | ||
|
|
dede2bb8cb | ||
|
|
fdc806be40 | ||
|
|
01107ee858 | ||
|
|
be8bc4a63f |
@@ -267,6 +267,7 @@ AdvSceneSwitcher.macroTab.pauseStateSaveBehavior.unpause="Unpaused"
|
||||
AdvSceneSwitcher.macroTab.currentRegisterDock="Register dock widget to control the pause state of selected macro or run it manually"
|
||||
AdvSceneSwitcher.macroTab.currentIsStandaloneDock="Is standalone dock"
|
||||
AdvSceneSwitcher.macroTab.currentDockWindowName="Add to macro dock with name:"
|
||||
AdvSceneSwitcher.macroTab.currentDockWindowName.addNew="Add new dock..."
|
||||
AdvSceneSwitcher.macroTab.currentDockAddRunButton="Add button to run the macro"
|
||||
AdvSceneSwitcher.macroTab.currentDockAddPauseButton="Add button to pause or unpause the macro"
|
||||
AdvSceneSwitcher.macroTab.currentDockAddStatusLabel="Add status label"
|
||||
@@ -985,6 +986,7 @@ 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"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "macro-settings.hpp"
|
||||
#include "layout-helpers.hpp"
|
||||
#include "macro-helpers.hpp"
|
||||
#include "macro.hpp"
|
||||
#include "obs-module-helper.hpp"
|
||||
#include "plugin-state-helpers.hpp"
|
||||
@@ -8,11 +9,48 @@
|
||||
#include <QScrollArea>
|
||||
#include <QScrollBar>
|
||||
#include <QVBoxLayout>
|
||||
#include <set>
|
||||
|
||||
namespace advss {
|
||||
|
||||
static GlobalMacroSettings macroSettings;
|
||||
|
||||
static constexpr int addNewDockWindowRole = Qt::UserRole + 1;
|
||||
|
||||
static QStringList GetExistingDockWindowNames()
|
||||
{
|
||||
std::set<std::string> names;
|
||||
for (const auto ¯o : GetAllMacros()) {
|
||||
if (!macro) {
|
||||
continue;
|
||||
}
|
||||
const auto &dockSettings = macro->GetDockSettings();
|
||||
if (dockSettings.IsStandaloneDock()) {
|
||||
continue;
|
||||
}
|
||||
names.insert(dockSettings.DockWindowName());
|
||||
}
|
||||
|
||||
QStringList result;
|
||||
for (const auto &name : names) {
|
||||
result << QString::fromStdString(name);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static void populateDockWindowNameCombo(QComboBox *combo)
|
||||
{
|
||||
combo->clear();
|
||||
auto names = GetExistingDockWindowNames();
|
||||
combo->addItems(names);
|
||||
if (!names.isEmpty()) {
|
||||
combo->insertSeparator(combo->count());
|
||||
}
|
||||
combo->addItem(obs_module_text(
|
||||
"AdvSceneSwitcher.macroTab.currentDockWindowName.addNew"));
|
||||
combo->setItemData(combo->count() - 1, true, addNewDockWindowRole);
|
||||
}
|
||||
|
||||
void GlobalMacroSettings::Save(obs_data_t *obj) const
|
||||
{
|
||||
auto data = obs_data_create();
|
||||
@@ -96,7 +134,7 @@ MacroSettingsDialog::MacroSettingsDialog(QWidget *parent,
|
||||
"AdvSceneSwitcher.macroTab.currentRegisterDock"))),
|
||||
_currentMacroIsStandaloneDock(new QCheckBox(obs_module_text(
|
||||
"AdvSceneSwitcher.macroTab.currentIsStandaloneDock"))),
|
||||
_currentMacroDockWindowName(new QLineEdit(this)),
|
||||
_currentMacroDockWindowName(new QComboBox(this)),
|
||||
_currentMacroDockAddRunButton(new QCheckBox(obs_module_text(
|
||||
"AdvSceneSwitcher.macroTab.currentDockAddRunButton"))),
|
||||
_currentMacroDockAddPauseButton(new QCheckBox(obs_module_text(
|
||||
@@ -143,6 +181,17 @@ MacroSettingsDialog::MacroSettingsDialog(QWidget *parent,
|
||||
"AdvSceneSwitcher.macroTab.pauseStateSaveBehavior.unpause"),
|
||||
static_cast<int>(Macro::PauseStateSaveBehavior::UNPAUSE));
|
||||
|
||||
_currentMacroDockWindowName->setEditable(true);
|
||||
populateDockWindowNameCombo(_currentMacroDockWindowName);
|
||||
connect(_currentMacroDockWindowName,
|
||||
qOverload<int>(&QComboBox::activated), this, [this](int index) {
|
||||
if (_currentMacroDockWindowName
|
||||
->itemData(index, addNewDockWindowRole)
|
||||
.toBool()) {
|
||||
_currentMacroDockWindowName->setCurrentText("");
|
||||
}
|
||||
});
|
||||
|
||||
auto highlightOptions = new QGroupBox(
|
||||
obs_module_text("AdvSceneSwitcher.macroTab.highlightSettings"));
|
||||
auto highlightLayout = new QVBoxLayout;
|
||||
@@ -348,7 +397,7 @@ MacroSettingsDialog::MacroSettingsDialog(QWidget *parent,
|
||||
_currentMacroRegisterDock->setChecked(dockEnabled);
|
||||
_currentMacroIsStandaloneDock->setChecked(
|
||||
dockSettings.IsStandaloneDock());
|
||||
_currentMacroDockWindowName->setText(
|
||||
_currentMacroDockWindowName->setCurrentText(
|
||||
QString::fromStdString(dockSettings.DockWindowName()));
|
||||
_currentMacroDockAddRunButton->setChecked(dockSettings.HasRunButton());
|
||||
_currentMacroDockAddPauseButton->setChecked(
|
||||
@@ -486,7 +535,7 @@ bool MacroSettingsDialog::AskForSettings(QWidget *parent,
|
||||
dockSettings.SetIsStandaloneDock(
|
||||
dialog._currentMacroIsStandaloneDock->isChecked());
|
||||
dockSettings.SetDockWindowName(
|
||||
dialog._currentMacroDockWindowName->text().toStdString());
|
||||
dialog._currentMacroDockWindowName->currentText().toStdString());
|
||||
dockSettings.SetHasRunButton(
|
||||
dialog._currentMacroDockAddRunButton->isChecked());
|
||||
dockSettings.SetHasPauseButton(
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <QWidget>
|
||||
#include <QDialog>
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QGroupBox>
|
||||
#include <QLineEdit>
|
||||
#include <QGridLayout>
|
||||
@@ -71,7 +72,7 @@ private:
|
||||
MacroInputSelection *_currentInputs;
|
||||
QCheckBox *_currentMacroRegisterDock;
|
||||
QCheckBox *_currentMacroIsStandaloneDock;
|
||||
QLineEdit *_currentMacroDockWindowName;
|
||||
QComboBox *_currentMacroDockWindowName;
|
||||
QCheckBox *_currentMacroDockAddRunButton;
|
||||
QCheckBox *_currentMacroDockAddPauseButton;
|
||||
QCheckBox *_currentMacroDockAddStatusLabel;
|
||||
|
||||
@@ -420,11 +420,10 @@ static bool queueWithNameExists(const std::string &name)
|
||||
return !GetWeakActionQueueByName(name).expired();
|
||||
}
|
||||
|
||||
static void signalImportedQueues(void *varsPtr)
|
||||
static void
|
||||
signalImportedQueues(const std::vector<std::shared_ptr<Item>> &queues)
|
||||
{
|
||||
auto queues = std::unique_ptr<std::vector<std::shared_ptr<Item>>>(
|
||||
static_cast<std::vector<std::shared_ptr<Item>> *>(varsPtr));
|
||||
for (const auto &queue : *queues) {
|
||||
for (const auto &queue : queues) {
|
||||
ActionQueueSignalManager::Instance()->Add(
|
||||
QString::fromStdString(queue->Name()));
|
||||
}
|
||||
@@ -436,7 +435,7 @@ void ImportQueues(obs_data_t *data)
|
||||
obs_data_get_array(data, "actionQueues");
|
||||
size_t count = obs_data_array_count(array);
|
||||
|
||||
auto importedQueues = new std::vector<std::shared_ptr<Item>>;
|
||||
std::vector<std::shared_ptr<Item>> importedQueues;
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
OBSDataAutoRelease arrayElement = obs_data_array_item(array, i);
|
||||
@@ -446,10 +445,11 @@ void ImportQueues(obs_data_t *data)
|
||||
continue;
|
||||
}
|
||||
queues.emplace_back(queue);
|
||||
importedQueues->emplace_back(queue);
|
||||
importedQueues.emplace_back(queue);
|
||||
}
|
||||
|
||||
QueueUITask(signalImportedQueues, importedQueues);
|
||||
QueueUITask(
|
||||
[importedQueues]() { signalImportedQueues(importedQueues); });
|
||||
}
|
||||
|
||||
std::weak_ptr<ActionQueue> GetWeakActionQueueByName(const std::string &name)
|
||||
|
||||
@@ -734,12 +734,10 @@ TempVarSignalManager *TempVarSignalManager::Instance()
|
||||
void NotifyUIAboutTempVarChange(MacroSegment *segment)
|
||||
{
|
||||
IncrementTempVarInUseGeneration();
|
||||
QueueUITask(
|
||||
[](void *segment) {
|
||||
TempVarSignalManager::Instance()->SegmentTempVarsChanged(
|
||||
(MacroSegment *)segment);
|
||||
},
|
||||
segment);
|
||||
QueueUITask([segment]() {
|
||||
TempVarSignalManager::Instance()->SegmentTempVarsChanged(
|
||||
segment);
|
||||
});
|
||||
}
|
||||
|
||||
TempVarOutputMappingsWidget::TempVarOutputMappingsWidget(QWidget *parent)
|
||||
|
||||
@@ -184,9 +184,9 @@ std::string GetThemeTypeName()
|
||||
#endif
|
||||
}
|
||||
|
||||
void QueueUITask(void (*task)(void *param), void *param)
|
||||
void QueueUITaskRaw(void (*task)(void *param), void *param, bool wait)
|
||||
{
|
||||
obs_queue_task(OBS_TASK_UI, task, param, false);
|
||||
obs_queue_task(OBS_TASK_UI, task, param, wait);
|
||||
}
|
||||
|
||||
bool IsCursorInWidgetArea(QWidget *widget)
|
||||
|
||||
@@ -6,7 +6,10 @@
|
||||
#include <QIcon>
|
||||
#include <QString>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
class QAbstractButton;
|
||||
class QComboBox;
|
||||
@@ -38,7 +41,23 @@ EXPORT void DisplayTrayMessage(const QString &title, const QString &msg,
|
||||
EXPORT std::string GetThemeTypeName();
|
||||
EXPORT QWidget *GetSettingsWindow();
|
||||
|
||||
EXPORT void QueueUITask(void (*task)(void *param), void *param);
|
||||
EXPORT void QueueUITaskRaw(void (*task)(void *param), void *param,
|
||||
bool wait = false);
|
||||
|
||||
// Runs func on the main/UI thread; blocks if wait is true.
|
||||
template<typename F> void QueueUITask(F &&func, bool wait = false)
|
||||
{
|
||||
using FnType = std::decay_t<F>;
|
||||
auto *heapFunc = new FnType(std::forward<F>(func));
|
||||
|
||||
QueueUITaskRaw(
|
||||
[](void *param) {
|
||||
std::unique_ptr<FnType> fn(
|
||||
static_cast<FnType *>(param));
|
||||
(*fn)();
|
||||
},
|
||||
heapFunc, wait);
|
||||
}
|
||||
|
||||
bool IsCursorInWidgetArea(QWidget *widget);
|
||||
|
||||
|
||||
@@ -504,11 +504,10 @@ void LoadVariables(obs_data_t *obj)
|
||||
}
|
||||
}
|
||||
|
||||
static void signalImportedVariables(void *varsPtr)
|
||||
static void
|
||||
signalImportedVariables(const std::vector<std::shared_ptr<Item>> &vars)
|
||||
{
|
||||
auto vars = std::unique_ptr<std::vector<std::shared_ptr<Item>>>(
|
||||
static_cast<std::vector<std::shared_ptr<Item>> *>(varsPtr));
|
||||
for (const auto &var : *vars) {
|
||||
for (const auto &var : vars) {
|
||||
VariableSignalManager::Instance()->Add(
|
||||
QString::fromStdString(var->Name()));
|
||||
}
|
||||
@@ -519,7 +518,7 @@ void ImportVariables(obs_data_t *data)
|
||||
OBSDataArrayAutoRelease array = obs_data_get_array(data, "variables");
|
||||
size_t count = obs_data_array_count(array);
|
||||
|
||||
auto importedVars = new std::vector<std::shared_ptr<Item>>;
|
||||
std::vector<std::shared_ptr<Item>> importedVars;
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
OBSDataAutoRelease arrayElement = obs_data_array_item(array, i);
|
||||
@@ -531,10 +530,11 @@ void ImportVariables(obs_data_t *data)
|
||||
}
|
||||
|
||||
GetVariables().emplace_back(var);
|
||||
importedVars->emplace_back(var);
|
||||
importedVars.emplace_back(var);
|
||||
}
|
||||
|
||||
QueueUITask(signalImportedVariables, importedVars);
|
||||
QueueUITask(
|
||||
[importedVars]() { signalImportedVariables(importedVars); });
|
||||
}
|
||||
|
||||
std::chrono::high_resolution_clock::time_point GetLastVariableChangeTime()
|
||||
|
||||
@@ -2,18 +2,64 @@
|
||||
#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(
|
||||
@@ -23,6 +69,7 @@ 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 {
|
||||
@@ -38,8 +85,7 @@ static void waitForPlaybackToEnd(Macro *macro, obs_source_t *source,
|
||||
std::unique_lock<std::mutex> lock(*GetMutex());
|
||||
SetMacroAbortWait(false);
|
||||
|
||||
// The media source needs time to open and decode before reaching
|
||||
// PLAYING state. Poll until it starts (or the macro is stopped).
|
||||
// Poll until the source starts playing or the macro is stopped.
|
||||
while (!MacroWaitShouldAbort() && !MacroIsStopped(macro)) {
|
||||
if (obs_source_media_get_state(source) ==
|
||||
OBS_MEDIA_STATE_PLAYING) {
|
||||
@@ -48,9 +94,8 @@ static void waitForPlaybackToEnd(Macro *macro, obs_source_t *source,
|
||||
GetMacroWaitCV().wait_for(lock, 10ms);
|
||||
}
|
||||
|
||||
// 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.
|
||||
// Wait for playback to end. Two consecutive non-playing samples are
|
||||
// required to avoid false positives on brief state transitions.
|
||||
const auto playbackStart = std::chrono::steady_clock::now();
|
||||
static const int kStopThreshold = 2;
|
||||
int stoppedCount = 0;
|
||||
@@ -95,7 +140,6 @@ 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);
|
||||
|
||||
@@ -113,10 +157,11 @@ 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 —
|
||||
// there is no point routing through the output channel if the mixer
|
||||
// mask would silence every track.
|
||||
// Fall back to monitor-only if all output tracks are deselected.
|
||||
const bool wantsOutput =
|
||||
(_monitorType != OBS_MONITORING_TYPE_MONITOR_ONLY) &&
|
||||
(_audioMixers != 0);
|
||||
@@ -128,10 +173,8 @@ bool MacroActionPlayAudio::PerformAction()
|
||||
|
||||
if (wantsOutput) {
|
||||
obs_source_set_audio_mixers(source, _audioMixers);
|
||||
// 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.
|
||||
// Route through a private scene positioned off-screen so the
|
||||
// audio mixes into the output without video appearing on screen.
|
||||
OBSSceneAutoRelease audioScene =
|
||||
obs_scene_create_private("advss_audio_scene");
|
||||
obs_sceneitem_t *item = obs_scene_add(audioScene, source);
|
||||
@@ -141,8 +184,7 @@ bool MacroActionPlayAudio::PerformAction()
|
||||
}
|
||||
obs_set_output_source(kPlaybackOutputChannel,
|
||||
obs_scene_get_source(audioScene));
|
||||
// audioScene released here; the output channel holds the
|
||||
// remaining reference and keeps the scene alive.
|
||||
// audioScene is released here; the output channel keeps the scene alive.
|
||||
} else {
|
||||
obs_source_set_audio_mixers(source, 0);
|
||||
obs_source_inc_active(source);
|
||||
@@ -167,15 +209,15 @@ bool MacroActionPlayAudio::PerformAction()
|
||||
return true;
|
||||
}
|
||||
|
||||
// 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.
|
||||
// Keep the source alive until playback ends via a background thread.
|
||||
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));
|
||||
@@ -204,6 +246,7 @@ 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;
|
||||
}
|
||||
|
||||
@@ -221,6 +264,7 @@ 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;
|
||||
}
|
||||
|
||||
@@ -262,7 +306,9 @@ MacroActionPlayAudioEdit::MacroActionPlayAudioEdit(
|
||||
_useDuration(new QCheckBox(this)),
|
||||
_playbackDuration(new DurationSelection(this, true, 0.0)),
|
||||
_waitForCompletion(new QCheckBox(
|
||||
obs_module_text("AdvSceneSwitcher.action.playAudio.wait")))
|
||||
obs_module_text("AdvSceneSwitcher.action.playAudio.wait"))),
|
||||
_mono(new QCheckBox(
|
||||
obs_module_text("AdvSceneSwitcher.action.playAudio.mono")))
|
||||
{
|
||||
_volumeDB->setMinimum(-100.0);
|
||||
_volumeDB->setMaximum(0.0);
|
||||
@@ -303,6 +349,8 @@ 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);
|
||||
@@ -346,6 +394,7 @@ MacroActionPlayAudioEdit::MacroActionPlayAudioEdit(
|
||||
mainLayout->addLayout(startOffsetLayout);
|
||||
mainLayout->addLayout(playbackDurationLayout);
|
||||
mainLayout->addWidget(_waitForCompletion);
|
||||
mainLayout->addWidget(_mono);
|
||||
setLayout(mainLayout);
|
||||
|
||||
_entryData = entryData;
|
||||
@@ -375,6 +424,7 @@ 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)
|
||||
@@ -443,4 +493,10 @@ void MacroActionPlayAudioEdit::WaitChanged(int value)
|
||||
_entryData->_waitForCompletion = value;
|
||||
}
|
||||
|
||||
void MacroActionPlayAudioEdit::MonoChanged(int value)
|
||||
{
|
||||
GUARD_LOADING_AND_LOCK();
|
||||
_entryData->_mono = value;
|
||||
}
|
||||
|
||||
} // namespace advss
|
||||
|
||||
@@ -37,6 +37,7 @@ public:
|
||||
bool _useDuration = false;
|
||||
Duration _playbackDuration;
|
||||
bool _waitForCompletion = false;
|
||||
bool _mono = false;
|
||||
|
||||
static bool _registered;
|
||||
static const std::string id;
|
||||
@@ -68,6 +69,7 @@ private slots:
|
||||
void UseDurationChanged(int);
|
||||
void PlaybackDurationChanged(const Duration &);
|
||||
void WaitChanged(int value);
|
||||
void MonoChanged(int value);
|
||||
|
||||
signals:
|
||||
void HeaderInfoChanged(const QString &);
|
||||
@@ -83,6 +85,7 @@ private:
|
||||
QCheckBox *_useDuration;
|
||||
DurationSelection *_playbackDuration;
|
||||
QCheckBox *_waitForCompletion;
|
||||
QCheckBox *_mono;
|
||||
|
||||
std::shared_ptr<MacroActionPlayAudio> _entryData;
|
||||
bool _loading = true;
|
||||
|
||||
@@ -17,20 +17,6 @@ bool MacroActionSceneCollection::_registered = MacroActionFactory::Register(
|
||||
MacroActionSceneCollectionEdit::Create,
|
||||
"AdvSceneSwitcher.action.sceneCollection"});
|
||||
|
||||
template<typename F> void QueueUITaskLambda(F &&func)
|
||||
{
|
||||
using FnType = std::decay_t<F>;
|
||||
auto *heapFunc = new FnType(std::forward<F>(func));
|
||||
|
||||
QueueUITask(
|
||||
[](void *param) {
|
||||
std::unique_ptr<FnType> fn(
|
||||
static_cast<FnType *>(param));
|
||||
(*fn)();
|
||||
},
|
||||
heapFunc);
|
||||
}
|
||||
|
||||
bool MacroActionSceneCollection::PerformAction()
|
||||
{
|
||||
// Changing the scene collection will also reload the settings of the
|
||||
@@ -41,7 +27,7 @@ bool MacroActionSceneCollection::PerformAction()
|
||||
}
|
||||
|
||||
const auto collectionName = _sceneCollection;
|
||||
QueueUITaskLambda([collectionName]() {
|
||||
QueueUITask([collectionName]() {
|
||||
obs_frontend_set_current_scene_collection(
|
||||
collectionName.c_str());
|
||||
});
|
||||
|
||||
@@ -185,20 +185,6 @@ static void closeSourceDialog(obs_source_t *source, bool accept,
|
||||
}
|
||||
}
|
||||
|
||||
template<typename F> void QueueUITaskLambda(F &&func)
|
||||
{
|
||||
using FnType = std::decay_t<F>;
|
||||
auto *heapFunc = new FnType(std::forward<F>(func));
|
||||
|
||||
QueueUITask(
|
||||
[](void *param) {
|
||||
std::unique_ptr<FnType> fn(
|
||||
static_cast<FnType *>(param));
|
||||
(*fn)();
|
||||
},
|
||||
heapFunc);
|
||||
}
|
||||
|
||||
bool MacroActionSource::PerformAction()
|
||||
{
|
||||
OBSSource s = obs_weak_source_get_source(_source.GetSource());
|
||||
@@ -271,17 +257,17 @@ bool MacroActionSource::PerformAction()
|
||||
break;
|
||||
}
|
||||
|
||||
QueueUITaskLambda([&]() {
|
||||
QueueUITask([&]() {
|
||||
closeSourceDialog(s, true, "OBSBasicInteraction");
|
||||
});
|
||||
break;
|
||||
case Action::CLOSE_FILTER_DIALOG:
|
||||
QueueUITaskLambda([&]() {
|
||||
QueueUITask([&]() {
|
||||
closeSourceDialog(s, _acceptDialog, "OBSBasicFilters");
|
||||
});
|
||||
break;
|
||||
case Action::CLOSE_PROPERTIES_DIALOG:
|
||||
QueueUITaskLambda([&]() {
|
||||
QueueUITask([&]() {
|
||||
closeSourceDialog(s, _acceptDialog,
|
||||
"OBSBasicProperties");
|
||||
});
|
||||
|
||||
@@ -5,8 +5,74 @@
|
||||
|
||||
#include <QFileDialog>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <spawn.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <csignal>
|
||||
#include <cerrno>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
extern char **environ;
|
||||
#endif
|
||||
|
||||
namespace advss {
|
||||
|
||||
#ifdef __APPLE__
|
||||
// QProcess uses fork(), which is unsafe to call in OBS's multi-threaded,
|
||||
// CEF/XPC-using process (see fork(2)). posix_spawn() avoids fork() entirely.
|
||||
|
||||
namespace {
|
||||
|
||||
std::vector<char *> BuildArgv(const std::string &path, const QStringList &args,
|
||||
std::vector<std::string> &storage)
|
||||
{
|
||||
storage.push_back(path);
|
||||
for (auto &arg : args) {
|
||||
storage.push_back(arg.toStdString());
|
||||
}
|
||||
|
||||
std::vector<char *> argv;
|
||||
argv.reserve(storage.size() + 1);
|
||||
for (auto &arg : storage) {
|
||||
argv.push_back(const_cast<char *>(arg.c_str()));
|
||||
}
|
||||
argv.push_back(nullptr);
|
||||
return argv;
|
||||
}
|
||||
|
||||
bool DrainPipe(int fd, std::string &buffer)
|
||||
{
|
||||
char chunk[4096];
|
||||
while (true) {
|
||||
ssize_t n = read(fd, chunk, sizeof(chunk));
|
||||
if (n > 0) {
|
||||
buffer.append(chunk, static_cast<size_t>(n));
|
||||
continue;
|
||||
}
|
||||
if (n == 0) {
|
||||
return false; // EOF
|
||||
}
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
return true; // EAGAIN/EWOULDBLOCK
|
||||
}
|
||||
}
|
||||
|
||||
std::string TrimTrailingNewline(const std::string &s)
|
||||
{
|
||||
static const QRegularExpression regex("(\\r\\n|\\r|\\n)$");
|
||||
return QString::fromStdString(s).remove(regex).toStdString();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
#endif
|
||||
|
||||
bool ProcessConfig::Save(obs_data_t *obj) const
|
||||
{
|
||||
auto data = obs_data_create();
|
||||
@@ -50,11 +116,44 @@ QStringList ProcessConfig::Args() const
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
bool ProcessConfig::StartProcessDetached() const
|
||||
{
|
||||
auto path = Path();
|
||||
auto workDir = WorkingDir();
|
||||
std::vector<std::string> argStorage;
|
||||
auto argv = BuildArgv(path, Args(), argStorage);
|
||||
|
||||
posix_spawn_file_actions_t actions;
|
||||
posix_spawn_file_actions_init(&actions);
|
||||
if (!workDir.empty()) {
|
||||
posix_spawn_file_actions_addchdir_np(&actions, workDir.c_str());
|
||||
}
|
||||
|
||||
pid_t pid = 0;
|
||||
int rc = posix_spawn(&pid, path.c_str(), &actions, nullptr, argv.data(),
|
||||
environ);
|
||||
posix_spawn_file_actions_destroy(&actions);
|
||||
|
||||
if (rc != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::thread([pid]() {
|
||||
int status = 0;
|
||||
while (waitpid(pid, &status, 0) == -1 && errno == EINTR) {
|
||||
}
|
||||
}).detach();
|
||||
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
bool ProcessConfig::StartProcessDetached() const
|
||||
{
|
||||
return QProcess::startDetached(QString::fromStdString(Path()), Args(),
|
||||
QString::fromStdString(WorkingDir()));
|
||||
}
|
||||
#endif
|
||||
|
||||
void ProcessConfig::ResolveVariables()
|
||||
{
|
||||
@@ -63,6 +162,139 @@ void ProcessConfig::ResolveVariables()
|
||||
_args.ResolveVariables();
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
std::variant<int, ProcessConfig::ProcStartError>
|
||||
ProcessConfig::StartProcessAndWait(int timeout)
|
||||
{
|
||||
ResetFinishedProcessData();
|
||||
|
||||
vblog(LOG_INFO, "run \"%s\" with a timeout of %d ms", Path().c_str(),
|
||||
timeout);
|
||||
|
||||
int outPipe[2];
|
||||
int errPipe[2];
|
||||
if (pipe(outPipe) != 0 || pipe(errPipe) != 0) {
|
||||
vblog(LOG_INFO, "failed to start \"%s\"!", Path().c_str());
|
||||
return ProcStartError::FAILED_TO_START;
|
||||
}
|
||||
|
||||
auto path = Path();
|
||||
auto workDir = WorkingDir();
|
||||
std::vector<std::string> argStorage;
|
||||
auto argv = BuildArgv(path, Args(), argStorage);
|
||||
|
||||
posix_spawn_file_actions_t actions;
|
||||
posix_spawn_file_actions_init(&actions);
|
||||
posix_spawn_file_actions_addclose(&actions, outPipe[0]);
|
||||
posix_spawn_file_actions_addclose(&actions, errPipe[0]);
|
||||
posix_spawn_file_actions_adddup2(&actions, outPipe[1], STDOUT_FILENO);
|
||||
posix_spawn_file_actions_adddup2(&actions, errPipe[1], STDERR_FILENO);
|
||||
posix_spawn_file_actions_addclose(&actions, outPipe[1]);
|
||||
posix_spawn_file_actions_addclose(&actions, errPipe[1]);
|
||||
if (!workDir.empty()) {
|
||||
posix_spawn_file_actions_addchdir_np(&actions, workDir.c_str());
|
||||
}
|
||||
|
||||
pid_t pid = 0;
|
||||
int rc = posix_spawn(&pid, path.c_str(), &actions, nullptr, argv.data(),
|
||||
environ);
|
||||
posix_spawn_file_actions_destroy(&actions);
|
||||
close(outPipe[1]);
|
||||
close(errPipe[1]);
|
||||
|
||||
if (rc != 0) {
|
||||
close(outPipe[0]);
|
||||
close(errPipe[0]);
|
||||
vblog(LOG_INFO, "failed to start \"%s\"!", Path().c_str());
|
||||
return ProcStartError::FAILED_TO_START;
|
||||
}
|
||||
|
||||
SetProcessId(std::to_string(pid));
|
||||
fcntl(outPipe[0], F_SETFL, O_NONBLOCK);
|
||||
fcntl(errPipe[0], F_SETFL, O_NONBLOCK);
|
||||
|
||||
std::string outBuf;
|
||||
std::string errBuf;
|
||||
bool outDone = false;
|
||||
bool errDone = false;
|
||||
auto deadline = std::chrono::steady_clock::now() +
|
||||
std::chrono::milliseconds(timeout);
|
||||
|
||||
while (!outDone || !errDone) {
|
||||
auto remaining =
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
deadline - std::chrono::steady_clock::now())
|
||||
.count();
|
||||
if (remaining <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
struct pollfd fds[2];
|
||||
int n = 0;
|
||||
int outIdx = -1;
|
||||
int errIdx = -1;
|
||||
if (!outDone) {
|
||||
fds[n] = {outPipe[0], POLLIN, 0};
|
||||
outIdx = n++;
|
||||
}
|
||||
if (!errDone) {
|
||||
fds[n] = {errPipe[0], POLLIN, 0};
|
||||
errIdx = n++;
|
||||
}
|
||||
|
||||
int pr = poll(fds, n, static_cast<int>(remaining));
|
||||
if (pr < 0) {
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (outIdx >= 0 && fds[outIdx].revents != 0) {
|
||||
if (!DrainPipe(outPipe[0], outBuf)) {
|
||||
outDone = true;
|
||||
}
|
||||
}
|
||||
if (errIdx >= 0 && fds[errIdx].revents != 0) {
|
||||
if (!DrainPipe(errPipe[0], errBuf)) {
|
||||
errDone = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
close(outPipe[0]);
|
||||
close(errPipe[0]);
|
||||
|
||||
if (!outDone || !errDone) {
|
||||
vblog(LOG_INFO,
|
||||
"timeout while running \"%s\"\nAttempting to kill process!",
|
||||
Path().c_str());
|
||||
kill(pid, SIGKILL);
|
||||
int status = 0;
|
||||
while (waitpid(pid, &status, 0) == -1 && errno == EINTR) {
|
||||
}
|
||||
_processOutputStream = TrimTrailingNewline(outBuf);
|
||||
_processErrorStream = TrimTrailingNewline(errBuf);
|
||||
return ProcStartError::TIMEOUT;
|
||||
}
|
||||
|
||||
int status = 0;
|
||||
while (waitpid(pid, &status, 0) == -1 && errno == EINTR) {
|
||||
}
|
||||
|
||||
_processOutputStream = TrimTrailingNewline(outBuf);
|
||||
_processErrorStream = TrimTrailingNewline(errBuf);
|
||||
|
||||
if (WIFEXITED(status)) {
|
||||
int exitCode = WEXITSTATUS(status);
|
||||
_processExitCode = std::to_string(exitCode);
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
vblog(LOG_INFO, "process \"%s\" crashed!", Path().c_str());
|
||||
return ProcStartError::CRASH;
|
||||
}
|
||||
#else
|
||||
std::variant<int, ProcessConfig::ProcStartError>
|
||||
ProcessConfig::StartProcessAndWait(int timeout)
|
||||
{
|
||||
@@ -101,6 +333,7 @@ ProcessConfig::StartProcessAndWait(int timeout)
|
||||
vblog(LOG_INFO, "process \"%s\" crashed!", Path().c_str());
|
||||
return ProcStartError::CRASH;
|
||||
}
|
||||
#endif
|
||||
|
||||
void ProcessConfig::SetFinishedProcessData(QProcess &process)
|
||||
{
|
||||
|
||||
@@ -31,14 +31,9 @@ static bool setup()
|
||||
static const auto showInvalidWarnings = [](void *) {
|
||||
const auto invalidTokens = getInvalidTokens();
|
||||
for (const auto &token : invalidTokens) {
|
||||
QueueUITask(
|
||||
[](void *tokenPtr) {
|
||||
auto tokenName = static_cast<QString *>(
|
||||
tokenPtr);
|
||||
InvalidTokenDialog::ShowWarning(
|
||||
*tokenName);
|
||||
},
|
||||
(void *)&token);
|
||||
QueueUITask([token]() {
|
||||
InvalidTokenDialog::ShowWarning(token);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ std::string GetThemeTypeName()
|
||||
return "Dark";
|
||||
}
|
||||
|
||||
void QueueUITask(void (*task)(void *param), void *) {}
|
||||
void QueueUITaskRaw(void (*task)(void *param), void *, bool) {}
|
||||
|
||||
QWidget *GetSettingsWindow()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user