Add advss namespace

Fixes name conflict with "Duration" class and typedef of the same name
on MacOS
This commit is contained in:
WarmUpTill
2023-04-12 16:16:03 +02:00
committed by WarmUpTill
parent b7479e8342
commit 2c5caabab0
266 changed files with 1142 additions and 92 deletions

View File

@@ -9,7 +9,9 @@
#include <QLayout>
#include <obs-module.h>
Q_DECLARE_METATYPE(Connection *);
Q_DECLARE_METATYPE(advss::Connection *);
namespace advss {
void SwitcherData::saveConnections(obs_data_t *obj)
{
@@ -419,3 +421,5 @@ void Connection::Save(obs_data_t *obj) const
obs_data_set_bool(obj, "reconnect", _reconnect);
obs_data_set_int(obj, "reconnectDelay", _reconnectDelay);
}
} // namespace advss

View File

@@ -15,6 +15,8 @@
#include <obs.hpp>
#include <websocket-helpers.hpp>
namespace advss {
class ConnectionSelection;
class ConnectionSettingsDialog;
@@ -97,3 +99,5 @@ public:
void SetConnection(const std::string &);
void SetConnection(const std::weak_ptr<Connection> &);
};
} // namespace advss

View File

@@ -5,6 +5,8 @@
#include <curl/curl.h>
#include <obs.hpp>
namespace advss {
#if defined(WIN32)
constexpr auto curl_library_name = "libcurl.dll";
#elif __APPLE__
@@ -108,3 +110,5 @@ bool Curlhelper::Resolve()
blog(LOG_INFO, "[adv-ss] curl symbols not resolved");
return false;
}
} // namespace advss

View File

@@ -2,6 +2,8 @@
#include <curl/curl.h>
#include <QLibrary>
namespace advss {
typedef CURL *(*initFunction)(void);
typedef void (*cleanupFunction)(CURL *);
typedef CURLcode (*setOptFunction)(CURL *, CURLoption, ...);
@@ -42,3 +44,5 @@ inline CURLcode Curlhelper::SetOpt(CURLoption option, Args... args)
}
return _setopt(_curl, option, args...);
}
} // namespace advss

View File

@@ -7,6 +7,8 @@
#include <iomanip>
#include <QHBoxLayout>
namespace advss {
Duration::Duration(double initialValueInSeconds) : _value(initialValueInSeconds)
{
}
@@ -223,3 +225,5 @@ void DurationSelection::_UnitChanged(int idx)
(prevMultiplier / newMultiplier));
emit DurationChanged(_current);
}
} // namespace advss

View File

@@ -8,6 +8,8 @@
#include <QPushButton>
#include <chrono>
namespace advss {
class Duration {
public:
Duration() = default;
@@ -61,3 +63,5 @@ private:
Duration _current;
};
} // namespace advss

View File

@@ -6,6 +6,8 @@
#include <QStandardPaths>
#include <filesystem>
namespace advss {
FileSelection::FileSelection(FileSelection::Type type, QWidget *parent)
: QWidget(parent),
_type(type),
@@ -68,3 +70,5 @@ void FileSelection::PathChange()
{
emit PathChanged(_filePath->text());
}
} // namespace advss

View File

@@ -5,6 +5,8 @@
#include <QPushButton>
#include <QWidget>
namespace advss {
class FileSelection : public QWidget {
Q_OBJECT
@@ -33,3 +35,5 @@ private:
VariableLineEdit *_filePath;
QPushButton *_browseButton;
};
} // namespace advss

View File

@@ -8,7 +8,9 @@
#include <QLayout>
#include <obs-module.h>
Q_DECLARE_METATYPE(Item *);
Q_DECLARE_METATYPE(advss::Item *);
namespace advss {
Item::Item(std::string name) : _name(name) {}
@@ -315,3 +317,5 @@ void Item::Save(obs_data_t *obj) const
{
obs_data_set_string(obj, "name", _name.c_str());
}
} // namespace advss

View File

