Skip to content

Commit 8306fbe

Browse files
committed
Add option to add new recording chapter
1 parent dfedbcf commit 8306fbe

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

data/locale/en-US.ini

+2-1
Original file line numberDiff line numberDiff line change
@@ -743,9 +743,10 @@ AdvSceneSwitcher.action.recording.type.unpause="Unpause recording"
743743
AdvSceneSwitcher.action.recording.type.split="Split recording file"
744744
AdvSceneSwitcher.action.recording.type.changeOutputFolder="Change output folder"
745745
AdvSceneSwitcher.action.recording.type.changeOutputFileFormat="Change filename formatting"
746+
AdvSceneSwitcher.action.recording.type.addChapter="Add chapter"
746747
AdvSceneSwitcher.action.recording.pause.hint="Note that depending on your recording settings you might not be able to pause recording"
747748
AdvSceneSwitcher.action.recording.split.hint="Make sure to enable automatic file splitting in the OBS settings first!"
748-
AdvSceneSwitcher.action.recording.entry="{{actions}}{{recordFolder}}{{recordFileFormat}}{{pauseHint}}{{splitHint}}"
749+
AdvSceneSwitcher.action.recording.entry="{{actions}}{{recordFolder}}{{recordFileFormat}}{{chapterName}}{{pauseHint}}{{splitHint}}"
749750
AdvSceneSwitcher.action.replay="Replay buffer"
750751
AdvSceneSwitcher.action.replay.saveWarn="Warning: Saving too frequently might result in the replay buffer not actually being saved!"
751752
AdvSceneSwitcher.action.replay.durationWarn="Warning: Changing the maximum replay time will only apply the next time the replay buffer is started!"

plugins/base/macro-action-recording.cpp

+33-12
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,18 @@ const static std::map<MacroActionRecord::Action, std::string> actionTypes = {
2222
"AdvSceneSwitcher.action.recording.type.pause"},
2323
{MacroActionRecord::Action::UNPAUSE,
2424
"AdvSceneSwitcher.action.recording.type.unpause"},
25+
#if LIBOBS_API_VER >= MAKE_SEMANTIC_VERSION(28, 0, 0)
2526
{MacroActionRecord::Action::SPLIT,
2627
"AdvSceneSwitcher.action.recording.type.split"},
28+
#endif
2729
{MacroActionRecord::Action::FOLDER,
2830
"AdvSceneSwitcher.action.recording.type.changeOutputFolder"},
2931
{MacroActionRecord::Action::FILE_FORMAT,
3032
"AdvSceneSwitcher.action.recording.type.changeOutputFileFormat"},
33+
#if LIBOBS_API_VER >= MAKE_SEMANTIC_VERSION(30, 2, 0)
34+
{MacroActionRecord::Action::ADD_CHAPTER,
35+
"AdvSceneSwitcher.action.recording.type.addChapter"},
36+
#endif
3137
};
3238

3339
bool MacroActionRecord::PerformAction()
@@ -86,6 +92,13 @@ bool MacroActionRecord::PerformAction()
8692
"failed to set recoding file format string");
8793
}
8894
break;
95+
#if LIBOBS_API_VER >= MAKE_SEMANTIC_VERSION(30, 2, 0)
96+
case Action::ADD_CHAPTER:
97+
if (!obs_frontend_recording_add_chapter(_chapterName.c_str())) {
98+
blog(LOG_WARNING, "failed to add recoding chapter!");
99+
}
100+
break;
101+
#endif
89102
}
90103
default:
91104
break;
@@ -110,6 +123,7 @@ bool MacroActionRecord::Save(obs_data_t *obj) const
110123
obs_data_set_int(obj, "action", static_cast<int>(_action));
111124
_folder.Save(obj, "folder");
112125
_fileFormat.Save(obj, "format");
126+
_chapterName.Save(obj, "chapterName");
113127
return true;
114128
}
115129

@@ -119,6 +133,7 @@ bool MacroActionRecord::Load(obs_data_t *obj)
119133
_action = static_cast<Action>(obs_data_get_int(obj, "action"));
120134
_folder.Load(obj, "folder");
121135
_fileFormat.Load(obj, "format");
136+
_chapterName.Load(obj, "chapterName");
122137
return true;
123138
}
124139

@@ -136,6 +151,7 @@ void MacroActionRecord::ResolveVariablesToFixedValues()
136151
{
137152
_folder.ResolveVariables();
138153
_fileFormat.ResolveVariables();
154+
_chapterName.ResolveVariables();
139155
}
140156

