mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-03-21 17:34:57 -05:00
Add ResolveVariables()
Settings will be set to fixed values based on the values of the variables used.
This commit is contained in:
parent
2928775f5b
commit
f8dadd38b4
|
|
@ -165,4 +165,9 @@ void Duration::SetUnit(Unit u)
|
|||
_value = _value * (prevMultiplier / newMultiplier);
|
||||
}
|
||||
|
||||
void Duration::ResolveVariables()
|
||||
{
|
||||
_value.ResolveVariables();
|
||||
}
|
||||
|
||||
} // namespace advss
|
||||
|
|
|
|||
|
|
@ -34,8 +34,10 @@ public:
|
|||
// Only use this function if you intend to convert old settings formats
|
||||
EXPORT void SetUnit(Unit u);
|
||||
|
||||
EXPORT void ResolveVariables();
|
||||
|
||||
private:
|
||||
NumberVariable<double> _value = 0.;
|
||||
DoubleVariable _value = 0.;
|
||||
Unit _unit = Unit::SECONDS;
|
||||
std::chrono::high_resolution_clock::time_point _startTime;
|
||||
|
||||
|
|
|
|||
|
|
@ -181,6 +181,12 @@ std::string SceneSelection::ToString(bool resolve) const
|
|||
return "";
|
||||
}
|
||||
|
||||
void SceneSelection::ResolveVariables()
|
||||
{
|
||||
_scene = GetScene();
|
||||
_type = Type::SCENE;
|
||||
}
|
||||
|
||||
SceneSelection SceneSelectionWidget::CurrentSelection()
|
||||
{
|
||||
SceneSelection s;
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ public:
|
|||
EXPORT Type GetType() const { return _type; }
|
||||
EXPORT OBSWeakSource GetScene(bool advance = true) const;
|
||||
EXPORT std::string ToString(bool resolve = false) const;
|
||||
EXPORT void ResolveVariables();
|
||||
|
||||
private:
|
||||
OBSWeakSource _scene;
|
||||
|
|
|
|||
|
|
@ -88,6 +88,11 @@ void SourceSelection::SetSource(OBSWeakSource source)
|
|||
_source = source;
|
||||
}
|
||||
|
||||
void SourceSelection::ResolveVariables()
|
||||
{
|
||||
SetSource(GetSource());
|
||||
}
|
||||
|
||||
std::string SourceSelection::ToString(bool resolve) const
|
||||
{
|
||||
switch (_type) {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ public:
|
|||
EXPORT Type GetType() const { return _type; }
|
||||
EXPORT OBSWeakSource GetSource() const;
|
||||
EXPORT void SetSource(OBSWeakSource);
|
||||
EXPORT void ResolveVariables();
|
||||
EXPORT std::string ToString(bool resolve = false) const;
|
||||
|
||||
EXPORT bool operator==(const SourceSelection &) const;
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ public:
|
|||
Type GetType() const { return _type; }
|
||||
bool IsFixedType() const { return _type == Type::FIXED_VALUE; }
|
||||
std::weak_ptr<Variable> GetVariable() const { return _variable; }
|
||||
void ResolveVariables();
|
||||
|
||||
private:
|
||||
Type _type = Type::FIXED_VALUE;
|
||||
|
|
|
|||
|
|
@ -93,3 +93,9 @@ template<typename T> NumberVariable<T>::operator T() const
|
|||
{
|
||||
return GetValue();
|
||||
}
|
||||
|
||||
template<typename T> void NumberVariable<T>::ResolveVariables()
|
||||
{
|
||||
_value = GetValue();
|
||||
_type = Type::FIXED_VALUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,6 +50,12 @@ void StringVariable::Save(obs_data_t *obj, const char *name) const
|
|||
obs_data_set_string(obj, name, _value.c_str());
|
||||
}
|
||||
|
||||
void StringVariable::ResolveVariables()
|
||||
{
|
||||
Resolve();
|
||||
_value = _resolvedValue;
|
||||
}
|
||||
|
||||
const char *StringVariable::c_str()
|
||||
{
|
||||
Resolve();
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ public:
|
|||
EXPORT void Load(obs_data_t *obj, const char *name);
|
||||
EXPORT void Save(obs_data_t *obj, const char *name) const;
|
||||
|
||||
EXPORT void ResolveVariables();
|
||||
|
||||
private:
|
||||
void Resolve() const;
|
||||
|
||||
|
|
|
|||
|
|
@ -114,6 +114,20 @@ FilterSelection::GetFilters(const SourceSelection &source) const
|
|||
return {};
|
||||
}
|
||||
|
||||
void FilterSelection::ResolveVariables()
|
||||
{
|
||||
if (_type != Type::VARIABLE) {
|
||||
return;
|
||||
}
|
||||
_type = Type::SOURCE;
|
||||
auto var = _variable.lock();
|
||||
if (!var) {
|
||||
_filterName = "";
|
||||
return;
|
||||
}
|
||||
_filterName = var->Value();
|
||||
}
|
||||
|
||||
std::string FilterSelection::ToString(bool resolve) const
|
||||
{
|
||||
switch (_type) {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ public:
|
|||
Type GetType() const { return _type; }
|
||||
std::vector<OBSWeakSource>
|
||||
GetFilters(const SourceSelection &source) const;
|
||||
void ResolveVariables();
|
||||
std::string ToString(bool resolve = false) const;
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -140,6 +140,11 @@ void OSCBlob::Load(obs_data_t *obj, const char *name)
|
|||
_stringRep.Load(obj, name);
|
||||
}
|
||||
|
||||
void OSCBlob::ResolveVariables()
|
||||
{
|
||||
_stringRep.ResolveVariables();
|
||||
}
|
||||
|
||||
void OSCTrue::Save(obs_data_t *obj, const char *name) const
|
||||
{
|
||||
obs_data_set_bool(obj, name, true);
|
||||
|
|
@ -201,6 +206,14 @@ std::optional<std::vector<char>> OSCMessage::GetBuffer() const
|
|||
return buffer;
|
||||
}
|
||||
|
||||
void OSCMessage::ResolveVariables()
|
||||
{
|
||||
_address.ResolveVariables();
|
||||
for (auto &element : _elements) {
|
||||
element.ResolveVariables();
|
||||
}
|
||||
}
|
||||
|
||||
const char *OSCMessageElement::GetTypeTag() const
|
||||
{
|
||||
return GetTypeTag(*this);
|
||||
|
|
@ -216,6 +229,21 @@ const char *OSCMessageElement::GetTypeTag(const OSCMessageElement &element)
|
|||
return _typeNames.at(element._value.index()).tag;
|
||||
}
|
||||
|
||||
void OSCMessageElement::ResolveVariables()
|
||||
{
|
||||
std::visit(
|
||||
[](auto &&arg) {
|
||||
using T = std::decay_t<decltype(arg)>;
|
||||
if constexpr (std::is_same_v<T, StringVariable> ||
|
||||
std::is_same_v<T, DoubleVariable> ||
|
||||
std::is_same_v<T, OSCBlob> ||
|
||||
std::is_same_v<T, IntVariable>) {
|
||||
arg.ResolveVariables();
|
||||
}
|
||||
},
|
||||
_value);
|
||||
}
|
||||
|
||||
const char *OSCMessageElement::GetTypeName(const OSCMessageElement &element)
|
||||
{
|
||||
return obs_module_text(
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ public:
|
|||
std::optional<std::vector<char>> GetBinary() const;
|
||||
void Save(obs_data_t *obj, const char *name) const;
|
||||
void Load(obs_data_t *obj, const char *name);
|
||||
void ResolveVariables();
|
||||
|
||||
private:
|
||||
StringVariable _stringRep;
|
||||
|
|
@ -69,6 +70,8 @@ public:
|
|||
static const char *GetTypeName(const OSCMessageElement &);
|
||||
static const char *GetTypeTag(const OSCMessageElement &);
|
||||
|
||||
void ResolveVariables();
|
||||
|
||||
private:
|
||||
struct TypeInfo {
|
||||
const char *localizedName, *tag;
|
||||
|
|
@ -91,6 +94,8 @@ public:
|
|||
std::string ToString() const;
|
||||
std::optional<std::vector<char>> GetBuffer() const;
|
||||
|
||||
void ResolveVariables();
|
||||
|
||||
private:
|
||||
StringVariable _address = "/address";
|
||||
std::vector<OSCMessageElement> _elements = {
|
||||
|
|
|
|||
|
|
@ -53,6 +53,13 @@ bool ProcessConfig::StartProcessDetached() const
|
|||
QString::fromStdString(WorkingDir()));
|
||||
}
|
||||
|
||||
void ProcessConfig::ResolveVariables()
|
||||
{
|
||||
_path.ResolveVariables();
|
||||
_workingDirectory.ResolveVariables();
|
||||
_args.ResolveVariables();
|
||||
}
|
||||
|
||||
std::variant<int, ProcessConfig::ProcStartError>
|
||||
ProcessConfig::StartProcessAndWait(int timeout) const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@ public:
|
|||
StartProcessAndWait(int timeoutInMs) const;
|
||||
bool StartProcessDetached() const;
|
||||
|
||||
void ResolveVariables();
|
||||
|
||||
private:
|
||||
StringVariable _path = obs_module_text("AdvSceneSwitcher.enterPath");
|
||||
StringVariable _workingDirectory = "";
|
||||
|
|
|
|||
|
|
@ -304,6 +304,25 @@ void SceneItemSelection::SetSourceTypeSelection(const char *type)
|
|||
_sourceGroup = type;
|
||||
}
|
||||
|
||||
void SceneItemSelection::ResolveVariables()
|
||||
{
|
||||
_index.ResolveVariables();
|
||||
_indexEnd.ResolveVariables();
|
||||
_pattern = std::string(_pattern);
|
||||
|
||||
if (_type != Type::VARIABLE_NAME) {
|
||||
return;
|
||||
}
|
||||
_type = Type::SOURCE_NAME;
|
||||
|
||||
auto variable = _variable.lock();
|
||||
if (variable) {
|
||||
_source = GetWeakSourceByName(variable->Value().c_str());
|
||||
} else {
|
||||
_source = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void SceneItemSelection::ReduceBadedOnIndexSelection(
|
||||
std::vector<OBSSceneItem> &items) const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -53,6 +53,8 @@ public:
|
|||
// scene item visibility action
|
||||
void SetSourceTypeSelection(const char *);
|
||||
|
||||
void ResolveVariables();
|
||||
|
||||
private:
|
||||
std::vector<OBSSceneItem>
|
||||
GetSceneItemsByName(const SceneSelection &) const;
|
||||
|
|
|
|||
|
|
@ -39,6 +39,13 @@ bool StringList::Load(obs_data_t *obj, const char *name,
|
|||
return true;
|
||||
}
|
||||
|
||||
void StringList::ResolveVariables()
|
||||
{
|
||||
for (auto &value : *this) {
|
||||
value.ResolveVariables();
|
||||
}
|
||||
}
|
||||
|
||||
StringListEdit::StringListEdit(QWidget *parent, const QString &addString,
|
||||
const QString &addStringDescription,
|
||||
int maxStringSize, bool allowEmtpy)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ public:
|
|||
const char *elementName = "string") const;
|
||||
bool Load(obs_data_t *obj, const char *name,
|
||||
const char *elementName = "string");
|
||||
void ResolveVariables();
|
||||
|
||||
friend class StringListEdit;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user