@@ -15,6 +15,8 @@
#include <obs.hpp>
#include <websocket-helpers.hpp>
namespace advss {
class ItemSelection;
class ItemSettingsDialog;
@@ -99,3 +101,5 @@ protected:
std::string_view _selectStr;
std::string_view _addStr;
};
} // namespace advss

View File

@@ -3,6 +3,8 @@
#include "macro-selection.hpp"
#include "utility.hpp"
namespace advss {
MacroList::MacroList(QWidget *parent, bool allowDuplicates, bool reorder)
: QWidget(parent),
_list(new QListWidget()),
@@ -217,3 +219,5 @@ void MacroList::SetMacroListSize()
setHeightToContentHeight(_list);
adjustSize();
}
} // namespace advss

View File

@@ -5,6 +5,8 @@
#include <QPushButton>
#include <QHBoxLayout>
namespace advss {
class MacroList : public QWidget {
Q_OBJECT
public:
@@ -42,3 +44,5 @@ private:
const bool _allowDuplicates;
const bool _reorder;
};
} // namespace advss

View File

@@ -13,6 +13,8 @@ const char *obs_module_text(const char *text)
typedef exprtk::expression<double> expression_t;
typedef exprtk::parser<double> parser_t;
namespace advss {
std::variant<double, std::string> EvalMathExpression(const std::string &expr)
{
expression_t expression;
@@ -41,3 +43,5 @@ std::optional<double> GetDouble(const std::string &str)
}
return {};
}
} // namespace advss

View File

@@ -3,7 +3,11 @@
#include <variant>
#include <optional>
namespace advss {
std::variant<double, std::string>
EvalMathExpression(const std::string &expression);
bool IsValidNumber(const std::string &);
std::optional<double> GetDouble(const std::string &);
} // namespace advss

View File

@@ -3,6 +3,8 @@
#include <QEvent>
#include <QScrollBar>
namespace advss {
MouseWheelWidgetAdjustmentGuard::MouseWheelWidgetAdjustmentGuard(QObject *parent)
: QObject(parent)
{
@@ -29,3 +31,5 @@ void PreventMouseWheelAdjustWithoutFocus(QWidget *w)
}
w->installEventFilter(new MouseWheelWidgetAdjustmentGuard(w));
}
} // namespace advss

View File

@@ -1,6 +1,8 @@
#pragma once
#include <QWidget>
namespace advss {
class MouseWheelWidgetAdjustmentGuard : public QObject {
public:
explicit MouseWheelWidgetAdjustmentGuard(QObject *parent);
@@ -10,3 +12,5 @@ protected:
};
void PreventMouseWheelAdjustWithoutFocus(QWidget *);
} // namespace advss

View File

@@ -2,6 +2,8 @@
#include <QDialogButtonBox>
#include "name-dialog.hpp"
namespace advss {
AdvSSNameDialog::AdvSSNameDialog(QWidget *parent) : QDialog(parent)
{
setModal(true);
@@ -67,3 +69,5 @@ bool AdvSSNameDialog::AskForName(QWidget *parent, const QString &title,
}
return true;
}
} // namespace advss

View File

@@ -4,6 +4,8 @@
#include <QLabel>
#include <QLineEdit>
namespace advss {
// Based on OBS's NameDialog
class AdvSSNameDialog : public QDialog {
Q_OBJECT
@@ -22,3 +24,5 @@ private:
QLabel *label;
QLineEdit *userText;
};
} // namespace advss

View File

@@ -5,6 +5,8 @@
#include <QProcess>
#include <QFileDialog>
namespace advss {
bool ProcessConfig::Save(obs_data_t *obj) const
{
auto data = obs_data_create();
@@ -141,3 +143,5 @@ void ProcessConfigEdit::ShowAdvancedSettings(bool showAdvancedSettings)
adjustSize();
updateGeometry();
}
} // namespace advss

View File

@@ -10,6 +10,8 @@
#include <QStringList>
#include <QVBoxLayout>
namespace advss {
class ProcessConfig {
public:
bool Save(obs_data_t *obj) const;
@@ -54,3 +56,5 @@ private:
StringListEdit *_argList;
FileSelection *_workingDirectory;
};
} // namespace advss

