Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Events: Add from and to scene names to transition events #1229

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 44 additions & 6 deletions src/eventhandler/EventHandler_Transitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,32 @@ void EventHandler::HandleCurrentSceneTransitionDurationChanged()
BroadcastEvent(EventSubscription::Transitions, "CurrentSceneTransitionDurationChanged", eventData);
}

void SetFromAndToScene(json &eventData, obs_source_t *transition)
{
OBSSourceAutoRelease sourceScene = obs_transition_get_source(transition, OBS_TRANSITION_SOURCE_A);
OBSSourceAutoRelease destinationScene = obs_transition_get_source(transition, OBS_TRANSITION_SOURCE_B);

eventData["fromScene"] = obs_source_get_name(sourceScene);
eventData["toScene"] = obs_source_get_name(destinationScene);
}

// FIXME: OBS bug causes source B to be null for transition end but not video transition end.
// Needs to be fixed in obs itself
void SetToScene(json &eventData, obs_source_t *transition)
{
OBSSourceAutoRelease sourceScene = obs_transition_get_source(transition, OBS_TRANSITION_SOURCE_A);

eventData["toScene"] = obs_source_get_name(sourceScene);
}

/**
* A scene transition has started.
*
* @dataField transitionName | String | Scene transition name
* @dataField transitionUuid | String | Scene transition UUID
* @dataField transitionName | String | Scene transition name
* @dataField transitionUuid | String | Scene transition UUID
* @dataField transitionDuration | Number | Transition duration in milliseconds
* @dataField toScene | String | Scene that we transitioned to
* @dataField fromScene | String | Scene that we transitioned away from
*
* @eventType SceneTransitionStarted
* @eventSubscription Transitions
Expand All @@ -88,6 +109,10 @@ void EventHandler::HandleSceneTransitionStarted(void *param, calldata_t *data)
json eventData;
eventData["transitionName"] = obs_source_get_name(source);
eventData["transitionUuid"] = obs_source_get_uuid(source);
eventData["transitionDuration"] = obs_frontend_get_transition_duration();

SetFromAndToScene(eventData, source);

eventHandler->BroadcastEvent(EventSubscription::Transitions, "SceneTransitionStarted", eventData);
}

Expand All @@ -96,8 +121,10 @@ void EventHandler::HandleSceneTransitionStarted(void *param, calldata_t *data)
*
* Note: Does not appear to trigger when the transition is interrupted by the user.
*
* @dataField transitionName | String | Scene transition name
* @dataField transitionUuid | String | Scene transition UUID
* @dataField transitionName | String | Scene transition name
* @dataField transitionUuid | String | Scene transition UUID
* @dataField transitionDuration | Number | Transition duration in milliseconds
* @dataField toScene | String | Scene that we transitioned to
*
* @eventType SceneTransitionEnded
* @eventSubscription Transitions
Expand All @@ -118,6 +145,10 @@ void EventHandler::HandleSceneTransitionEnded(void *param, calldata_t *data)
json eventData;
eventData["transitionName"] = obs_source_get_name(source);
eventData["transitionUuid"] = obs_source_get_uuid(source);
eventData["transitionDuration"] = obs_frontend_get_transition_duration();

SetToScene(eventData, source);

eventHandler->BroadcastEvent(EventSubscription::Transitions, "SceneTransitionEnded", eventData);
}

Expand All @@ -129,8 +160,11 @@ void EventHandler::HandleSceneTransitionEnded(void *param, calldata_t *data)
*
* Note: Appears to be called by every transition, regardless of relevance.
*
* @dataField transitionName | String | Scene transition name
* @dataField transitionUuid | String | Scene transition UUID
* @dataField transitionName | String | Scene transition name
* @dataField transitionUuid | String | Scene transition UUID
* @dataField transitionDuration | Number | Transition duration in milliseconds
* @dataField toScene | String | Scene that we transitioned to
* @dataField fromScene | String | Scene that we transitioned away from
*
* @eventType SceneTransitionVideoEnded
* @eventSubscription Transitions
Expand All @@ -151,5 +185,9 @@ void EventHandler::HandleSceneTransitionVideoEnded(void *param, calldata_t *data
json eventData;
eventData["transitionName"] = obs_source_get_name(source);
eventData["transitionUuid"] = obs_source_get_uuid(source);
eventData["transitionDuration"] = obs_frontend_get_transition_duration();

SetFromAndToScene(eventData, source);

eventHandler->BroadcastEvent(EventSubscription::Transitions, "SceneTransitionVideoEnded", eventData);
}