141157
static inline void populateActionSelection(QComboBox *list)
@@ -154,7 +170,8 @@ MacroActionRecordEdit::MacroActionRecordEdit(
154170
_splitHint(new QLabel(obs_module_text(
155171
"AdvSceneSwitcher.action.recording.split.hint"))),
156172
_recordFolder(new FileSelection(FileSelection::Type::FOLDER, this)),
157-
_recordFileFormat(new VariableLineEdit(this))
173+
_recordFileFormat(new VariableLineEdit(this)),
174+
_chapterName(new VariableLineEdit(this))
158175
{
159176
populateActionSelection(_actions);
160177

@@ -164,6 +181,8 @@ MacroActionRecordEdit::MacroActionRecordEdit(
164181
this, SLOT(FolderChanged(const QString &)));
165182
QWidget::connect(_recordFileFormat, SIGNAL(editingFinished()), this,
166183
SLOT(FormatStringChanged()));
184+
QWidget::connect(_chapterName, SIGNAL(editingFinished()), this,
185+
SLOT(ChapterNameChanged()));
167186

168187
auto mainLayout = new QHBoxLayout;
169188
PlaceWidgets(obs_module_text("AdvSceneSwitcher.action.recording.entry"),
@@ -172,7 +191,8 @@ MacroActionRecordEdit::MacroActionRecordEdit(
172191
{"{{pauseHint}}", _pauseHint},
173192
{"{{splitHint}}", _splitHint},
174193
{"{{recordFolder}}", _recordFolder},
175-
{"{{recordFileFormat}}", _recordFileFormat}});
194+
{"{{recordFileFormat}}", _recordFileFormat},
195+
{"{{chapterName}}", _chapterName}});
176196
setLayout(mainLayout);
177197

178198
_entryData = entryData;
@@ -188,6 +208,7 @@ void MacroActionRecordEdit::UpdateEntryData()
188208
_actions->setCurrentIndex(static_cast<int>(_entryData->_action));
189209
_recordFolder->SetPath(_entryData->_folder);
190210
_recordFileFormat->setText(_entryData->_fileFormat);
211+
_chapterName->setText(_entryData->_chapterName);
191212
SetWidgetVisibility();
192213
}
193214

@@ -199,24 +220,22 @@ static bool isPauseAction(MacroActionRecord::Action a)
199220

200221
void MacroActionRecordEdit::FolderChanged(const QString &folder)
201222
{
202-
if (_loading || !_entryData) {
203-
return;
204-
}
205-
206-
auto lock = LockContext();
223+
GUARD_LOADING_AND_LOCK();
207224
_entryData->_folder = folder.toStdString();
208225
}
209226

210227
void MacroActionRecordEdit::FormatStringChanged()
211228
{
212-
if (_loading || !_entryData) {
213-
return;
214-
}
215-
216-
auto lock = LockContext();
229+
GUARD_LOADING_AND_LOCK();
217230
_entryData->_fileFormat = _recordFileFormat->text().toStdString();
218231
}
219232

233+
void MacroActionRecordEdit::ChapterNameChanged()
234+
{
235+
GUARD_LOADING_AND_LOCK();
236+
_entryData->_chapterName = _chapterName->text().toStdString();
237+
}
238+
220239
void MacroActionRecordEdit::SetWidgetVisibility()
221240
{
222241
_pauseHint->setVisible(isPauseAction(_entryData->_action));
@@ -226,6 +245,8 @@ void MacroActionRecordEdit::SetWidgetVisibility()
226245
MacroActionRecord::Action::FOLDER);
227246
_recordFileFormat->setVisible(_entryData->_action ==
228247
MacroActionRecord::Action::FILE_FORMAT);
248+
_chapterName->setVisible(_entryData->_action ==
249+
MacroActionRecord::Action::ADD_CHAPTER);
229250
}
230251

231252
void MacroActionRecordEdit::ActionChanged(int value)

plugins/base/macro-action-recording.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ class MacroActionRecord : public MacroAction {
2929
SPLIT,
3030
FOLDER,
3131
FILE_FORMAT,
32+
ADD_CHAPTER,
3233
};
3334
Action _action = Action::STOP;
3435

3536
StringVariable _folder = QDir::homePath().toStdString() + "/Videos";
3637
StringVariable _fileFormat = "%CCYY-%MM-%DD %hh-%mm-%ss";
38+
StringVariable _chapterName = "";
3739

3840
private:
3941
static bool _registered;
@@ -60,13 +62,15 @@ private slots:
6062
void ActionChanged(int value);
6163
void FolderChanged(const QString &);
6264
void FormatStringChanged();
65+
void ChapterNameChanged();
6366

6467
protected:
6568
QComboBox *_actions;
6669
QLabel *_pauseHint;
6770
QLabel *_splitHint;
6871
FileSelection *_recordFolder;
6972
VariableLineEdit *_recordFileFormat;
73+
VariableLineEdit *_chapterName;
7074
std::shared_ptr<MacroActionRecord> _entryData;
7175

7276
private:

0 commit comments

Comments
 (0)