View File

@@ -4,6 +4,8 @@
#include <QLayout>
#include <obs-module.h>
namespace advss {
void RegexConfig::Save(obs_data_t *obj) const
{
auto data = obs_data_create();
@@ -180,3 +182,5 @@ bool RegexConfigDialog::AskForSettings(QWidget *parent, RegexConfig &settings)
dialog._extendedPattern);
return true;
}
} // namespace advss

View File

@@ -8,6 +8,8 @@
#include <QDialogButtonBox>
#include <QRegularExpression>
namespace advss {
class RegexConfigWidget;
class RegexConfigDialog;
@@ -74,3 +76,5 @@ private:
QCheckBox *_extendedPattern;
QDialogButtonBox *_buttonbox;
};
} // namespace advss

View File

@@ -1,5 +1,7 @@
#include "resizing-text-edit.hpp"
namespace advss {
ResizingPlainTextEdit::ResizingPlainTextEdit(QWidget *parent,
const int scrollAt,
const int minLines,
@@ -29,3 +31,5 @@ void ResizingPlainTextEdit::ResizeTexteditArea()
adjustSize();
updateGeometry();
}
} // namespace advss

View File

@@ -1,6 +1,8 @@
#pragma once
#include <QPlainTextEdit>
namespace advss {
class ResizingPlainTextEdit : public QPlainTextEdit {
Q_OBJECT
public:
@@ -16,3 +18,5 @@ private:
const int _minLines;
const int _paddingLines;
};
} // namespace advss

View File

@@ -2,6 +2,8 @@
#include <obs-module.h>
namespace advss {
constexpr std::string_view typeSaveName = "type";
constexpr std::string_view itemSaveName = "item";
constexpr std::string_view idxSaveName = "idx";
@@ -490,3 +492,5 @@ void SceneItemSelectionWidget::SetupIdxSelection(int sceneItemCount)
}
adjustSize();
}
} // namespace advss

View File

@@ -6,6 +6,8 @@
#include <QComboBox>
#include <obs-data.h>
namespace advss {
class SceneItemSelection {
public:
void Save(obs_data_t *obj,
@@ -82,3 +84,5 @@ private:
int _variablesEndIdx = -1;
int _itemsEndIdx = -1;
};
} // namespace advss

View File

@@ -2,6 +2,8 @@
#include "advanced-scene-switcher.hpp"
#include "utility.hpp"
namespace advss {
constexpr std::string_view typeSaveName = "type";
constexpr std::string_view nameSaveName = "name";
constexpr std::string_view selectionSaveName = "sceneSelection";
@@ -454,3 +456,5 @@ void SceneSelectionWidget::ItemRename(const QString &, const QString &)
Reset();
blockSignals(false);
}
} // namespace advss

View File

@@ -5,6 +5,8 @@
#include <QComboBox>
namespace advss {
class SceneSelection {
public:
void Save(obs_data_t *obj) const;
@@ -78,3 +80,5 @@ private:
int _groupsEndIdx = -1;
int _scenesEndIdx = -1;
};
} // namespace advss

View File

@@ -3,6 +3,8 @@
#include <chrono>
namespace advss {
static void ScreenshotTick(void *param, float);
ScreenshotHelper::ScreenshotHelper(obs_source_t *source, bool blocking,
@@ -179,3 +181,5 @@ static void ScreenshotTick(void *param, float)
data->stage++;
}
} // namespace advss

View File

@@ -7,6 +7,8 @@
#include <mutex>
#include <condition_variable>
namespace advss {
class ScreenshotHelper {
public:
ScreenshotHelper() = default;
@@ -44,3 +46,5 @@ private:
std::mutex _mutex;
std::condition_variable _cv;
};
} // namespace advss

View File

