Ability to get and set transition duration

This commit is contained in:
Palakis 2017-02-27 11:53:44 +01:00
parent 0d495f4d65
commit 42a80c6185
5 changed files with 60 additions and 0 deletions

View File

@ -43,6 +43,7 @@ The protocol in general is based on the OBS Remote protocol created by Bill Hami
- ["GetTransitionList"](#gettransitionlist)
- ["GetCurrentTransition"](#getcurrenttransition)
- ["SetCurrentTransition"](#setcurrenttransition)
- ["SetTransitionDuration"](#settransitionduration)
- ["SetVolume"](#setvolume)
- ["GetVolume"](#getvolume)
- ["SetMute"](#setmute)
@ -328,6 +329,7 @@ Get the name of the currently selected transition in the frontend's dropdown men
__Request fields__ : none
__Response__ : always OK, with these additional fields :
- **"name"** (string) : name of the selected transition
- **"duration"** (integer, only if transition supports this) : transition duration
*New in OBS Studio*
@ -343,6 +345,18 @@ __Response__ : OK if specified transition exists, error otherwise.
---
#### "SetTransitionDuration"
Set the duration of the currently selected transition.
__Request fields__ :
- **"duration"** (integer) : desired transition duration in milliseconds
__Response__ : always OK.
*New in OBS Studio*
---
#### "SetVolume"
Set the volume of a specific source.

View File

@ -18,6 +18,8 @@ with this program. If not, see <https://www.gnu.org/licenses/>
#include "Utils.h"
#include <obs-frontend-api.h>
#include <QMainWindow>
#include <QSpinBox>
#include "obs-websocket.h"
obs_data_array_t* string_list_to_array(char** strings, char* key)
@ -207,6 +209,32 @@ obs_data_array_t* Utils::GetProfiles()
return list;
}
int Utils::GetTransitionDuration()
{
QMainWindow *window = (QMainWindow*)obs_frontend_get_main_window();
QSpinBox* durationControl = window->findChild<QSpinBox*>("transitionDuration");
if (durationControl)
{
return durationControl->value();
}
else
{
return -1;
}
}
void Utils::SetTransitionDuration(int ms)
{
QMainWindow *window = (QMainWindow*)obs_frontend_get_main_window();
QSpinBox* durationControl = window->findChild<QSpinBox*>("transitionDuration");
if (durationControl && ms >= 0)
{
durationControl->setValue(ms);
}
}
const char* Utils::OBSVersionString() {
uint32_t version = obs_get_version();

View File

@ -37,6 +37,9 @@ class Utils
static obs_data_array_t* GetSceneCollections();
static obs_data_array_t* GetProfiles();
static int GetTransitionDuration();
static void SetTransitionDuration(int ms);
static const char* OBSVersionString();
};

View File

@ -49,6 +49,7 @@ WSRequestHandler::WSRequestHandler(QWebSocket *client) :
messageMap["GetTransitionList"] = WSRequestHandler::HandleGetTransitionList;
messageMap["GetCurrentTransition"] = WSRequestHandler::HandleGetCurrentTransition;
messageMap["SetCurrentTransition"] = WSRequestHandler::HandleSetCurrentTransition;
messageMap["SetTransitionDuration"] = WSRequestHandler::HandleSetTransitionDuration;
messageMap["SetVolume"] = WSRequestHandler::HandleSetVolume;
messageMap["GetVolume"] = WSRequestHandler::HandleGetVolume;
@ -359,6 +360,11 @@ void WSRequestHandler::HandleGetCurrentTransition(WSRequestHandler *owner)
obs_data_t *response = obs_data_create();
obs_data_set_string(response, "name", obs_source_get_name(current_transition));
if (!obs_transition_fixed(current_transition))
{
obs_data_set_int(response, "duration", Utils::GetTransitionDuration());
}
owner->SendOKResponse(response);
@ -384,6 +390,13 @@ void WSRequestHandler::HandleSetCurrentTransition(WSRequestHandler *owner)
}
}
void WSRequestHandler::HandleSetTransitionDuration(WSRequestHandler *owner)
{
int ms = obs_data_get_int(owner->_requestData, "duration");
Utils::SetTransitionDuration(ms);
owner->SendOKResponse();
}
void WSRequestHandler::HandleSetVolume(WSRequestHandler *owner)
{
const char *item_name = obs_data_get_string(owner->_requestData, "source");

View File

@ -78,6 +78,8 @@ class WSRequestHandler : public QObject
static void HandleSetCurrentProfile(WSRequestHandler *owner);
static void HandleGetCurrentProfile(WSRequestHandler *owner);
static void HandleListProfiles(WSRequestHandler *owner);
static void HandleSetTransitionDuration(WSRequestHandler *owner);
};
#endif // WSPROTOCOL_H