diff --git a/PROTOCOL.md b/PROTOCOL.md index e39a3b8a..1b604979 100644 --- a/PROTOCOL.md +++ b/PROTOCOL.md @@ -14,6 +14,7 @@ The protocol in general is based on the OBS Remote protocol created by Bill Hami - ["SceneCollectionChanged"](#scenecollectionchanged) - ["SceneCollectionListChanged"](#scenecollectionlistchanged) - ["SwitchTransition"](#switchtransition) + - ["TransitionDurationChanged"](#transitiondurationchanged) - ["TransitionListChanged"](#transitionlistchanged) - ["ProfileChanged"](#profilechanged) - ["ProfileListChanged"](#profilelistchanged) @@ -94,6 +95,12 @@ The active transition has been changed. --- +#### "TransitionDurationChanged" +Triggered when the transition duration has changed. +- **"new-duration"** (integer) : new transition duration + +--- + #### "TransitionListChanged" The list of available transitions has been modified (Transitions have been added, removed, or renamed). diff --git a/Utils.cpp b/Utils.cpp index b1093ebd..0ac75611 100644 --- a/Utils.cpp +++ b/Utils.cpp @@ -209,14 +209,18 @@ obs_data_array_t* Utils::GetProfiles() return list; } -int Utils::GetTransitionDuration() +QSpinBox* Utils::GetTransitionDurationControl() { QMainWindow *window = (QMainWindow*)obs_frontend_get_main_window(); - QSpinBox* durationControl = window->findChild("transitionDuration"); + return window->findChild("transitionDuration"); +} - if (durationControl) +int Utils::GetTransitionDuration() +{ + QSpinBox* control = GetTransitionDurationControl(); + if (control) { - return durationControl->value(); + return control->value(); } else { @@ -226,12 +230,11 @@ int Utils::GetTransitionDuration() void Utils::SetTransitionDuration(int ms) { - QMainWindow *window = (QMainWindow*)obs_frontend_get_main_window(); - QSpinBox* durationControl = window->findChild("transitionDuration"); + QSpinBox* control = GetTransitionDurationControl(); - if (durationControl && ms >= 0) + if (control && ms >= 0) { - durationControl->setValue(ms); + control->setValue(ms); } } diff --git a/Utils.h b/Utils.h index 6e950661..91b22be7 100644 --- a/Utils.h +++ b/Utils.h @@ -19,6 +19,7 @@ with this program. If not, see #ifndef UTILS_H #define UTILS_H +#include #include #include @@ -37,6 +38,7 @@ class Utils static obs_data_array_t* GetSceneCollections(); static obs_data_array_t* GetProfiles(); + static QSpinBox* GetTransitionDurationControl(); static int GetTransitionDuration(); static void SetTransitionDuration(int ms); diff --git a/WSEvents.cpp b/WSEvents.cpp index 7a4f6af1..9ae977ca 100644 --- a/WSEvents.cpp +++ b/WSEvents.cpp @@ -19,7 +19,7 @@ with this program. If not, see #include #include - +#include "Utils.h" #include "WSEvents.h" WSEvents::WSEvents(WSServer *srv) @@ -27,6 +27,9 @@ WSEvents::WSEvents(WSServer *srv) _srv = srv; obs_frontend_add_event_callback(WSEvents::FrontendEventHandler, this); + QSpinBox* duration_control = Utils::GetTransitionDurationControl(); + connect(duration_control, SIGNAL(valueChanged(int)), this, SLOT(TransitionDurationChanged(int))); + QTimer *statusTimer = new QTimer(); connect(statusTimer, SIGNAL(timeout()), this, SLOT(StreamStatus())); statusTimer->start(2000); // equal to frontend's constant BITRATE_UPDATE_SECONDS @@ -340,3 +343,13 @@ void WSEvents::StreamStatus() obs_data_release(data); obs_output_release(stream_output); } + +void WSEvents::TransitionDurationChanged(int ms) +{ + obs_data_t* fields = obs_data_create(); + obs_data_set_int(fields, "new-duration", ms); + + broadcastUpdate("TransitionDurationChanged", fields); + + obs_data_release(fields); +} \ No newline at end of file diff --git a/WSEvents.h b/WSEvents.h index 38efd7da..3b0b65b0 100644 --- a/WSEvents.h +++ b/WSEvents.h @@ -21,7 +21,6 @@ with this program. If not, see #define WSEVENTS_H #include - #include "WSServer.h" class WSEvents : public QObject @@ -35,6 +34,7 @@ class WSEvents : public QObject private Q_SLOTS: void StreamStatus(); + void TransitionDurationChanged(int ms); private: WSServer *_srv;