@@ -4,6 +4,8 @@
#include <QPropertyAnimation>
#include <QEvent>
namespace advss {
Section::Section(const int animationDuration, QWidget *parent)
: QWidget(parent), _animationDuration(animationDuration)
{
@@ -175,3 +177,5 @@ void Section::AnimationFinish()
_transitioning = false;
emit AnimationFinished();
}
} // namespace advss

View File

@@ -7,6 +7,8 @@
#include <QToolButton>
#include <QWidget>
namespace advss {
class Section : public QWidget {
Q_OBJECT
@@ -47,3 +49,5 @@ private:
int _headerHeight = 0;
int _contentHeight = 0;
};
} // namespace advss

View File

@@ -1,6 +1,8 @@
#include "slider-spinbox.hpp"
#include <QHBoxLayout>
namespace advss {
SliderSpinBox::SliderSpinBox(double min, double max, const QString &label,
const QString &description, QWidget *parent)
: QWidget(parent),
@@ -71,3 +73,5 @@ void SliderSpinBox::SetVisibility(const NumberVariable<double> &value)
{
_slider->setVisible(value.IsFixedType());
}
} // namespace advss

View File

@@ -6,6 +6,8 @@
#include <QLabel>
#include <QDoubleSpinBox>
namespace advss {
class SliderSpinBox : public QWidget {
Q_OBJECT
@@ -28,3 +30,5 @@ private:
QSlider *_slider;
double _scale = 100.0;
};
} // namespace advss

View File

@@ -1,6 +1,8 @@
#include "source-selection.hpp"
#include "advanced-scene-switcher.hpp"
namespace advss {
constexpr std::string_view typeSaveName = "type";
constexpr std::string_view nameSaveName = "name";
@@ -247,3 +249,5 @@ void SourceSelectionWidget::ItemRename(const QString &, const QString &)
Reset();
blockSignals(false);
}
} // namespace advss

View File

@@ -5,6 +5,8 @@
#include <QComboBox>
namespace advss {
class SourceSelection {
public:
void Save(obs_data_t *obj, const char *name = "source") const;
@@ -66,3 +68,5 @@ private:
int _variablesEndIdx = -1;
int _sourcesEndIdx = -1;
};
} // namespace advss

View File

@@ -4,6 +4,8 @@
#include <QLayout>
namespace advss {
bool StringList::Save(obs_data_t *obj, const char *name,
const char *elementName) const
{
@@ -195,3 +197,5 @@ void StringListEdit::SetListSize()
adjustSize();
updateGeometry();
}
} // namespace advss

View File

@@ -8,6 +8,8 @@
#include <QListWidget>
#include <QStringList>
namespace advss {
class StringList : public QList<StringVariable> {
public:
bool Save(obs_data_t *obj, const char *name,
@@ -49,3 +51,5 @@ private:
QString _addString;
QString _addStringDescription;
};
} // namespace advss

View File

@@ -2,6 +2,8 @@
#include <cmath>
namespace advss {
constexpr QColor stripeColor = QColor(255, 255, 255, 50);
constexpr int stripeWidth = 30;
constexpr int stripeSpacing = 30;
@@ -35,3 +37,5 @@ void StripedFrame::paintEvent(QPaintEvent *event)
painter.translate(horizontalMoveStep, verticalMoveStep);
}
}
} // namespace advss

View File

@@ -2,6 +2,8 @@
#include <QFrame>
#include <QPainter>
namespace advss {
class StripedFrame : public QFrame {
public:
StripedFrame(QWidget *parent = nullptr) : QFrame(parent) {}
@@ -9,3 +11,5 @@ public:
protected:
void paintEvent(QPaintEvent *event) override;
};
} // namespace advss

View File

@@ -1,6 +1,8 @@
#include "transition-selection.hpp"
#include "advanced-scene-switcher.hpp"
namespace advss {
void TransitionSelection::Save(obs_data_t *obj, const char *name,
const char *typeName) const
{
@@ -169,3 +171,5 @@ void TransitionSelectionWidget::SelectionChanged(const QString &name)
emit TransitionChanged(t);
}
} // namespace advss

View File

