mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
Add ability to specify a transition when calling TransitionToProgram
This commit is contained in:
parent
5748e163f8
commit
a6677edbf5
10
PROTOCOL.md
10
PROTOCOL.md
@ -377,8 +377,14 @@ __Response__ : OK if specified scene exists, error otherwise.
|
|||||||
#### "TransitionToProgram"
|
#### "TransitionToProgram"
|
||||||
Studio Mode only. Transitions the currently previewed scene to Program (main output).
|
Studio Mode only. Transitions the currently previewed scene to Program (main output).
|
||||||
|
|
||||||
__Request fields__ : none
|
__Request fields__ :
|
||||||
__Response__ : always OK. No additional fields.
|
- **"with-transition" (object, optional) : if specified, use this transition when switching from preview to program. This will change the current transition in the frontend to this one.
|
||||||
|
|
||||||
|
__Response__ : always OK. No additional fields
|
||||||
|
|
||||||
|
An object passed as `"with-transition"` in a request must have the following fields :
|
||||||
|
- **"name"** (string) : transition name
|
||||||
|
- **"duration"** (integer, optional) : transition duration in milliseconds
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
17
Utils.cpp
17
Utils.cpp
@ -241,6 +241,23 @@ void Utils::SetTransitionDuration(int ms)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Utils::SetTransitionByName(const char* transition_name)
|
||||||
|
{
|
||||||
|
obs_source_t *transition = GetTransitionFromName(transition_name);
|
||||||
|
|
||||||
|
if (transition)
|
||||||
|
{
|
||||||
|
obs_frontend_set_current_transition(transition);
|
||||||
|
obs_source_release(transition);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QPushButton* Utils::GetPreviewModeButtonControl()
|
QPushButton* Utils::GetPreviewModeButtonControl()
|
||||||
{
|
{
|
||||||
QMainWindow* main = (QMainWindow*)obs_frontend_get_main_window();
|
QMainWindow* main = (QMainWindow*)obs_frontend_get_main_window();
|
||||||
|
2
Utils.h
2
Utils.h
@ -45,6 +45,8 @@ class Utils
|
|||||||
static int GetTransitionDuration();
|
static int GetTransitionDuration();
|
||||||
static void SetTransitionDuration(int ms);
|
static void SetTransitionDuration(int ms);
|
||||||
|
|
||||||
|
static bool SetTransitionByName(const char* transition_name);
|
||||||
|
|
||||||
static QPushButton* GetPreviewModeButtonControl();
|
static QPushButton* GetPreviewModeButtonControl();
|
||||||
static QLayout* GetPreviewLayout();
|
static QLayout* GetPreviewLayout();
|
||||||
static QListWidget* GetSceneListControl();
|
static QListWidget* GetSceneListControl();
|
||||||
|
@ -437,19 +437,13 @@ void WSRequestHandler::HandleGetCurrentTransition(WSRequestHandler *owner)
|
|||||||
void WSRequestHandler::HandleSetCurrentTransition(WSRequestHandler *owner)
|
void WSRequestHandler::HandleSetCurrentTransition(WSRequestHandler *owner)
|
||||||
{
|
{
|
||||||
const char *name = obs_data_get_string(owner->_requestData, "transition-name");
|
const char *name = obs_data_get_string(owner->_requestData, "transition-name");
|
||||||
obs_source_t *transition = Utils::GetTransitionFromName(name);
|
|
||||||
|
|
||||||
if (transition)
|
bool success = Utils::SetTransitionByName(name);
|
||||||
{
|
|
||||||
obs_frontend_set_current_transition(transition);
|
if (success)
|
||||||
owner->SendOKResponse();
|
owner->SendOKResponse();
|
||||||
|
|
||||||
obs_source_release(transition);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
owner->SendErrorResponse("requested transition does not exist");
|
owner->SendErrorResponse("requested transition does not exist");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WSRequestHandler::HandleSetTransitionDuration(WSRequestHandler *owner)
|
void WSRequestHandler::HandleSetTransitionDuration(WSRequestHandler *owner)
|
||||||
@ -808,6 +802,30 @@ void WSRequestHandler::HandleSetPreviewScene(WSRequestHandler *owner)
|
|||||||
|
|
||||||
void WSRequestHandler::HandleTransitionToProgram(WSRequestHandler *owner)
|
void WSRequestHandler::HandleTransitionToProgram(WSRequestHandler *owner)
|
||||||
{
|
{
|
||||||
|
obs_data_t* transitionInfo = obs_data_get_obj(owner->_requestData, "with-transition");
|
||||||
|
|
||||||
|
if (transitionInfo)
|
||||||
|
{
|
||||||
|
const char* transitionName = obs_data_get_string(transitionInfo, "name");
|
||||||
|
int transitionDuration = obs_data_get_int(transitionInfo, "duration");
|
||||||
|
|
||||||
|
if (!transitionName)
|
||||||
|
{
|
||||||
|
owner->SendErrorResponse("specified transition doesn't exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool success = Utils::SetTransitionByName(transitionName);
|
||||||
|
if (!success)
|
||||||
|
{
|
||||||
|
owner->SendErrorResponse("unknown error while trying to change current transition");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (transitionDuration > 0)
|
||||||
|
Utils::SetTransitionDuration(transitionDuration);
|
||||||
|
}
|
||||||
|
|
||||||
Utils::TransitionToProgram();
|
Utils::TransitionToProgram();
|
||||||
owner->SendOKResponse();
|
owner->SendOKResponse();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user