mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-09-10 18:46:11 -05:00
Compare commits
2 Commits
mac-proc-f
...
play-mono
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
465f55d3f3 | ||
|
|
9758c14c33 |
@@ -267,7 +267,6 @@ 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"
|
||||
@@ -343,9 +342,7 @@ 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"
|
||||
@@ -907,19 +904,9 @@ AdvSceneSwitcher.condition.streamDeck.stopListen="Stop listening"
|
||||
AdvSceneSwitcher.condition.streamDeck.pluginDownload="<html><head/><body><p>The Stream Deck plugin can be found <a href=\"https://github.com/WarmUpTill/advanced-scene-switcher-streamdeck-plugin/releases\"><span style=\" text-decoration: underline; color:#268bd2;\">here on GitHub</span></a>.</p></body></html>"
|
||||
AdvSceneSwitcher.condition.gameCapture="Game capture"
|
||||
AdvSceneSwitcher.condition.gameCapture.entry="{{sources}}hooked a game."
|
||||
|
||||
AdvSceneSwitcher.condition.screenshot="Screenshot"
|
||||
AdvSceneSwitcher.condition.screenshot.entry="A screenshot was taken"
|
||||
AdvSceneSwitcher.condition.nowPlaying="Now Playing"
|
||||
AdvSceneSwitcher.condition.nowPlaying.checkType.playbackState="Playback state"
|
||||
AdvSceneSwitcher.condition.nowPlaying.checkType.title="Title"
|
||||
AdvSceneSwitcher.condition.nowPlaying.checkType.artist="Artist"
|
||||
AdvSceneSwitcher.condition.nowPlaying.checkType.album="Album"
|
||||
AdvSceneSwitcher.condition.nowPlaying.checkType.appName="App name"
|
||||
AdvSceneSwitcher.condition.nowPlaying.playbackState.playing="Playing"
|
||||
AdvSceneSwitcher.condition.nowPlaying.playbackState.paused="Paused"
|
||||
AdvSceneSwitcher.condition.nowPlaying.playbackState.stopped="Stopped"
|
||||
AdvSceneSwitcher.condition.nowPlaying.playbackState.opening="Opening"
|
||||
AdvSceneSwitcher.condition.nowPlaying.playbackState.changing="Changing"
|
||||
AdvSceneSwitcher.condition.mqtt="MQTT"
|
||||
AdvSceneSwitcher.condition.mqtt.layout.match="Message was received from{{connection}} which matches{{regex}}:"
|
||||
AdvSceneSwitcher.condition.mqtt.layout.listen="Set message selection to incoming message:{{listenButton}}"
|
||||
@@ -2378,7 +2365,6 @@ 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."
|
||||
@@ -2614,12 +2600,6 @@ AdvSceneSwitcher.tempVar.gameCapture.class.description="Window class of the appl
|
||||
AdvSceneSwitcher.tempVar.gameCapture.executable="Executable"
|
||||
AdvSceneSwitcher.tempVar.gameCapture.executable.description="Executable name of the application captured by the source."
|
||||
|
||||
AdvSceneSwitcher.tempVar.nowPlaying.title="Title"
|
||||
AdvSceneSwitcher.tempVar.nowPlaying.artist="Artist"
|
||||
AdvSceneSwitcher.tempVar.nowPlaying.album="Album"
|
||||
AdvSceneSwitcher.tempVar.nowPlaying.appName="App name"
|
||||
AdvSceneSwitcher.tempVar.nowPlaying.playbackStatus="Playback status"
|
||||
|
||||
AdvSceneSwitcher.tempVar.http.status="Status code"
|
||||
AdvSceneSwitcher.tempVar.http.error="Error"
|
||||
AdvSceneSwitcher.tempVar.http.error.description="Empty when no error occurred.\nOther possible values:\n\n * Could not establish connection\n * Failed to bind IP address\n * Failed to read connection\n * Failed to write connection\n * Maximum redirect count exceeded\n * Connection handling canceled\n * SSL connection failed\n * SSL certificate loading failed\n * SSL server verification failed\n * Unsupported HTTP multipart boundary characters\n * Compression failed\n * Connection timed out\n * Proxy connection failed\n * Unknown"
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#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"
|
||||
@@ -9,48 +8,11 @@
|
||||
#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();
|
||||
@@ -134,7 +96,7 @@ MacroSettingsDialog::MacroSettingsDialog(QWidget *parent,
|
||||
"AdvSceneSwitcher.macroTab.currentRegisterDock"))),
|
||||
_currentMacroIsStandaloneDock(new QCheckBox(obs_module_text(
|
||||
"AdvSceneSwitcher.macroTab.currentIsStandaloneDock"))),
|
||||
_currentMacroDockWindowName(new QComboBox(this)),
|
||||
_currentMacroDockWindowName(new QLineEdit(this)),
|
||||
_currentMacroDockAddRunButton(new QCheckBox(obs_module_text(
|
||||
"AdvSceneSwitcher.macroTab.currentDockAddRunButton"))),
|
||||
_currentMacroDockAddPauseButton(new QCheckBox(obs_module_text(
|
||||
@@ -181,17 +143,6 @@ 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;
|
||||
@@ -397,7 +348,7 @@ MacroSettingsDialog::MacroSettingsDialog(QWidget *parent,
|
||||
_currentMacroRegisterDock->setChecked(dockEnabled);
|
||||
_currentMacroIsStandaloneDock->setChecked(
|
||||
dockSettings.IsStandaloneDock());
|
||||
_currentMacroDockWindowName->setCurrentText(
|
||||
_currentMacroDockWindowName->setText(
|
||||
QString::fromStdString(dockSettings.DockWindowName()));
|
||||
_currentMacroDockAddRunButton->setChecked(dockSettings.HasRunButton());
|
||||
_currentMacroDockAddPauseButton->setChecked(
|
||||
@@ -535,7 +486,7 @@ bool MacroSettingsDialog::AskForSettings(QWidget *parent,
|
||||
dockSettings.SetIsStandaloneDock(
|
||||
dialog._currentMacroIsStandaloneDock->isChecked());
|
||||
dockSettings.SetDockWindowName(
|
||||
dialog._currentMacroDockWindowName->currentText().toStdString());
|
||||
dialog._currentMacroDockWindowName->text().toStdString());
|
||||
dockSettings.SetHasRunButton(
|
||||
dialog._currentMacroDockAddRunButton->isChecked());
|
||||
dockSettings.SetHasPauseButton(
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include <QWidget>
|
||||
#include <QDialog>
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QGroupBox>
|
||||
#include <QLineEdit>
|
||||
#include <QGridLayout>
|
||||
@@ -72,7 +71,7 @@ private:
|
||||
MacroInputSelection *_currentInputs;
|
||||
QCheckBox *_currentMacroRegisterDock;
|
||||
QCheckBox *_currentMacroIsStandaloneDock;
|
||||
QComboBox *_currentMacroDockWindowName;
|
||||
QLineEdit *_currentMacroDockWindowName;
|
||||
QCheckBox *_currentMacroDockAddRunButton;
|
||||
QCheckBox *_currentMacroDockAddPauseButton;
|
||||
QCheckBox *_currentMacroDockAddStatusLabel;
|
||||
|
||||
@@ -420,10 +420,11 @@ static bool queueWithNameExists(const std::string &name)
|
||||
return !GetWeakActionQueueByName(name).expired();
|
||||
}
|
||||
|
||||
static void
|
||||
signalImportedQueues(const std::vector<std::shared_ptr<Item>> &queues)
|
||||
static void signalImportedQueues(void *varsPtr)
|
||||
{
|
||||
for (const auto &queue : 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) {
|
||||
ActionQueueSignalManager::Instance()->Add(
|
||||
QString::fromStdString(queue->Name()));
|
||||
}
|
||||
@@ -435,7 +436,7 @@ void ImportQueues(obs_data_t *data)
|
||||
obs_data_get_array(data, "actionQueues");
|
||||
size_t count = obs_data_array_count(array);
|
||||
|
||||
std::vector<std::shared_ptr<Item>> importedQueues;
|
||||
auto importedQueues = new std::vector<std::shared_ptr<Item>>;
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
OBSDataAutoRelease arrayElement = obs_data_array_item(array, i);
|
||||
@@ -445,11 +446,10 @@ void ImportQueues(obs_data_t *data)
|
||||
continue;
|
||||
}
|
||||
queues.emplace_back(queue);
|
||||
importedQueues.emplace_back(queue);
|
||||
importedQueues->emplace_back(queue);
|
||||
}
|
||||
|
||||
QueueUITask(
|
||||
[importedQueues]() { signalImportedQueues(importedQueues); });
|
||||
QueueUITask(signalImportedQueues, importedQueues);
|
||||
}
|
||||
|
||||
std::weak_ptr<ActionQueue> GetWeakActionQueueByName(const std::string &name)
|
||||
|
||||
@@ -734,10 +734,12 @@ TempVarSignalManager *TempVarSignalManager::Instance()
|
||||
void NotifyUIAboutTempVarChange(MacroSegment *segment)
|
||||
{
|
||||
IncrementTempVarInUseGeneration();
|
||||
QueueUITask([segment]() {
|
||||
TempVarSignalManager::Instance()->SegmentTempVarsChanged(
|
||||
segment);
|
||||
});
|
||||
QueueUITask(
|
||||
[](void *segment) {
|
||||
TempVarSignalManager::Instance()->SegmentTempVarsChanged(
|
||||
(MacroSegment *)segment);
|
||||
},
|
||||
segment);
|
||||
}
|
||||
|
||||
TempVarOutputMappingsWidget::TempVarOutputMappingsWidget(QWidget *parent)
|
||||
|
||||
@@ -184,9 +184,9 @@ std::string GetThemeTypeName()
|
||||
#endif
|
||||
}
|
||||
|
||||
void QueueUITaskRaw(void (*task)(void *param), void *param, bool wait)
|
||||
void QueueUITask(void (*task)(void *param), void *param)
|
||||
{
|
||||
obs_queue_task(OBS_TASK_UI, task, param, wait);
|
||||
obs_queue_task(OBS_TASK_UI, task, param, false);
|
||||
}
|
||||
|
||||
bool IsCursorInWidgetArea(QWidget *widget)
|
||||
|
||||
@@ -6,10 +6,7 @@
|
||||
#include <QIcon>
|
||||
#include <QString>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
class QAbstractButton;
|
||||
class QComboBox;
|
||||
@@ -41,23 +38,7 @@ EXPORT void DisplayTrayMessage(const QString &title, const QString &msg,
|
||||
EXPORT std::string GetThemeTypeName();
|
||||
EXPORT QWidget *GetSettingsWindow();
|
||||
|
||||
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);
|
||||
}
|
||||
EXPORT void QueueUITask(void (*task)(void *param), void *param);
|
||||
|
||||
bool IsCursorInWidgetArea(QWidget *widget);
|
||||
|
||||
|
||||
@@ -504,10 +504,11 @@ void LoadVariables(obs_data_t *obj)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
signalImportedVariables(const std::vector<std::shared_ptr<Item>> &vars)
|
||||
static void signalImportedVariables(void *varsPtr)
|
||||
{
|
||||
for (const auto &var : 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) {
|
||||
VariableSignalManager::Instance()->Add(
|
||||
QString::fromStdString(var->Name()));
|
||||
}
|
||||
@@ -518,7 +519,7 @@ void ImportVariables(obs_data_t *data)
|
||||
OBSDataArrayAutoRelease array = obs_data_get_array(data, "variables");
|
||||
size_t count = obs_data_array_count(array);
|
||||
|
||||
std::vector<std::shared_ptr<Item>> importedVars;
|
||||
auto importedVars = new std::vector<std::shared_ptr<Item>>;
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
OBSDataAutoRelease arrayElement = obs_data_array_item(array, i);
|
||||
@@ -530,11 +531,10 @@ void ImportVariables(obs_data_t *data)
|
||||
}
|
||||
|
||||
GetVariables().emplace_back(var);
|
||||
importedVars.emplace_back(var);
|
||||
importedVars->emplace_back(var);
|
||||
}
|
||||
|
||||
QueueUITask(
|
||||
[importedVars]() { signalImportedVariables(importedVars); });
|
||||
QueueUITask(signalImportedVariables, importedVars);
|
||||
}
|
||||
|
||||
std::chrono::high_resolution_clock::time_point GetLastVariableChangeTime()
|
||||
|
||||
@@ -42,7 +42,6 @@ add_plugin(twitch)
|
||||
add_plugin(usb)
|
||||
add_plugin(video)
|
||||
add_plugin(speech)
|
||||
add_plugin(now-playing)
|
||||
|
||||
# ---------------------------------------------------------------------------- #
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
#include "macro-action-scene-collection.hpp"
|
||||
|
||||
#include "layout-helpers.hpp"
|
||||
#include "plugin-state-helpers.hpp"
|
||||
#include "selection-helpers.hpp"
|
||||
#include "ui-helpers.hpp"
|
||||
|
||||
#include <obs-frontend-api.h>
|
||||
|
||||
@@ -25,13 +23,7 @@ bool MacroActionSceneCollection::PerformAction()
|
||||
if (SettingsWindowIsOpened()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto collectionName = _sceneCollection;
|
||||
QueueUITask([collectionName]() {
|
||||
obs_frontend_set_current_scene_collection(
|
||||
collectionName.c_str());
|
||||
});
|
||||
|
||||
obs_frontend_set_current_scene_collection(_sceneCollection.c_str());
|
||||
// It does not make sense to continue as the current settings will be
|
||||
// invalid after switching scene collection.
|
||||
return false;
|
||||
|
||||
@@ -185,6 +185,20 @@ 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());
|
||||
@@ -257,17 +271,17 @@ bool MacroActionSource::PerformAction()
|
||||
break;
|
||||
}
|
||||
|
||||
QueueUITask([&]() {
|
||||
QueueUITaskLambda([&]() {
|
||||
closeSourceDialog(s, true, "OBSBasicInteraction");
|
||||
});
|
||||
break;
|
||||
case Action::CLOSE_FILTER_DIALOG:
|
||||
QueueUITask([&]() {
|
||||
QueueUITaskLambda([&]() {
|
||||
closeSourceDialog(s, _acceptDialog, "OBSBasicFilters");
|
||||
});
|
||||
break;
|
||||
case Action::CLOSE_PROPERTIES_DIALOG:
|
||||
QueueUITask([&]() {
|
||||
QueueUITaskLambda([&]() {
|
||||
closeSourceDialog(s, _acceptDialog,
|
||||
"OBSBasicProperties");
|
||||
});
|
||||
|
||||
@@ -25,8 +25,6 @@ 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>
|
||||
@@ -247,20 +245,6 @@ 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;
|
||||
@@ -280,9 +264,6 @@ bool MacroConditionAudio::CheckCondition()
|
||||
case Type::BALANCE:
|
||||
ret = CheckBalance();
|
||||
break;
|
||||
case Type::TRACK:
|
||||
ret = CheckTrack();
|
||||
break;
|
||||
}
|
||||
|
||||
if (GetVariableValue().empty()) {
|
||||
@@ -300,7 +281,6 @@ 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));
|
||||
@@ -366,7 +346,6 @@ bool MacroConditionAudio::Load(obs_data_t *obj)
|
||||
_useDb = obs_data_get_bool(obj, "useDb");
|
||||
_volumeDB.Load(obj, "volumeDB");
|
||||
}
|
||||
_track.Load(obj, "track");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -442,12 +421,6 @@ 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;
|
||||
}
|
||||
@@ -495,7 +468,6 @@ 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()),
|
||||
@@ -504,8 +476,7 @@ MacroConditionAudioEdit::MacroConditionAudioEdit(
|
||||
_percentDBToggle(new QPushButton),
|
||||
_syncOffset(new VariableSpinBox()),
|
||||
_monitorTypes(new QComboBox),
|
||||
_balance(new SliderSpinBox(0., 1., "")),
|
||||
_track(new VariableSpinBox())
|
||||
_balance(new SliderSpinBox(0., 1., ""))
|
||||
{
|
||||
_volumePercent->setSuffix("%");
|
||||
_volumePercent->setMaximum(100);
|
||||
@@ -520,9 +491,6 @@ 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(
|
||||
@@ -551,16 +519,27 @@ 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(_layout);
|
||||
mainLayout->addLayout(switchLayout);
|
||||
mainLayout->addWidget(_balance);
|
||||
setLayout(mainLayout);
|
||||
|
||||
@@ -629,12 +608,6 @@ 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)
|
||||
{
|
||||
@@ -719,8 +692,6 @@ 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();
|
||||
}
|
||||
@@ -737,7 +708,6 @@ 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())));
|
||||
|
||||
@@ -778,63 +748,26 @@ 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(
|
||||
!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());
|
||||
_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);
|
||||
_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,7 +5,6 @@
|
||||
#include "source-selection.hpp"
|
||||
|
||||
#include <limits>
|
||||
#include <QHBoxLayout>
|
||||
#include <QWidget>
|
||||
#include <QComboBox>
|
||||
#include <chrono>
|
||||
@@ -37,7 +36,6 @@ public:
|
||||
SYNC_OFFSET,
|
||||
MONITOR,
|
||||
BALANCE,
|
||||
TRACK,
|
||||
};
|
||||
void SetType(const Type &);
|
||||
Type GetType() const { return _checkType; }
|
||||
@@ -62,7 +60,6 @@ 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;
|
||||
@@ -73,7 +70,6 @@ private:
|
||||
bool CheckSyncOffset();
|
||||
bool CheckMonitor();
|
||||
bool CheckBalance();
|
||||
bool CheckTrack();
|
||||
void SetupTempVars();
|
||||
float GetVolumePeak();
|
||||
|
||||
@@ -115,7 +111,6 @@ 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 &);
|
||||
@@ -124,7 +119,6 @@ private:
|
||||
void SetWidgetVisibility();
|
||||
bool HasVolumeControl() const;
|
||||
|
||||
QHBoxLayout *_layout;
|
||||
QComboBox *_checkTypes;
|
||||
SourceSelectionWidget *_sources;
|
||||
QComboBox *_condition;
|
||||
@@ -134,7 +128,6 @@ private:
|
||||
VariableSpinBox *_syncOffset;
|
||||
QComboBox *_monitorTypes;
|
||||
SliderSpinBox *_balance;
|
||||
VariableSpinBox *_track;
|
||||
VolControl *_volMeter = nullptr;
|
||||
|
||||
std::shared_ptr<MacroConditionAudio> _entryData;
|
||||
|
||||
@@ -5,74 +5,8 @@
|
||||
|
||||
#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();
|
||||
@@ -116,44 +50,11 @@ 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()
|
||||
{
|
||||
@@ -162,139 +63,6 @@ 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)
|
||||
{
|
||||
@@ -333,7 +101,6 @@ ProcessConfig::StartProcessAndWait(int timeout)
|
||||
vblog(LOG_INFO, "process \"%s\" crashed!", Path().c_str());
|
||||
return ProcStartError::CRASH;
|
||||
}
|
||||
#endif
|
||||
|
||||
void ProcessConfig::SetFinishedProcessData(QProcess &process)
|
||||
{
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
project(advanced-scene-switcher-now-playing)
|
||||
|
||||
if(NOT WIN32)
|
||||
message(WARNING "Now playing condition is only supported on Windows.")
|
||||
return()
|
||||
endif()
|
||||
|
||||
add_library(${PROJECT_NAME} MODULE)
|
||||
target_sources(${PROJECT_NAME} PRIVATE macro-condition-now-playing.cpp
|
||||
macro-condition-now-playing.hpp)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE windowsapp)
|
||||
|
||||
setup_advss_plugin(${PROJECT_NAME})
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")
|
||||
install_advss_plugin(${PROJECT_NAME})
|
||||
@@ -1,338 +0,0 @@
|
||||
#include "macro-condition-now-playing.hpp"
|
||||
#include "layout-helpers.hpp"
|
||||
#include "sync-helpers.hpp"
|
||||
|
||||
#include <util/base.h>
|
||||
|
||||
#include <roapi.h>
|
||||
#include <winrt/Windows.Foundation.h>
|
||||
#include <winrt/Windows.Media.Control.h>
|
||||
|
||||
namespace advss {
|
||||
|
||||
using namespace winrt::Windows::Media::Control;
|
||||
|
||||
const std::string MacroConditionNowPlaying::id = "now_playing";
|
||||
|
||||
bool MacroConditionNowPlaying::_registered = MacroConditionFactory::Register(
|
||||
MacroConditionNowPlaying::id,
|
||||
{MacroConditionNowPlaying::Create, MacroConditionNowPlayingEdit::Create,
|
||||
"AdvSceneSwitcher.condition.nowPlaying"});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
struct SessionInfo {
|
||||
bool hasSession = false;
|
||||
std::string title;
|
||||
std::string artist;
|
||||
std::string album;
|
||||
std::string appName;
|
||||
GlobalSystemMediaTransportControlsSessionPlaybackStatus playbackStatus =
|
||||
GlobalSystemMediaTransportControlsSessionPlaybackStatus::Closed;
|
||||
};
|
||||
|
||||
static bool initWinRT()
|
||||
{
|
||||
HRESULT hr = RoInitialize(RO_INIT_MULTITHREADED);
|
||||
// S_OK: initialized, S_FALSE: already initialized with same type,
|
||||
// RPC_E_CHANGED_MODE: thread is STA (OBS UI thread) - WinRT still usable
|
||||
return SUCCEEDED(hr) || hr == RPC_E_CHANGED_MODE;
|
||||
}
|
||||
|
||||
static SessionInfo getCurrentSessionInfo()
|
||||
{
|
||||
thread_local bool initialized = initWinRT();
|
||||
(void)initialized;
|
||||
|
||||
SessionInfo info;
|
||||
|
||||
try {
|
||||
auto manager =
|
||||
GlobalSystemMediaTransportControlsSessionManager::
|
||||
RequestAsync()
|
||||
.get();
|
||||
auto session = manager.GetCurrentSession();
|
||||
if (!session) {
|
||||
return info;
|
||||
}
|
||||
|
||||
info.hasSession = true;
|
||||
info.appName = winrt::to_string(session.SourceAppUserModelId());
|
||||
|
||||
auto playbackInfo = session.GetPlaybackInfo();
|
||||
info.playbackStatus = playbackInfo.PlaybackStatus();
|
||||
|
||||
auto props = session.TryGetMediaPropertiesAsync().get();
|
||||
if (props) {
|
||||
info.title = winrt::to_string(props.Title());
|
||||
info.artist = winrt::to_string(props.Artist());
|
||||
info.album = winrt::to_string(props.AlbumTitle());
|
||||
}
|
||||
} catch (const winrt::hresult_error &e) {
|
||||
blog(LOG_WARNING, "now playing: WinRT error 0x%08X",
|
||||
static_cast<uint32_t>(e.code()));
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
static std::string PlaybackStatusToString(
|
||||
GlobalSystemMediaTransportControlsSessionPlaybackStatus status)
|
||||
{
|
||||
switch (status) {
|
||||
case GlobalSystemMediaTransportControlsSessionPlaybackStatus::Playing:
|
||||
return "Playing";
|
||||
case GlobalSystemMediaTransportControlsSessionPlaybackStatus::Paused:
|
||||
return "Paused";
|
||||
case GlobalSystemMediaTransportControlsSessionPlaybackStatus::Stopped:
|
||||
return "Stopped";
|
||||
case GlobalSystemMediaTransportControlsSessionPlaybackStatus::Opened:
|
||||
return "Opening";
|
||||
case GlobalSystemMediaTransportControlsSessionPlaybackStatus::Changing:
|
||||
return "Changing";
|
||||
default:
|
||||
return "Closed";
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
bool MacroConditionNowPlaying::CheckCondition()
|
||||
{
|
||||
const auto info = getCurrentSessionInfo();
|
||||
|
||||
SetTempVarValue("title", info.title);
|
||||
SetTempVarValue("artist", info.artist);
|
||||
SetTempVarValue("album", info.album);
|
||||
SetTempVarValue("appName", info.appName);
|
||||
SetTempVarValue("playbackStatus",
|
||||
PlaybackStatusToString(info.playbackStatus));
|
||||
|
||||
if (!info.hasSession) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto textMatches = [this](const std::string &field) -> bool {
|
||||
const QString pattern = QString::fromStdString(_matchText);
|
||||
const QString value = QString::fromStdString(field);
|
||||
if (_regex.Enabled()) {
|
||||
return _regex.Matches(value, pattern);
|
||||
}
|
||||
return value == pattern;
|
||||
};
|
||||
|
||||
switch (_checkType) {
|
||||
case CheckType::PLAYBACK_STATE: {
|
||||
using S =
|
||||
GlobalSystemMediaTransportControlsSessionPlaybackStatus;
|
||||
switch (_playbackState) {
|
||||
case PlaybackState::PLAYING:
|
||||
return info.playbackStatus == S::Playing;
|
||||
case PlaybackState::PAUSED:
|
||||
return info.playbackStatus == S::Paused;
|
||||
case PlaybackState::STOPPED:
|
||||
return info.playbackStatus == S::Stopped;
|
||||
case PlaybackState::OPENING:
|
||||
return info.playbackStatus == S::Opened;
|
||||
case PlaybackState::CHANGING:
|
||||
return info.playbackStatus == S::Changing;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CheckType::TITLE:
|
||||
return textMatches(info.title);
|
||||
case CheckType::ARTIST:
|
||||
return textMatches(info.artist);
|
||||
case CheckType::ALBUM:
|
||||
return textMatches(info.album);
|
||||
case CheckType::APP_NAME:
|
||||
return textMatches(info.appName);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MacroConditionNowPlaying::Save(obs_data_t *obj) const
|
||||
{
|
||||
MacroCondition::Save(obj);
|
||||
obs_data_set_int(obj, "checkType", static_cast<int>(_checkType));
|
||||
obs_data_set_int(obj, "playbackState",
|
||||
static_cast<int>(_playbackState));
|
||||
_matchText.Save(obj, "matchText");
|
||||
_regex.Save(obj);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MacroConditionNowPlaying::Load(obs_data_t *obj)
|
||||
{
|
||||
MacroCondition::Load(obj);
|
||||
_checkType = static_cast<CheckType>(obs_data_get_int(obj, "checkType"));
|
||||
_playbackState = static_cast<PlaybackState>(
|
||||
obs_data_get_int(obj, "playbackState"));
|
||||
_matchText.Load(obj, "matchText");
|
||||
_regex.Load(obj);
|
||||
return true;
|
||||
}
|
||||
|
||||
void MacroConditionNowPlaying::SetupTempVars()
|
||||
{
|
||||
AddTempvar(
|
||||
"title",
|
||||
obs_module_text("AdvSceneSwitcher.tempVar.nowPlaying.title"));
|
||||
AddTempvar(
|
||||
"artist",
|
||||
obs_module_text("AdvSceneSwitcher.tempVar.nowPlaying.artist"));
|
||||
AddTempvar(
|
||||
"album",
|
||||
obs_module_text("AdvSceneSwitcher.tempVar.nowPlaying.album"));
|
||||
AddTempvar(
|
||||
"appName",
|
||||
obs_module_text("AdvSceneSwitcher.tempVar.nowPlaying.appName"));
|
||||
AddTempvar(
|
||||
"playbackStatus",
|
||||
obs_module_text(
|
||||
"AdvSceneSwitcher.tempVar.nowPlaying.playbackStatus"));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
static void populateCheckTypeSelection(QComboBox *list)
|
||||
{
|
||||
static const std::map<MacroConditionNowPlaying::CheckType, std::string> checkTypes = {
|
||||
{MacroConditionNowPlaying::CheckType::PLAYBACK_STATE,
|
||||
"AdvSceneSwitcher.condition.nowPlaying.checkType.playbackState"},
|
||||
{MacroConditionNowPlaying::CheckType::TITLE,
|
||||
"AdvSceneSwitcher.condition.nowPlaying.checkType.title"},
|
||||
{MacroConditionNowPlaying::CheckType::ARTIST,
|
||||
"AdvSceneSwitcher.condition.nowPlaying.checkType.artist"},
|
||||
{MacroConditionNowPlaying::CheckType::ALBUM,
|
||||
"AdvSceneSwitcher.condition.nowPlaying.checkType.album"},
|
||||
{MacroConditionNowPlaying::CheckType::APP_NAME,
|
||||
"AdvSceneSwitcher.condition.nowPlaying.checkType.appName"},
|
||||
};
|
||||
|
||||
for (const auto &[type, name] : checkTypes) {
|
||||
list->addItem(obs_module_text(name.c_str()),
|
||||
static_cast<int>(type));
|
||||
}
|
||||
}
|
||||
|
||||
static void populatePlaybackStateSelection(QComboBox *list)
|
||||
{
|
||||
static const std::map<MacroConditionNowPlaying::PlaybackState, std::string> playbackStates = {
|
||||
{MacroConditionNowPlaying::PlaybackState::PLAYING,
|
||||
"AdvSceneSwitcher.condition.nowPlaying.playbackState.playing"},
|
||||
{MacroConditionNowPlaying::PlaybackState::PAUSED,
|
||||
"AdvSceneSwitcher.condition.nowPlaying.playbackState.paused"},
|
||||
{MacroConditionNowPlaying::PlaybackState::STOPPED,
|
||||
"AdvSceneSwitcher.condition.nowPlaying.playbackState.stopped"},
|
||||
{MacroConditionNowPlaying::PlaybackState::OPENING,
|
||||
"AdvSceneSwitcher.condition.nowPlaying.playbackState.opening"},
|
||||
{MacroConditionNowPlaying::PlaybackState::CHANGING,
|
||||
"AdvSceneSwitcher.condition.nowPlaying.playbackState.changing"},
|
||||
};
|
||||
|
||||
for (const auto &[state, name] : playbackStates) {
|
||||
list->addItem(obs_module_text(name.c_str()),
|
||||
static_cast<int>(state));
|
||||
}
|
||||
}
|
||||
|
||||
MacroConditionNowPlayingEdit::MacroConditionNowPlayingEdit(
|
||||
QWidget *parent, std::shared_ptr<MacroConditionNowPlaying> entryData)
|
||||
: QWidget(parent),
|
||||
_checkType(new QComboBox(this)),
|
||||
_playbackState(new QComboBox(this)),
|
||||
_matchText(new VariableLineEdit(this)),
|
||||
_regex(new RegexConfigWidget(this))
|
||||
{
|
||||
populateCheckTypeSelection(_checkType);
|
||||
populatePlaybackStateSelection(_playbackState);
|
||||
|
||||
connect(_checkType, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
||||
this, &MacroConditionNowPlayingEdit::CheckTypeChanged);
|
||||
connect(_playbackState,
|
||||
QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
||||
&MacroConditionNowPlayingEdit::PlaybackStateChanged);
|
||||
connect(_matchText, &VariableLineEdit::textEdited, this,
|
||||
&MacroConditionNowPlayingEdit::MatchTextChanged);
|
||||
connect(_regex, &RegexConfigWidget::RegexConfigChanged, this,
|
||||
&MacroConditionNowPlayingEdit::RegexChanged);
|
||||
|
||||
_layout = new QHBoxLayout();
|
||||
_layout->addWidget(_checkType);
|
||||
_layout->addWidget(_playbackState);
|
||||
_layout->addWidget(_matchText);
|
||||
_layout->addWidget(_regex);
|
||||
setLayout(_layout);
|
||||
|
||||
_entryData = entryData;
|
||||
UpdateEntryData();
|
||||
_loading = false;
|
||||
}
|
||||
|
||||
void MacroConditionNowPlayingEdit::UpdateEntryData()
|
||||
{
|
||||
if (!_entryData) {
|
||||
return;
|
||||
}
|
||||
|
||||
_checkType->setCurrentIndex(
|
||||
_checkType->findData(static_cast<int>(_entryData->_checkType)));
|
||||
_playbackState->setCurrentIndex(_playbackState->findData(
|
||||
static_cast<int>(_entryData->_playbackState)));
|
||||
_matchText->setText(QString::fromStdString(_entryData->_matchText));
|
||||
_regex->SetRegexConfig(_entryData->_regex);
|
||||
|
||||
SetWidgetVisibility();
|
||||
}
|
||||
|
||||
void MacroConditionNowPlayingEdit::CheckTypeChanged(int)
|
||||
{
|
||||
GUARD_LOADING_AND_LOCK();
|
||||
_entryData->_checkType =
|
||||
static_cast<MacroConditionNowPlaying::CheckType>(
|
||||
_checkType->currentData().toInt());
|
||||
SetWidgetVisibility();
|
||||
}
|
||||
|
||||
void MacroConditionNowPlayingEdit::PlaybackStateChanged(int)
|
||||
{
|
||||
GUARD_LOADING_AND_LOCK();
|
||||
_entryData->_playbackState =
|
||||
static_cast<MacroConditionNowPlaying::PlaybackState>(
|
||||
_playbackState->currentData().toInt());
|
||||
}
|
||||
|
||||
void MacroConditionNowPlayingEdit::MatchTextChanged(const QString &text)
|
||||
{
|
||||
GUARD_LOADING_AND_LOCK();
|
||||
_entryData->_matchText = text.toStdString();
|
||||
}
|
||||
|
||||
void MacroConditionNowPlayingEdit::RegexChanged(const RegexConfig ®ex)
|
||||
{
|
||||
GUARD_LOADING_AND_LOCK();
|
||||
_entryData->_regex = regex;
|
||||
}
|
||||
|
||||
void MacroConditionNowPlayingEdit::SetWidgetVisibility()
|
||||
{
|
||||
const bool isStateCheck =
|
||||
_entryData->_checkType ==
|
||||
MacroConditionNowPlaying::CheckType::PLAYBACK_STATE;
|
||||
_playbackState->setVisible(isStateCheck);
|
||||
_matchText->setVisible(!isStateCheck);
|
||||
_regex->setVisible(!isStateCheck);
|
||||
|
||||
if (isStateCheck) {
|
||||
AddStretchIfNecessary(_layout);
|
||||
} else {
|
||||
RemoveStretchIfPresent(_layout);
|
||||
}
|
||||
|
||||
adjustSize();
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
} // namespace advss
|
||||
@@ -1,86 +0,0 @@
|
||||
#pragma once
|
||||
#include "macro-condition-edit.hpp"
|
||||
#include "regex-config.hpp"
|
||||
#include "variable-line-edit.hpp"
|
||||
|
||||
#include <QComboBox>
|
||||
|
||||
namespace advss {
|
||||
|
||||
class MacroConditionNowPlaying : public MacroCondition {
|
||||
public:
|
||||
enum class CheckType {
|
||||
PLAYBACK_STATE,
|
||||
TITLE,
|
||||
ARTIST,
|
||||
ALBUM,
|
||||
APP_NAME,
|
||||
};
|
||||
|
||||
enum class PlaybackState {
|
||||
PLAYING,
|
||||
PAUSED,
|
||||
STOPPED,
|
||||
OPENING,
|
||||
CHANGING,
|
||||
};
|
||||
|
||||
MacroConditionNowPlaying(Macro *m) : MacroCondition(m) {}
|
||||
bool CheckCondition();
|
||||
bool Save(obs_data_t *obj) const;
|
||||
bool Load(obs_data_t *obj);
|
||||
std::string GetId() const { return id; }
|
||||
static std::shared_ptr<MacroCondition> Create(Macro *m)
|
||||
{
|
||||
return std::make_shared<MacroConditionNowPlaying>(m);
|
||||
}
|
||||
|
||||
CheckType _checkType = CheckType::PLAYBACK_STATE;
|
||||
PlaybackState _playbackState = PlaybackState::PLAYING;
|
||||
StringVariable _matchText;
|
||||
RegexConfig _regex;
|
||||
|
||||
private:
|
||||
void SetupTempVars();
|
||||
|
||||
static bool _registered;
|
||||
static const std::string id;
|
||||
};
|
||||
|
||||
class MacroConditionNowPlayingEdit : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MacroConditionNowPlayingEdit(
|
||||
QWidget *parent,
|
||||
std::shared_ptr<MacroConditionNowPlaying> cond = nullptr);
|
||||
void UpdateEntryData();
|
||||
static QWidget *Create(QWidget *parent,
|
||||
std::shared_ptr<MacroCondition> cond)
|
||||
{
|
||||
return new MacroConditionNowPlayingEdit(
|
||||
parent,
|
||||
std::dynamic_pointer_cast<MacroConditionNowPlaying>(
|
||||
cond));
|
||||
}
|
||||
|
||||
private slots:
|
||||
void CheckTypeChanged(int);
|
||||
void PlaybackStateChanged(int);
|
||||
void MatchTextChanged(const QString &);
|
||||
void RegexChanged(const RegexConfig &);
|
||||
|
||||
private:
|
||||
void SetWidgetVisibility();
|
||||
|
||||
QHBoxLayout *_layout;
|
||||
QComboBox *_checkType;
|
||||
QComboBox *_playbackState;
|
||||
VariableLineEdit *_matchText;
|
||||
RegexConfigWidget *_regex;
|
||||
|
||||
std::shared_ptr<MacroConditionNowPlaying> _entryData;
|
||||
bool _loading = true;
|
||||
};
|
||||
|
||||
} // namespace advss
|
||||
@@ -31,9 +31,14 @@ static bool setup()
|
||||
static const auto showInvalidWarnings = [](void *) {
|
||||
const auto invalidTokens = getInvalidTokens();
|
||||
for (const auto &token : invalidTokens) {
|
||||
QueueUITask([token]() {
|
||||
InvalidTokenDialog::ShowWarning(token);
|
||||
});
|
||||
QueueUITask(
|
||||
[](void *tokenPtr) {
|
||||
auto tokenName = static_cast<QString *>(
|
||||
tokenPtr);
|
||||
InvalidTokenDialog::ShowWarning(
|
||||
*tokenName);
|
||||
},
|
||||
(void *)&token);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ std::string GetThemeTypeName()
|
||||
return "Dark";
|
||||
}
|
||||
|
||||
void QueueUITaskRaw(void (*task)(void *param), void *, bool) {}
|
||||
void QueueUITask(void (*task)(void *param), void *) {}
|
||||
|
||||
QWidget *GetSettingsWindow()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user