Merge pull request #899 from Palakis/preview-api

UI: Add functions and events for Studio Mode into the Frontend API
master
Jim 2017-06-27 19:39:53 -07:00 committed by GitHub
commit 27bb2f836d
5 changed files with 83 additions and 1 deletions

View File

@ -369,6 +369,37 @@ struct OBSStudioAPI : obs_frontend_callbacks {
main->SaveService();
}
bool obs_frontend_preview_program_mode_active(void) override
{
return main->IsPreviewProgramMode();
}
void obs_frontend_set_preview_program_mode(bool enable) override
{
main->SetPreviewProgramMode(enable);
}
obs_source_t *obs_frontend_get_current_preview_scene(void) override
{
OBSSource source = nullptr;
if (main->IsPreviewProgramMode()) {
source = main->GetCurrentSceneSource();
obs_source_addref(source);
}
return source;
}
void obs_frontend_set_current_preview_scene(obs_source_t *scene) override
{
if (main->IsPreviewProgramMode()) {
QMetaObject::invokeMethod(main, "SetCurrentScene",
Q_ARG(OBSSource, OBSSource(scene)),
Q_ARG(bool, false));
}
}
void on_load(obs_data_t *settings) override
{
for (auto cb : saveCallbacks)

View File

@ -336,3 +336,29 @@ void obs_frontend_save_streaming_service(void)
if (callbacks_valid())
c->obs_frontend_save_streaming_service();
}
bool obs_frontend_preview_program_mode_active(void)
{
return !!callbacks_valid()
? c->obs_frontend_preview_program_mode_active()
: false;
}
void obs_frontend_set_preview_program_mode(bool enable)
{
if (callbacks_valid())
c->obs_frontend_set_preview_program_mode(enable);
}
obs_source_t *obs_frontend_get_current_preview_scene(void)
{
return !!callbacks_valid()
? c->obs_frontend_get_current_preview_scene()
: nullptr;
}
void obs_frontend_set_current_preview_scene(obs_source_t *scene)
{
if (callbacks_valid())
c->obs_frontend_set_current_preview_scene(scene);
}

View File

@ -103,7 +103,11 @@ enum obs_frontend_event {
OBS_FRONTEND_EVENT_REPLAY_BUFFER_STARTING,
OBS_FRONTEND_EVENT_REPLAY_BUFFER_STARTED,
OBS_FRONTEND_EVENT_REPLAY_BUFFER_STOPPING,
OBS_FRONTEND_EVENT_REPLAY_BUFFER_STOPPED
OBS_FRONTEND_EVENT_REPLAY_BUFFER_STOPPED,
OBS_FRONTEND_EVENT_STUDIO_MODE_ENABLED,
OBS_FRONTEND_EVENT_STUDIO_MODE_DISABLED,
OBS_FRONTEND_EVENT_PREVIEW_SCENE_CHANGED
};
typedef void (*obs_frontend_event_cb)(enum obs_frontend_event event,
@ -141,6 +145,12 @@ EXPORT void obs_frontend_set_streaming_service(obs_service_t *service);
EXPORT obs_service_t* obs_frontend_get_streaming_service(void);
EXPORT void obs_frontend_save_streaming_service(void);
EXPORT bool obs_frontend_preview_program_mode_active(void);
EXPORT void obs_frontend_set_preview_program_mode(bool enable);
EXPORT obs_source_t *obs_frontend_get_current_preview_scene(void);
EXPORT void obs_frontend_set_current_preview_scene(obs_source_t *scene);
/* ------------------------------------------------------------------------- */
#ifdef __cplusplus

View File

@ -75,6 +75,12 @@ struct obs_frontend_callbacks {
virtual obs_service_t *obs_frontend_get_streaming_service(void)=0;
virtual void obs_frontend_save_streaming_service()=0;
virtual bool obs_frontend_preview_program_mode_active(void)=0;
virtual void obs_frontend_set_preview_program_mode(bool enable)=0;
virtual obs_source_t *obs_frontend_get_current_preview_scene(void)=0;
virtual void obs_frontend_set_current_preview_scene(obs_source_t *scene)=0;
virtual void on_load(obs_data_t *settings)=0;
virtual void on_save(obs_data_t *settings)=0;
virtual void on_event(enum obs_frontend_event event)=0;

View File

@ -585,6 +585,9 @@ void OBSBasic::SetCurrentScene(OBSSource scene, bool force)
break;
}
}
if (api && IsPreviewProgramMode())
api->on_event(OBS_FRONTEND_EVENT_PREVIEW_SCENE_CHANGED);
}
UpdateSceneSelection(scene);
@ -1009,6 +1012,9 @@ void OBSBasic::SetPreviewProgramMode(bool enabled)
ui->previewLayout->addWidget(program);
program->show();
if (api)
api->on_event(OBS_FRONTEND_EVENT_STUDIO_MODE_ENABLED);
blog(LOG_INFO, "Switched to Preview/Program mode");
blog(LOG_INFO, "-----------------------------"
"-------------------");
@ -1039,6 +1045,9 @@ void OBSBasic::SetPreviewProgramMode(bool enabled)
if (!previewEnabled)
EnablePreviewDisplay(false);
if (api)
api->on_event(OBS_FRONTEND_EVENT_STUDIO_MODE_DISABLED);
blog(LOG_INFO, "Switched to regular Preview mode");
blog(LOG_INFO, "-----------------------------"
"-------------------");