Skip to content

Commit

Permalink
UI: Add chapter frontend API and hotkey
Browse files Browse the repository at this point in the history
  • Loading branch information
derrod committed May 5, 2024
1 parent a7d38b7 commit 928a327
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 1 deletion.
17 changes: 17 additions & 0 deletions UI/api-interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,23 @@ struct OBSStudioAPI : obs_frontend_callbacks {
}
}

bool obs_frontend_recording_add_chapter(const char *name) override
{
if (!os_atomic_load_bool(&recording_active) ||
os_atomic_load_bool(&recording_paused))
return false;

proc_handler_t *ph = obs_output_get_proc_handler(
main->outputHandler->fileOutput);

calldata cd;
calldata_init(&cd);
calldata_set_string(&cd, "chapter_name", name);
bool result = proc_handler_call(ph, "add_chapter", &cd);
calldata_free(&cd);
return result;
}

void obs_frontend_replay_buffer_start(void) override
{
QMetaObject::invokeMethod(main, "StartReplayBuffer");
Expand Down
1 change: 1 addition & 0 deletions UI/data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,7 @@ Basic.Main.StopRecording="Stop Recording"
Basic.Main.PauseRecording="Pause Recording"
Basic.Main.UnpauseRecording="Unpause Recording"
Basic.Main.SplitFile="Split Recording File"
Basic.Main.AddChapterMarker="Add Chapter Marker"
Basic.Main.StoppingRecording="Stopping Recording..."
Basic.Main.StopReplayBuffer="Stop Replay Buffer"
Basic.Main.StoppingReplayBuffer="Stopping Replay Buffer..."
Expand Down
6 changes: 6 additions & 0 deletions UI/obs-frontend-api/obs-frontend-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,12 @@ bool obs_frontend_recording_split_file(void)
: false;
}

bool obs_frontend_recording_add_chapter(const char *name)
{
return !!callbacks_valid() ? c->obs_frontend_recording_add_chapter(name)
: false;
}

void obs_frontend_replay_buffer_start(void)
{
if (callbacks_valid())
Expand Down
1 change: 1 addition & 0 deletions UI/obs-frontend-api/obs-frontend-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ EXPORT bool obs_frontend_recording_active(void);
EXPORT void obs_frontend_recording_pause(bool pause);
EXPORT bool obs_frontend_recording_paused(void);
EXPORT bool obs_frontend_recording_split_file(void);
EXPORT bool obs_frontend_recording_add_chapter(const char *name);

EXPORT void obs_frontend_replay_buffer_start(void);
EXPORT void obs_frontend_replay_buffer_save(void);
Expand Down
1 change: 1 addition & 0 deletions UI/obs-frontend-api/obs-frontend-internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ struct obs_frontend_callbacks {
virtual void obs_frontend_recording_pause(bool pause) = 0;
virtual bool obs_frontend_recording_paused(void) = 0;
virtual bool obs_frontend_recording_split_file(void) = 0;
virtual bool obs_frontend_recording_add_chapter(const char *name) = 0;

virtual void obs_frontend_replay_buffer_start(void) = 0;
virtual void obs_frontend_replay_buffer_save(void) = 0;
Expand Down
18 changes: 18 additions & 0 deletions UI/window-basic-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2796,6 +2796,23 @@ void OBSBasic::CreateHotkeys()
this);
LoadHotkey(splitFileHotkey, "OBSBasic.SplitFile");

/* Adding chapters is only supported by the native MP4 output */
const string_view output_id =
obs_output_get_id(outputHandler->fileOutput);
if (output_id == "mp4_output") {
addChapterHotkey = obs_hotkey_register_frontend(
"OBSBasic.AddChapterMarker",
Str("Basic.Main.AddChapterMarker"),
[](void *, obs_hotkey_id, obs_hotkey_t *,
bool pressed) {
if (pressed)
obs_frontend_recording_add_chapter(
nullptr);
},
this);
LoadHotkey(addChapterHotkey, "OBSBasic.AddChapterMarker");
}

replayBufHotkeys = obs_hotkey_pair_register_frontend(
"OBSBasic.StartReplayBuffer",
Str("Basic.Main.StartReplayBuffer"),
Expand Down Expand Up @@ -2924,6 +2941,7 @@ void OBSBasic::ClearHotkeys()
obs_hotkey_pair_unregister(recordingHotkeys);
obs_hotkey_pair_unregister(pauseHotkeys);
obs_hotkey_unregister(splitFileHotkey);
obs_hotkey_unregister(addChapterHotkey);
obs_hotkey_pair_unregister(replayBufHotkeys);
obs_hotkey_pair_unregister(vcamHotkeys);
obs_hotkey_pair_unregister(togglePreviewHotkeys);
Expand Down
3 changes: 2 additions & 1 deletion UI/window-basic-main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,8 @@ class OBSBasic : public OBSMainWindow {
obs_hotkey_pair_id streamingHotkeys, recordingHotkeys, pauseHotkeys,
replayBufHotkeys, vcamHotkeys, togglePreviewHotkeys,
contextBarHotkeys;
obs_hotkey_id forceStreamingStopHotkey, splitFileHotkey;
obs_hotkey_id forceStreamingStopHotkey, splitFileHotkey,
addChapterHotkey;

void InitDefaultTransitions();
void InitTransition(obs_source_t *transition);
Expand Down

0 comments on commit 928a327

Please sign in to comment.