@@ -3,6 +3,8 @@
#include <QComboBox>
namespace advss {
class TransitionSelection {
public:
void Save(obs_data_t *obj, const char *name = "transition",
@@ -44,3 +46,5 @@ private:
bool IsCurrentTransitionSelected(const QString &name);
bool IsAnyTransitionSelected(const QString &name);
};
} // namespace advss

View File

@@ -22,6 +22,8 @@
#include <set>
#include <obs-module.h>
namespace advss {
bool WeakSourceValid(obs_weak_source_t *ws)
{
obs_source_t *source = obs_weak_source_get_source(ws);
@@ -1055,3 +1057,5 @@ void replaceAll(std::string &str, const std::string &from,
start_pos += to.length();
}
}
} // namespace advss

View File

@@ -13,6 +13,8 @@
#include <unordered_map>
#include "scene-group.hpp"
namespace advss {
class SceneSelection;
class RegexConfig;
@@ -120,3 +122,5 @@ bool doubleEquals(double left, double right, double epsilon);
std::pair<int, int> getCursorPos();
void replaceAll(std::string &str, const std::string &from,
const std::string &to);
} // namespace advss

View File

@@ -1,5 +1,7 @@
#include "variable-line-edit.hpp"
namespace advss {
VariableLineEdit::VariableLineEdit(QWidget *parent) : QLineEdit(parent) {}
void VariableLineEdit::setText(const QString &string)
@@ -11,3 +13,5 @@ void VariableLineEdit::setText(const StringVariable &string)
{
QLineEdit::setText(QString::fromStdString(string.UnresolvedValue()));
}
} // namespace advss

View File

@@ -3,6 +3,8 @@
#include <QLineEdit>
namespace advss {
class VariableLineEdit : public QLineEdit {
Q_OBJECT
public:
@@ -12,3 +14,5 @@ public:
private:
};
} // namespace advss

View File

@@ -3,6 +3,8 @@
#include <obs.hpp>
namespace advss {
template<typename T> class NumberVariable {
public:
NumberVariable() = default;
@@ -33,3 +35,5 @@ private:
};
#include "variable-number.tpp"
} // namespace advss

View File

@@ -4,6 +4,8 @@
#include <QLayout>
namespace advss {
GenericVaraiableSpinbox::GenericVaraiableSpinbox(QWidget *parent,
bool wholeNumber)
: QWidget(parent),
@@ -194,3 +196,5 @@ VariableDoubleSpinBox::VariableDoubleSpinBox(QWidget *parent)
: GenericVaraiableSpinbox(parent, false)
{
}
} // namespace advss

View File

@@ -6,6 +6,8 @@
#include <QDoubleSpinBox>
#include <QPushButton>
namespace advss {
class GenericVaraiableSpinbox : public QWidget {
Q_OBJECT
public:
@@ -66,3 +68,5 @@ public:
QDoubleSpinBox *SpinBox() { return _fixedValueDouble; }
void setDecimals(int prec) { _fixedValueDouble->setDecimals(prec); }
};
} // namespace advss

View File

@@ -3,6 +3,8 @@
#include <switcher-data-structs.hpp>
#include <utility.hpp>
namespace advss {
void StringVariable::Resolve()
{
if (switcher->variables.empty()) {
@@ -71,3 +73,5 @@ std::string SubstitueVariables(std::string str)
}
return str;
}
} // namespace advss

View File

@@ -4,6 +4,8 @@
#include <string>
#include <obs.hpp>
namespace advss {
// Helper class which automatically resovles variables contained in strings
// when reading its value as a std::string
@@ -32,6 +34,8 @@ private:
std::chrono::high_resolution_clock::time_point _lastResolve{};
};
Q_DECLARE_METATYPE(StringVariable);
std::string SubstitueVariables(std::string str);
} // namespace advss
Q_DECLARE_METATYPE(advss::StringVariable);

View File

