mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
requesthandler: Finish transition requests
This commit is contained in:
parent
d9070f9edb
commit
9664f28483
@ -105,7 +105,9 @@ const std::unordered_map<std::string, RequestMethodHandler> RequestHandler::_han
|
||||
{"SetCurrentSceneTransition", &RequestHandler::SetCurrentSceneTransition},
|
||||
{"SetCurrentSceneTransitionDuration", &RequestHandler::SetCurrentSceneTransitionDuration},
|
||||
{"SetCurrentSceneTransitionSettings", &RequestHandler::SetCurrentSceneTransitionSettings},
|
||||
{"GetCurrentSceneTransitionCursor", &RequestHandler::GetCurrentSceneTransitionCursor},
|
||||
{"TriggerStudioModeTransition", &RequestHandler::TriggerStudioModeTransition},
|
||||
{"SetTBarPosition", &RequestHandler::SetTBarPosition},
|
||||
|
||||
// Filters
|
||||
{"GetSourceFilter", &RequestHandler::GetSourceFilter},
|
||||
|
@ -123,7 +123,9 @@ class RequestHandler {
|
||||
RequestResult SetCurrentSceneTransition(const Request&);
|
||||
RequestResult SetCurrentSceneTransitionDuration(const Request&);
|
||||
RequestResult SetCurrentSceneTransitionSettings(const Request&);
|
||||
RequestResult GetCurrentSceneTransitionCursor(const Request&);
|
||||
RequestResult TriggerStudioModeTransition(const Request&);
|
||||
RequestResult SetTBarPosition(const Request&);
|
||||
|
||||
// Filters
|
||||
RequestResult GetSourceFilter(const Request&);
|
||||
|
@ -17,6 +17,8 @@ You should have received a copy of the GNU General Public License along
|
||||
with this program. If not, see <https://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "RequestHandler.h"
|
||||
|
||||
/**
|
||||
@ -226,6 +228,32 @@ RequestResult RequestHandler::SetCurrentSceneTransitionSettings(const Request& r
|
||||
return RequestResult::Success();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cursor position of the current scene transition.
|
||||
*
|
||||
* Note: `transitionCursor` will return 1.0 when the transition is inactive.
|
||||
*
|
||||
* @responseField transitionCursor | Number | Cursor position, between 0.0 and 1.0
|
||||
*
|
||||
* @requestType GetCurrentSceneTransitionCursor
|
||||
* @complexity 2
|
||||
* @rpcVersion -1
|
||||
* @initialVersion 5.0.0
|
||||
* @api requests
|
||||
* @category transitions
|
||||
*/
|
||||
RequestResult RequestHandler::GetCurrentSceneTransitionCursor(const Request&)
|
||||
{
|
||||
OBSSourceAutoRelease transition = obs_frontend_get_current_transition();
|
||||
if (!transition)
|
||||
return RequestResult::Error(RequestStatus::InvalidResourceState, "OBS does not currently have a scene transition set."); // This should not happen!
|
||||
|
||||
json responseData;
|
||||
responseData["transitionCursor"] = obs_transition_get_time(transition);
|
||||
|
||||
return RequestResult::Success(responseData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers the current scene transition. Same functionality as the `Transition` button in studio mode.
|
||||
*
|
||||
@ -247,3 +275,48 @@ RequestResult RequestHandler::TriggerStudioModeTransition(const Request&)
|
||||
|
||||
return RequestResult::Success();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the position of the TBar.
|
||||
*
|
||||
* **Very important note**: This will be deprecated and replaced in a future version of obs-websocket.
|
||||
*
|
||||
* @requestField position | Number | New position | >= 0.0, <= 1.0
|
||||
* @requestField ?release | Boolean | Whether to release the TBar. Only set `false` if you know that you will be sending another position update | `true`
|
||||
*
|
||||
* @requestType SetTBarPosition
|
||||
* @complexity 3
|
||||
* @rpcVersion -1
|
||||
* @initialVersion 5.0.0
|
||||
* @api requests
|
||||
* @category transitions
|
||||
*/
|
||||
RequestResult RequestHandler::SetTBarPosition(const Request& request)
|
||||
{
|
||||
if (!obs_frontend_preview_program_mode_active())
|
||||
return RequestResult::Error(RequestStatus::StudioModeNotActive);
|
||||
|
||||
RequestStatus::RequestStatus statusCode;
|
||||
std::string comment;
|
||||
if (!request.ValidateNumber("position", statusCode, comment, 0.0, 1.0))
|
||||
return RequestResult::Error(statusCode, comment);
|
||||
|
||||
bool release = true;
|
||||
if (request.Contains("release")) {
|
||||
if (!request.ValidateOptionalBoolean("release", statusCode, comment))
|
||||
return RequestResult::Error(statusCode, comment);
|
||||
}
|
||||
|
||||
OBSSourceAutoRelease transition = obs_frontend_get_current_transition();
|
||||
if (!transition)
|
||||
return RequestResult::Error(RequestStatus::InvalidResourceState, "OBS does not currently have a scene transition set."); // This should not happen!
|
||||
|
||||
float position = request.RequestData["position"];
|
||||
|
||||
obs_frontend_set_tbar_position((int)round(position * 1024.0));
|
||||
|
||||
if (release)
|
||||
obs_frontend_release_tbar();
|
||||
|
||||
return RequestResult::Success();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user