mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-12-01 20:37:18 -06:00
Add toggle option to streaming, recording and replay buffer actions
This commit is contained in:
@@ -1032,6 +1032,7 @@ AdvSceneSwitcher.action.playAudio.mono="Mono"
|
||||
AdvSceneSwitcher.action.recording="Recording"
|
||||
AdvSceneSwitcher.action.recording.type.stop="Stop recording"
|
||||
AdvSceneSwitcher.action.recording.type.start="Start recording"
|
||||
AdvSceneSwitcher.action.recording.type.toggle="Toggle recording"
|
||||
AdvSceneSwitcher.action.recording.type.pause="Pause recording"
|
||||
AdvSceneSwitcher.action.recording.type.unpause="Unpause recording"
|
||||
AdvSceneSwitcher.action.recording.type.split="Split recording file"
|
||||
@@ -1047,12 +1048,14 @@ AdvSceneSwitcher.action.replay.saveWarn="Warning: Saving too frequently might re
|
||||
AdvSceneSwitcher.action.replay.durationWarn="Warning: Changing the maximum replay time will only apply the next time the replay buffer is started!"
|
||||
AdvSceneSwitcher.action.replay.type.stop="Stop replay buffer"
|
||||
AdvSceneSwitcher.action.replay.type.start="Start replay buffer"
|
||||
AdvSceneSwitcher.action.replay.type.toggle="Toggle replay buffer"
|
||||
AdvSceneSwitcher.action.replay.type.save="Save replay buffer"
|
||||
AdvSceneSwitcher.action.replay.type.duration="Set maximum replay time"
|
||||
AdvSceneSwitcher.action.replay.entry="{{actions}}{{duration}}"
|
||||
AdvSceneSwitcher.action.streaming="Streaming"
|
||||
AdvSceneSwitcher.action.streaming.type.stop="Stop streaming"
|
||||
AdvSceneSwitcher.action.streaming.type.start="Start streaming"
|
||||
AdvSceneSwitcher.action.streaming.type.toggle="Toggle streaming"
|
||||
AdvSceneSwitcher.action.streaming.type.keyFrameInterval="Set keyframe interval"
|
||||
AdvSceneSwitcher.action.streaming.type.server="Set server URL"
|
||||
AdvSceneSwitcher.action.streaming.type.streamKey="Set stream key"
|
||||
|
||||
@@ -34,6 +34,8 @@ const static std::map<MacroActionRecord::Action, std::string> actionTypes = {
|
||||
{MacroActionRecord::Action::ADD_CHAPTER,
|
||||
"AdvSceneSwitcher.action.recording.type.addChapter"},
|
||||
#endif
|
||||
{MacroActionRecord::Action::TOGGLE,
|
||||
"AdvSceneSwitcher.action.recording.type.toggle"},
|
||||
};
|
||||
|
||||
bool MacroActionRecord::PerformAction()
|
||||
@@ -49,6 +51,13 @@ bool MacroActionRecord::PerformAction()
|
||||
obs_frontend_recording_start();
|
||||
}
|
||||
break;
|
||||
case Action::TOGGLE:
|
||||
if (obs_frontend_recording_active()) {
|
||||
obs_frontend_recording_stop();
|
||||
} else {
|
||||
obs_frontend_recording_start();
|
||||
}
|
||||
break;
|
||||
case Action::PAUSE:
|
||||
if (obs_frontend_recording_active() &&
|
||||
!obs_frontend_recording_paused()) {
|
||||
@@ -156,8 +165,9 @@ void MacroActionRecord::ResolveVariablesToFixedValues()
|
||||
|
||||
static inline void populateActionSelection(QComboBox *list)
|
||||
{
|
||||
for (const auto &[_, name] : actionTypes) {
|
||||
list->addItem(obs_module_text(name.c_str()));
|
||||
for (const auto &[action, name] : actionTypes) {
|
||||
list->addItem(obs_module_text(name.c_str()),
|
||||
static_cast<int>(action));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,7 +225,8 @@ void MacroActionRecordEdit::UpdateEntryData()
|
||||
if (!_entryData) {
|
||||
return;
|
||||
}
|
||||
_actions->setCurrentIndex(static_cast<int>(_entryData->_action));
|
||||
_actions->setCurrentIndex(
|
||||
_actions->findData(static_cast<int>(_entryData->_action)));
|
||||
_recordFolder->SetPath(_entryData->_folder);
|
||||
_recordFileFormat->setText(_entryData->_fileFormat);
|
||||
_chapterName->setText(_entryData->_chapterName);
|
||||
@@ -271,10 +282,11 @@ void MacroActionRecordEdit::SetWidgetVisibility()
|
||||
}
|
||||
}
|
||||
|
||||
void MacroActionRecordEdit::ActionChanged(int value)
|
||||
void MacroActionRecordEdit::ActionChanged(int index)
|
||||
{
|
||||
GUARD_LOADING_AND_LOCK();
|
||||
_entryData->_action = static_cast<MacroActionRecord::Action>(value);
|
||||
_entryData->_action = static_cast<MacroActionRecord::Action>(
|
||||
_actions->itemData(index).toInt());
|
||||
SetWidgetVisibility();
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ public:
|
||||
FOLDER,
|
||||
FILE_FORMAT,
|
||||
ADD_CHAPTER,
|
||||
TOGGLE,
|
||||
};
|
||||
Action _action = Action::STOP;
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@ static const std::map<MacroActionReplayBuffer::Action, std::string>
|
||||
"AdvSceneSwitcher.action.replay.type.save"},
|
||||
{MacroActionReplayBuffer::Action::DURATION,
|
||||
"AdvSceneSwitcher.action.replay.type.duration"},
|
||||
{MacroActionReplayBuffer::Action::TOGGLE,
|
||||
"AdvSceneSwitcher.action.replay.type.toggle"},
|
||||
};
|
||||
|
||||
bool MacroActionReplayBuffer::PerformAction()
|
||||
@@ -38,6 +40,13 @@ bool MacroActionReplayBuffer::PerformAction()
|
||||
obs_frontend_replay_buffer_start();
|
||||
}
|
||||
break;
|
||||
case Action::TOGGLE:
|
||||
if (obs_frontend_replay_buffer_active()) {
|
||||
obs_frontend_replay_buffer_stop();
|
||||
} else {
|
||||
obs_frontend_replay_buffer_start();
|
||||
}
|
||||
break;
|
||||
case Action::SAVE:
|
||||
if (obs_frontend_replay_buffer_active()) {
|
||||
obs_frontend_replay_buffer_save();
|
||||
@@ -101,8 +110,9 @@ std::shared_ptr<MacroAction> MacroActionReplayBuffer::Copy() const
|
||||
|
||||
static inline void populateActionSelection(QComboBox *list)
|
||||
{
|
||||
for (const auto &[_, name] : actionTypes) {
|
||||
list->addItem(obs_module_text(name.c_str()));
|
||||
for (const auto &[action, name] : actionTypes) {
|
||||
list->addItem(obs_module_text(name.c_str()),
|
||||
static_cast<int>(action));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +150,8 @@ void MacroActionReplayBufferEdit::UpdateEntryData()
|
||||
if (!_entryData) {
|
||||
return;
|
||||
}
|
||||
_actions->setCurrentIndex(static_cast<int>(_entryData->_action));
|
||||
_actions->setCurrentIndex(
|
||||
_actions->findData(static_cast<int>(_entryData->_action)));
|
||||
_duration->SetDuration(_entryData->_duration);
|
||||
SetWidgetVisibility();
|
||||
}
|
||||
@@ -163,11 +174,11 @@ void MacroActionReplayBufferEdit::SetWidgetVisibility()
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
void MacroActionReplayBufferEdit::ActionChanged(int value)
|
||||
void MacroActionReplayBufferEdit::ActionChanged(int index)
|
||||
{
|
||||
GUARD_LOADING_AND_LOCK();
|
||||
_entryData->_action =
|
||||
static_cast<MacroActionReplayBuffer::Action>(value);
|
||||
_entryData->_action = static_cast<MacroActionReplayBuffer::Action>(
|
||||
_actions->itemData(index).toInt());
|
||||
|
||||
SetWidgetVisibility();
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ public:
|
||||
START,
|
||||
SAVE,
|
||||
DURATION,
|
||||
TOGGLE,
|
||||
};
|
||||
Action _action = Action::STOP;
|
||||
Duration _duration;
|
||||
|
||||
@@ -31,6 +31,8 @@ const static std::map<MacroActionStream::Action, std::string> actionTypes = {
|
||||
"AdvSceneSwitcher.action.streaming.type.username"},
|
||||
{MacroActionStream::Action::PASSWORD,
|
||||
"AdvSceneSwitcher.action.streaming.type.password"},
|
||||
{MacroActionStream::Action::TOGGLE,
|
||||
"AdvSceneSwitcher.action.streaming.type.toggle"},
|
||||
};
|
||||
|
||||
constexpr int streamStartCooldown = 5;
|
||||
@@ -88,6 +90,15 @@ bool MacroActionStream::CooldownDurationReached() const
|
||||
return timePassed.count() >= streamStartCooldown;
|
||||
}
|
||||
|
||||
void MacroActionStream::StartStreaming() const
|
||||
{
|
||||
if (!CooldownDurationReached()) {
|
||||
return;
|
||||
}
|
||||
obs_frontend_streaming_start();
|
||||
s_lastAttempt = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
|
||||
bool MacroActionStream::PerformAction()
|
||||
{
|
||||
switch (_action) {
|
||||
@@ -97,11 +108,15 @@ bool MacroActionStream::PerformAction()
|
||||
}
|
||||
break;
|
||||
case Action::START:
|
||||
if (!obs_frontend_streaming_active() &&
|
||||
CooldownDurationReached()) {
|
||||
obs_frontend_streaming_start();
|
||||
s_lastAttempt =
|
||||
std::chrono::high_resolution_clock::now();
|
||||
if (!obs_frontend_streaming_active()) {
|
||||
StartStreaming();
|
||||
}
|
||||
break;
|
||||
case Action::TOGGLE:
|
||||
if (obs_frontend_streaming_active()) {
|
||||
obs_frontend_streaming_stop();
|
||||
} else {
|
||||
StartStreaming();
|
||||
}
|
||||
break;
|
||||
case Action::KEYFRAME_INTERVAL:
|
||||
@@ -172,8 +187,9 @@ void MacroActionStream::ResolveVariablesToFixedValues()
|
||||
|
||||
static inline void populateActionSelection(QComboBox *list)
|
||||
{
|
||||
for (auto entry : actionTypes) {
|
||||
list->addItem(obs_module_text(entry.second.c_str()));
|
||||
for (const auto &[action, name] : actionTypes) {
|
||||
list->addItem(obs_module_text(name.c_str()),
|
||||
static_cast<int>(action));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,7 +250,8 @@ void MacroActionStreamEdit::UpdateEntryData()
|
||||
if (!_entryData) {
|
||||
return;
|
||||
}
|
||||
_actions->setCurrentIndex(static_cast<int>(_entryData->_action));
|
||||
_actions->setCurrentIndex(
|
||||
_actions->findData(static_cast<int>(_entryData->_action)));
|
||||
_keyFrameInterval->SetValue(_entryData->_keyFrameInterval);
|
||||
_stringValue->setText(_entryData->_stringValue);
|
||||
SetWidgetVisibility();
|
||||
@@ -356,12 +373,12 @@ void MacroActionStreamEdit::GetCurrentValueClicked()
|
||||
}
|
||||
}
|
||||
|
||||
void MacroActionStreamEdit::ActionChanged(int value)
|
||||
void MacroActionStreamEdit::ActionChanged(int index)
|
||||
{
|
||||
{
|
||||
GUARD_LOADING_AND_LOCK();
|
||||
_entryData->_action =
|
||||
static_cast<MacroActionStream::Action>(value);
|
||||
_entryData->_action = static_cast<MacroActionStream::Action>(
|
||||
_actions->itemData(index).toInt());
|
||||
}
|
||||
_stringValue->setText(QString(""));
|
||||
SetWidgetVisibility();
|
||||
|
||||
@@ -29,12 +29,14 @@ public:
|
||||
STREAM_KEY,
|
||||
USERNAME,
|
||||
PASSWORD,
|
||||
TOGGLE,
|
||||
};
|
||||
Action _action = Action::STOP;
|
||||
IntVariable _keyFrameInterval = 0;
|
||||
StringVariable _stringValue;
|
||||
|
||||
private:
|
||||
void StartStreaming() const;
|
||||
void SetKeyFrameInterval() const;
|
||||
void SetStreamSettingsValue(const char *name, const std::string &value,
|
||||
bool enableAuth = false) const;
|
||||
|
||||
Reference in New Issue
Block a user