@@ -1,6 +1,8 @@
#include "variable-text-edit.hpp"
#include "switcher-data-structs.hpp"
namespace advss {
VariableTextEdit::VariableTextEdit(QWidget *parent)
: ResizingPlainTextEdit(parent)
{
@@ -16,3 +18,5 @@ void VariableTextEdit::setPlainText(const StringVariable &string)
QPlainTextEdit::setPlainText(
QString::fromStdString(string.UnresolvedValue()));
}
} // namespace advss

View File

@@ -2,6 +2,8 @@
#include "resizing-text-edit.hpp"
#include "variable-string.hpp"
namespace advss {
class VariableTextEdit : public ResizingPlainTextEdit {
Q_OBJECT
public:
@@ -11,3 +13,5 @@ public:
private:
};
} // namespace advss

View File

@@ -4,6 +4,8 @@
#include <switcher-data-structs.hpp>
namespace advss {
// Keep track of the last time a variable was changed to save some work when
// when resolving strings containing variables, etc.
static std::chrono::high_resolution_clock::time_point lastVariableChange{};
@@ -284,3 +286,5 @@ void VariableSelection::SetVariable(const std::weak_ptr<Variable> &variable_)
_selection->setCurrentIndex(0);
}
}
} // namespace advss

View File

@@ -7,6 +7,8 @@
#include <QStringList>
#include <obs.hpp>
namespace advss {
class VariableSelection;
class VariableSettingsDialog;
@@ -72,3 +74,5 @@ public:
void SetVariable(const std::string &);
void SetVariable(const std::weak_ptr<Variable> &);
};
} // namespace advss

View File

@@ -9,6 +9,8 @@
#include <QStyleFactory>
#include <util/platform.h>
namespace advss {
using namespace std;
#define CLAMP(x, min, max) ((x) < (min) ? (min) : ((x) > (max) ? (max) : (x)))
@@ -1249,3 +1251,5 @@ void VolumeMeterTimer::timerEvent(QTimerEvent *)
}
}
}
} // namespace advss

View File

@@ -11,6 +11,11 @@
#include <QMenu>
class QPushButton;
class QLabel;
class QSlider;
namespace advss {
class VolumeMeterTimer;
class VolumeMeter : public QWidget {
@@ -271,9 +276,6 @@ protected:
QList<VolumeMeter *> volumeMeters;
};
class QLabel;
class QSlider;
class VolControl : public QWidget {
Q_OBJECT
@@ -338,3 +340,5 @@ public:
VolumeSlider(obs_fader_t *fader, Qt::Orientation orientation,
QWidget *parent = nullptr);
};
} // namespace advss

View File

@@ -5,6 +5,8 @@
#include <QCryptographicHash>
#include <obs-websocket-api.h>
namespace advss {
using websocketpp::lib::placeholders::_1;
using websocketpp::lib::placeholders::_2;
using websocketpp::lib::bind;
@@ -83,10 +85,10 @@ WSConnection::WSConnection() : QObject(nullptr)
_client.set_reuse_addr(true);
#endif
_client.set_open_handler(bind(&WSConnection::OnOpen, this, ::_1));
_client.set_open_handler(bind(&WSConnection::OnOpen, this, _1));
_client.set_message_handler(
bind(&WSConnection::OnMessage, this, ::_1, ::_2));
_client.set_close_handler(bind(&WSConnection::OnClose, this, ::_1));
bind(&WSConnection::OnMessage, this, _1, _2));
_client.set_close_handler(bind(&WSConnection::OnClose, this, _1));
}
WSConnection::~WSConnection()
@@ -356,3 +358,5 @@ void WSConnection::OnClose(connection_hdl)
blog(LOG_INFO, "client-connection to %s closed.", _uri.c_str());
_status = Status::DISCONNECTED;
}
} // namespace advss

View File

@@ -18,6 +18,8 @@
#include <obs.hpp>
namespace advss {
using websocketpp::connection_hdl;
typedef websocketpp::server<websocketpp::config::asio> server;
typedef websocketpp::client<websocketpp::config::asio_client> client;
@@ -75,3 +77,5 @@ private:
std::vector<std::string> _messages;
};
} // namespace advss