mirror of
https://github.com/gtalent/sc9k.git
synced 2025-01-23 00:33:36 -06:00
Add video image settings per camera preset
This commit is contained in:
parent
bc342a290f
commit
b119268396
@ -8,6 +8,7 @@
|
||||
|
||||
#include <QNetworkReply>
|
||||
#include <QSettings>
|
||||
#include <string_view>
|
||||
|
||||
#include "settingsdata.hpp"
|
||||
#include "cameraclient.hpp"
|
||||
@ -20,16 +21,93 @@ CameraClient::CameraClient(QObject *parent): QObject(parent) {
|
||||
}
|
||||
|
||||
void CameraClient::setPreset(int preset) {
|
||||
if (preset > -1) {
|
||||
if (preset > 0 && preset < MaxCameraPresets) {
|
||||
get(QString("/cgi-bin/ptzctrl.cgi?ptzcmd&poscall&%1").arg(preset));
|
||||
--preset;
|
||||
auto const vc = getVideoConfig()[preset];
|
||||
qDebug() << preset << vc.brightness;
|
||||
setBrightness(vc.brightness);
|
||||
setSaturation(vc.saturation);
|
||||
setContrast(vc.contrast);
|
||||
setSharpness(vc.sharpness);
|
||||
setHue(vc.hue);
|
||||
}
|
||||
}
|
||||
|
||||
void CameraClient::setBrightness(int val) {
|
||||
if (val > -1) {
|
||||
get(QString("/cgi-bin/ptzctrl.cgi?post_image_value&bright&%1").arg(val));
|
||||
}
|
||||
}
|
||||
|
||||
void CameraClient::setSaturation(int val) {
|
||||
if (val > -1) {
|
||||
get(QString("/cgi-bin/ptzctrl.cgi?post_image_value&saturation&%1").arg(val));
|
||||
}
|
||||
}
|
||||
|
||||
void CameraClient::setContrast(int val) {
|
||||
if (val > -1) {
|
||||
get(QString("/cgi-bin/ptzctrl.cgi?post_image_value&contrast&%1").arg(val));
|
||||
}
|
||||
}
|
||||
|
||||
void CameraClient::setSharpness(int val) {
|
||||
if (val > -1) {
|
||||
get(QString("/cgi-bin/ptzctrl.cgi?post_image_value&sharpness&%1").arg(val));
|
||||
}
|
||||
}
|
||||
|
||||
void CameraClient::setHue(int val) {
|
||||
if (val > -1) {
|
||||
get(QString("/cgi-bin/ptzctrl.cgi?post_image_value&hue&%1").arg(val));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
void CameraClient::getVideoConfig() {
|
||||
QUrl url(QString(m_baseUrl) + "/cgi-bin/param.cgi?get_image_conf");
|
||||
QNetworkRequest rqst(url);
|
||||
auto const reply = m_nam->get(rqst);
|
||||
connect(reply, &QIODevice::readyRead, this, [this, reply] {processVideoConfig(reply);});
|
||||
}
|
||||
*/
|
||||
|
||||
void CameraClient::setBaseUrl() {
|
||||
auto const [host, port] = getCameraConnectionData();
|
||||
m_baseUrl = QString("http://%1:%2").arg(host, QString::number(port));
|
||||
}
|
||||
|
||||
/*
|
||||
void CameraClient::processVideoConfig(QNetworkReply *reply) {
|
||||
auto constexpr brightStart = std::string_view("bright = ");
|
||||
auto constexpr saturationStart = std::string_view("saturation = ");
|
||||
auto constexpr contrastStart = std::string_view("contrast = ");
|
||||
auto constexpr sharpnessStart = std::string_view("sharpness = ");
|
||||
auto constexpr hueStart = std::string_view("hue = ");
|
||||
while (!reply->atEnd()) {
|
||||
auto const line = reply->readLine();
|
||||
if (line.startsWith(brightStart)) {
|
||||
m_videoConfig.brightness = QString(line.mid(brightStart.size())).toInt();
|
||||
} else if (line.startsWith(saturationStart)) {
|
||||
m_videoConfig.saturation = QString(line.mid(saturationStart.size())).toInt();
|
||||
} else if (line.startsWith(contrastStart)) {
|
||||
m_videoConfig.contrast = QString(line.mid(contrastStart.size())).toInt();
|
||||
} else if (line.startsWith(sharpnessStart)) {
|
||||
m_videoConfig.sharpness = QString(line.mid(sharpnessStart.size())).toInt();
|
||||
} else if (line.startsWith(hueStart)) {
|
||||
m_videoConfig.hue = QString(line.mid(hueStart.size())).toInt();
|
||||
}
|
||||
}
|
||||
qDebug() <<
|
||||
"brightness:" << m_videoConfig.brightness <<
|
||||
"saturation:" << m_videoConfig.brightness <<
|
||||
"contrast:" << m_videoConfig.brightness <<
|
||||
"sharpness:" << m_videoConfig.brightness <<
|
||||
"hue:" << m_videoConfig.hue;
|
||||
}
|
||||
*/
|
||||
|
||||
void CameraClient::get(QString const&urlExt) {
|
||||
QUrl url(QString(m_baseUrl) + urlExt);
|
||||
QNetworkRequest rqst(url);
|
||||
|
@ -27,10 +27,22 @@ class CameraClient: public QObject {
|
||||
|
||||
void setPreset(int preset);
|
||||
|
||||
void setBrightness(int val);
|
||||
|
||||
void setSaturation(int val);
|
||||
|
||||
void setContrast(int val);
|
||||
|
||||
void setSharpness(int val);
|
||||
|
||||
void setHue(int val);
|
||||
|
||||
public slots:
|
||||
void setBaseUrl();
|
||||
|
||||
private:
|
||||
void processVideoConfig(QNetworkReply*);
|
||||
|
||||
void get(QString const&url);
|
||||
|
||||
void poll();
|
||||
|
@ -113,7 +113,7 @@ void MainWindow::setupMenu() {
|
||||
// camera preset menu
|
||||
{
|
||||
auto const menu = menuBar()->addMenu(tr("&Camera Preset"));
|
||||
for (auto i = 0; i < MaxCameraPresets; ++i) {
|
||||
for (auto i = 0; i < std::min(9, MaxCameraPresets); ++i) {
|
||||
auto const cameraPresetAct = new QAction(tr("Camera Preset &%1").arg(i + 1), this);
|
||||
cameraPresetAct->setShortcut(Qt::ALT | static_cast<Qt::Key>(Qt::Key_1 + i));
|
||||
connect(cameraPresetAct, &QAction::triggered, &m_cameraClient, [this, i] {
|
||||
@ -141,27 +141,7 @@ Built on Qt library under LGPL 2.0)").arg(__DATE__));
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::setupDefaultViewControls(QGridLayout *viewCtlLyt) {
|
||||
auto const mainWidget = viewCtlLyt->parentWidget();
|
||||
auto const btnHideSlides = new QPushButton(tr("1. Hide"), mainWidget);
|
||||
auto const btnOpenLpShowSlides = new QPushButton(tr("2. Show in OpenLP Only"), mainWidget);
|
||||
auto const btnShowSlides = new QPushButton(tr("3. Show"), mainWidget);
|
||||
viewCtlLyt->addWidget(btnHideSlides, 0, 0);
|
||||
viewCtlLyt->addWidget(btnOpenLpShowSlides, 0, 1);
|
||||
viewCtlLyt->addWidget(btnShowSlides, 0, 2);
|
||||
btnHideSlides->setShortcut(Qt::Key_1);
|
||||
btnOpenLpShowSlides->setShortcut(Qt::Key_2);
|
||||
btnHideSlides->setToolTip(tr("Also hides slides in OBS"));
|
||||
btnShowSlides->setShortcut(Qt::Key_3);
|
||||
connect(btnHideSlides, &QPushButton::clicked, &m_openlpClient, &OpenLPClient::blankScreen);
|
||||
connect(btnHideSlides, &QPushButton::clicked, &m_obsClient, &OBSClient::hideSlides);
|
||||
connect(btnOpenLpShowSlides, &QPushButton::clicked, &m_openlpClient, &OpenLPClient::showSlides);
|
||||
connect(btnOpenLpShowSlides, &QPushButton::clicked, &m_obsClient, &OBSClient::hideSlides);
|
||||
connect(btnShowSlides, &QPushButton::clicked, &m_obsClient, &OBSClient::showSlides);
|
||||
connect(btnShowSlides, &QPushButton::clicked, &m_openlpClient, &OpenLPClient::showSlides);
|
||||
}
|
||||
|
||||
void MainWindow::setupCustomViewControls(QVector<View> const&views, QGridLayout *viewCtlLyt) {
|
||||
void MainWindow::setupViewControlButtons(QVector<View> const&views, QGridLayout *viewCtlLyt) {
|
||||
constexpr auto columns = 3;
|
||||
auto const parent = viewCtlLyt->parentWidget();
|
||||
for (auto i = 0; auto const&view : views) {
|
||||
@ -203,8 +183,8 @@ void MainWindow::setupViewControls(QVBoxLayout *rootLyt) {
|
||||
.obsSlides = false,
|
||||
});
|
||||
views.emplace_back(View{
|
||||
.name = tr("Hide in OBS"),
|
||||
.slides = false,
|
||||
.name = tr("Show in OpenLP Only"),
|
||||
.slides = true,
|
||||
.obsSlides = false,
|
||||
});
|
||||
views.emplace_back(View{
|
||||
@ -213,11 +193,7 @@ void MainWindow::setupViewControls(QVBoxLayout *rootLyt) {
|
||||
.obsSlides = false,
|
||||
});
|
||||
}
|
||||
if (views.empty()) {
|
||||
setupDefaultViewControls(viewCtlLyt);
|
||||
} else {
|
||||
setupCustomViewControls(views, viewCtlLyt);
|
||||
}
|
||||
setupViewControlButtons(views, viewCtlLyt);
|
||||
}
|
||||
|
||||
void MainWindow::openSettings() {
|
||||
|
@ -40,9 +40,7 @@ class MainWindow: public QMainWindow {
|
||||
private:
|
||||
void setupMenu();
|
||||
|
||||
void setupDefaultViewControls(class QGridLayout *rootLyt);
|
||||
|
||||
void setupCustomViewControls(QVector<View> const&views, class QGridLayout *rootLyt);
|
||||
void setupViewControlButtons(QVector<View> const&views, class QGridLayout *rootLyt);
|
||||
|
||||
void setupViewControls(class QVBoxLayout *rootLyt);
|
||||
|
||||
|
@ -8,8 +8,54 @@
|
||||
|
||||
#include <QSettings>
|
||||
|
||||
#include "consts.hpp"
|
||||
#include "settingsdata.hpp"
|
||||
|
||||
void setVideoConfig(QSettings &settings, QVector<VideoConfig> const&vcList) {
|
||||
settings.beginGroup("Camera");
|
||||
settings.beginWriteArray("VideoImageConfig");
|
||||
for (auto i = 0; auto const&vc : vcList) {
|
||||
settings.setArrayIndex(i);
|
||||
settings.setValue("brightness", vc.brightness);
|
||||
settings.setValue("saturation", vc.saturation);
|
||||
settings.setValue("contrast", vc.contrast);
|
||||
settings.setValue("sharpness", vc.sharpness);
|
||||
settings.setValue("hue", vc.hue);
|
||||
++i;
|
||||
}
|
||||
settings.endArray();
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
void setVideoConfig(QVector<VideoConfig> const&vcList) {
|
||||
QSettings s;
|
||||
setVideoConfig(s, vcList);
|
||||
}
|
||||
|
||||
QVector<VideoConfig> getVideoConfig(QSettings &settings) {
|
||||
QVector<VideoConfig> vc(MaxCameraPresets);
|
||||
settings.beginGroup("Camera");
|
||||
auto const size = std::min(settings.beginReadArray("VideoImageConfig"), MaxCameraPresets);
|
||||
for (auto i = 0; i < size; ++i) {
|
||||
settings.setArrayIndex(i);
|
||||
vc[i] = {
|
||||
.brightness = settings.value("brightness").toInt(),
|
||||
.saturation = settings.value("saturation").toInt(),
|
||||
.contrast = settings.value("contrast").toInt(),
|
||||
.sharpness = settings.value("sharpness").toInt(),
|
||||
.hue = settings.value("hue").toInt(),
|
||||
};
|
||||
}
|
||||
settings.endArray();
|
||||
settings.endGroup();
|
||||
return vc;
|
||||
}
|
||||
|
||||
QVector<VideoConfig> getVideoConfig() {
|
||||
QSettings s;
|
||||
return getVideoConfig(s);
|
||||
}
|
||||
|
||||
void setCameraConnectionData(QSettings &settings, ConnectionData const&cd) {
|
||||
settings.beginGroup("CameraClient");
|
||||
settings.setValue("Host", cd.host);
|
||||
|
@ -8,9 +8,26 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QHash>
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
|
||||
struct VideoConfig {
|
||||
int brightness = 6;
|
||||
int saturation = 4;
|
||||
int contrast = 8;
|
||||
int sharpness = 3;
|
||||
int hue = 7;
|
||||
};
|
||||
|
||||
void setVideoConfig(class QSettings &settings, QVector<VideoConfig> const&vc);
|
||||
|
||||
void setVideoConfig(QVector<VideoConfig> const&vc);
|
||||
|
||||
QVector<VideoConfig> getVideoConfig(QSettings &settings);
|
||||
|
||||
QVector<VideoConfig> getVideoConfig();
|
||||
|
||||
struct ConnectionData {
|
||||
QString host;
|
||||
uint16_t port = 0;
|
||||
|
@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QFormLayout>
|
||||
#include <QHeaderView>
|
||||
#include <QIntValidator>
|
||||
@ -14,7 +15,9 @@
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QSettings>
|
||||
#include <QSlider>
|
||||
#include <QSpacerItem>
|
||||
#include <QSpinBox>
|
||||
#include <QTabWidget>
|
||||
#include <QTableWidget>
|
||||
#include <QVBoxLayout>
|
||||
@ -34,6 +37,7 @@ SettingsDialog::SettingsDialog(QWidget *parent): QDialog(parent) {
|
||||
auto const lyt = new QVBoxLayout(this);
|
||||
auto const tabs = new QTabWidget(this);
|
||||
lyt->addWidget(tabs);
|
||||
tabs->addTab(setupImageConfig(tabs), tr("&Image"));
|
||||
tabs->addTab(setupViewConfig(tabs), tr("&Views"));
|
||||
tabs->addTab(setupNetworkInputs(tabs), tr("&Network"));
|
||||
lyt->addWidget(setupButtons(this));
|
||||
@ -81,6 +85,32 @@ QWidget *SettingsDialog::setupNetworkInputs(QWidget *parent) {
|
||||
return root;
|
||||
}
|
||||
|
||||
QWidget *SettingsDialog::setupImageConfig(QWidget *parent) {
|
||||
auto const root = new QWidget(parent);
|
||||
auto const lyt = new QFormLayout(root);
|
||||
m_videoConfig = getVideoConfig();
|
||||
auto const mkSb = [parent, lyt](QString lbl) {
|
||||
auto const s = new QSpinBox(parent);
|
||||
s->setAlignment(Qt::AlignRight);
|
||||
s->setRange(0, 14);
|
||||
lyt->addRow(lbl, s);
|
||||
return s;
|
||||
};
|
||||
auto const presetNo = new QComboBox(parent);
|
||||
connect(presetNo, &QComboBox::currentIndexChanged, this, &SettingsDialog::updateVidConfigPreset);
|
||||
for (auto i = 0; i < MaxCameraPresets; ++i) {
|
||||
presetNo->addItem(tr("Camera Preset %1").arg(i + 1));
|
||||
}
|
||||
lyt->addRow(presetNo);
|
||||
m_vidBrightness = mkSb(tr("&Brightness:"));
|
||||
m_vidSaturation = mkSb(tr("&Saturation:"));
|
||||
m_vidContrast = mkSb(tr("C&ontrast:"));
|
||||
m_vidSharpness = mkSb(tr("Sh&arpness:"));
|
||||
m_vidHue = mkSb(tr("&Hue:"));
|
||||
updateVidConfigPreset(0);
|
||||
return root;
|
||||
}
|
||||
|
||||
QWidget *SettingsDialog::setupViewConfig(QWidget *parent) {
|
||||
auto const root = new QWidget(parent);
|
||||
auto const lyt = new QVBoxLayout(root);
|
||||
@ -177,6 +207,8 @@ void SettingsDialog::handleOK() {
|
||||
.host = m_obsHostLe->text(),
|
||||
.port = m_obsPortLe->text().toUShort(),
|
||||
});
|
||||
collectVideoConfig();
|
||||
setVideoConfig(settings, m_videoConfig);
|
||||
accept();
|
||||
}
|
||||
|
||||
@ -220,3 +252,38 @@ int SettingsDialog::collectViews(QVector<View> &views) const {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SettingsDialog::collectVideoConfig() {
|
||||
auto &vc = m_videoConfig[m_vidCurrentPreset];
|
||||
auto constexpr getVal = [](int &val, QSpinBox *src) {
|
||||
if (src) {
|
||||
val = src->value();
|
||||
}
|
||||
};
|
||||
getVal(vc.brightness, m_vidBrightness);
|
||||
getVal(vc.saturation, m_vidSaturation);
|
||||
getVal(vc.contrast, m_vidContrast);
|
||||
getVal(vc.sharpness, m_vidSharpness);
|
||||
getVal(vc.hue, m_vidHue);
|
||||
}
|
||||
|
||||
void SettingsDialog::updateVidConfigPreset(int preset) {
|
||||
// update to new value
|
||||
auto constexpr setVal = [](int val, QSpinBox *dst) {
|
||||
if (dst) {
|
||||
dst->setValue(val);
|
||||
}
|
||||
};
|
||||
auto const&vc = m_videoConfig[preset];
|
||||
setVal(vc.brightness, m_vidBrightness);
|
||||
setVal(vc.saturation, m_vidSaturation);
|
||||
setVal(vc.contrast, m_vidContrast);
|
||||
setVal(vc.sharpness, m_vidSharpness);
|
||||
setVal(vc.hue, m_vidHue);
|
||||
m_vidCurrentPreset = preset;
|
||||
}
|
||||
|
||||
void SettingsDialog::updateVidConfigPresetCollect(int preset) {
|
||||
collectVideoConfig();
|
||||
updateVidConfigPreset(preset);
|
||||
}
|
||||
|
@ -10,11 +10,13 @@
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#include "consts.hpp"
|
||||
#include "settingsdata.hpp"
|
||||
|
||||
class SettingsDialog: public QDialog {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QVector<VideoConfig> m_videoConfig = QVector<VideoConfig>(MaxCameraPresets);
|
||||
class QLabel *m_errLbl = nullptr;
|
||||
class QLineEdit *m_cameraHostLe = nullptr;
|
||||
class QLineEdit *m_cameraPortLe = nullptr;
|
||||
@ -22,12 +24,19 @@ class SettingsDialog: public QDialog {
|
||||
class QLineEdit *m_openLpPortLe = nullptr;
|
||||
class QLineEdit *m_obsHostLe = nullptr;
|
||||
class QLineEdit *m_obsPortLe = nullptr;
|
||||
class QSpinBox *m_vidBrightness = nullptr;
|
||||
class QSpinBox *m_vidSaturation = nullptr;
|
||||
class QSpinBox *m_vidContrast = nullptr;
|
||||
class QSpinBox *m_vidSharpness = nullptr;
|
||||
class QSpinBox *m_vidHue = nullptr;
|
||||
int m_vidCurrentPreset = 0;
|
||||
class QTableWidget *m_viewTable = nullptr;
|
||||
public:
|
||||
explicit SettingsDialog(QWidget *parent);
|
||||
private:
|
||||
QWidget *setupNetworkInputs(QWidget *parent);
|
||||
QWidget *setupViewConfig(QWidget *parent);
|
||||
QWidget *setupImageConfig(QWidget *parent);
|
||||
QWidget *setupButtons(QWidget *parent);
|
||||
void handleOK();
|
||||
void setupViewRow(int row, View const&view = {});
|
||||
@ -37,4 +46,7 @@ class SettingsDialog: public QDialog {
|
||||
*/
|
||||
[[nodiscard("Must check error code")]]
|
||||
int collectViews(QVector<View> &views) const;
|
||||
void collectVideoConfig();
|
||||
void updateVidConfigPreset(int preset);
|
||||
void updateVidConfigPresetCollect(int preset);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user