From 08dc59c88561baa7dae422187060489c9b6b6f02 Mon Sep 17 00:00:00 2001 From: LordGrey <48840279+Lord-Grey@users.noreply.github.com> Date: Sun, 1 Oct 2023 21:56:53 +0200 Subject: [PATCH] Fix #1630 - Audio Capture settings are ignored (#1640) * Fix macOS build * Update minimum cmake version * Correct compile errorswith Qt6.7 * Update minimum cmake version (2) * Use C++17 * Correct compile errors with Qt6.7 * Replace unsupported Lambda UniqueConnection * Support UTF-8 Output on console * Fix #1630 --- CMakeLists.txt | 34 +++++++------- assets/webconfig/js/content_grabber.js | 6 +-- cmake/Dependencies.cmake | 1 + dependencies/CMakeLists-qmdnsengine.txt.in | 2 +- dependencies/CMakeLists.txt | 8 ++-- include/api/JsonAPI.h | 5 ++ include/grabber/AudioGrabberWindows.h | 14 +++--- include/hyperion/ImageToLedsMap.h | 10 ++-- include/utils/global_defines.h | 2 +- libsrc/api/JsonAPI.cpp | 37 +++++++++------ libsrc/api/JsonCB.cpp | 2 +- libsrc/db/DBManager.cpp | 11 +++-- libsrc/effectengine/EffectFileHandler.cpp | 12 ++--- libsrc/forwarder/MessageForwarder.cpp | 10 ++-- libsrc/grabber/audio/AudioGrabber.cpp | 46 +++++++++++++------ libsrc/grabber/audio/AudioGrabberWindows.cpp | 8 +++- libsrc/grabber/audio/CMakeLists.txt | 2 +- libsrc/grabber/qt/QtGrabber.cpp | 2 +- libsrc/hyperion/ComponentRegister.cpp | 2 +- libsrc/hyperion/SettingsManager.cpp | 32 ++++++++----- .../leddevice/dev_net/LedDevicePhilipsHue.cpp | 2 +- libsrc/leddevice/dev_net/LedDeviceWled.cpp | 8 ++-- libsrc/utils/Logger.cpp | 2 +- .../utils/jsonschema/QJsonSchemaChecker.cpp | 4 +- src/hyperion-aml/CMakeLists.txt | 2 +- src/hyperion-dispmanx/CMakeLists.txt | 2 +- src/hyperion-framebuffer/CMakeLists.txt | 2 +- src/hyperion-osx/CMakeLists.txt | 2 +- src/hyperion-qt/CMakeLists.txt | 2 +- src/hyperion-remote/CMakeLists.txt | 2 +- src/hyperion-remote/hyperion-remote.cpp | 4 +- src/hyperion-v4l2/CMakeLists.txt | 2 +- src/hyperion-x11/CMakeLists.txt | 2 +- src/hyperion-xcb/CMakeLists.txt | 2 +- src/hyperiond/console.h | 1 + src/hyperiond/main.cpp | 4 +- 36 files changed, 169 insertions(+), 120 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cbb1ef3f..813cb750 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1.0) +cmake_minimum_required(VERSION 3.5.0) message( STATUS "CMake Version: ${CMAKE_VERSION}" ) @@ -38,26 +38,24 @@ if ( CCACHE_FOUND ) set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) endif(CCACHE_FOUND) -# enable C++14; MSVC doesn't have c++14 feature switch -if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC") - if(APPLE) - include(CheckCXXCompilerFlag) - CHECK_CXX_COMPILER_FLAG("Werror=unguarded-availability" REQUIRED_UNGUARDED_AVAILABILITY) - if(REQUIRED_UNGUARDED_AVAILABILITY) - list(APPEND CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} "Werror=unguarded-availability") - endif() +# enable C++17 +if(APPLE) + include(CheckCXXCompilerFlag) + CHECK_CXX_COMPILER_FLAG("Werror=unguarded-availability" REQUIRED_UNGUARDED_AVAILABILITY) + if(REQUIRED_UNGUARDED_AVAILABILITY) + list(APPEND CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} "Werror=unguarded-availability") endif() - - if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "GNU") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-psabi") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-psabi") - endif() - - set(CMAKE_CXX_STANDARD 14) - set(CXX_STANDARD_REQUIRED ON) - set(CXX_EXTENSIONS OFF) endif() +if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "GNU") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-psabi") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-psabi") +endif() + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + # Set build variables # Grabber SET ( DEFAULT_AMLOGIC OFF ) diff --git a/assets/webconfig/js/content_grabber.js b/assets/webconfig/js/content_grabber.js index 20da6030..6136673a 100755 --- a/assets/webconfig/js/content_grabber.js +++ b/assets/webconfig/js/content_grabber.js @@ -327,7 +327,7 @@ $(document).ready(function () { var saveOptions = conf_editor_screen.getValue(); var instCaptOptions = window.serverConfig.instCapture; - instCaptOptions.systemEnable = true; + instCaptOptions.systemEnable = saveOptions.framegrabber.enable; saveOptions.instCapture = instCaptOptions; requestWriteConfig(saveOptions); @@ -679,7 +679,7 @@ $(document).ready(function () { var saveOptions = conf_editor_video.getValue(); var instCaptOptions = window.serverConfig.instCapture; - instCaptOptions.v4lEnable = true; + instCaptOptions.v4lEnable = saveOptions.grabberV4L2.enable; saveOptions.instCapture = instCaptOptions; requestWriteConfig(saveOptions); @@ -805,7 +805,7 @@ $(document).ready(function () { const saveOptions = conf_editor_audio.getValue(); const instCaptOptions = window.serverConfig.instCapture; - instCaptOptions.audioEnable = true; + instCaptOptions.audioEnable = saveOptions.grabberAudio.enable; saveOptions.instCapture = instCaptOptions; requestWriteConfig(saveOptions); diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index 08120831..40ada3e1 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -48,6 +48,7 @@ macro(DeployMacOS TARGET) foreach(PLUGIN "platforms" "sqldrivers" "imageformats") if(EXISTS ${PLUGIN_DIR}/${PLUGIN}) file(GLOB files "${PLUGIN_DIR}/${PLUGIN}/*") + list(FILTER files EXCLUDE REGEX ".*libqwebp\\.dylib$") foreach(file ${files}) file(GET_RUNTIME_DEPENDENCIES EXECUTABLES ${file} diff --git a/dependencies/CMakeLists-qmdnsengine.txt.in b/dependencies/CMakeLists-qmdnsengine.txt.in index 12e45328..b3f0812a 100644 --- a/dependencies/CMakeLists-qmdnsengine.txt.in +++ b/dependencies/CMakeLists-qmdnsengine.txt.in @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.2) +cmake_minimum_required(VERSION 3.5) project(qmdnsengine) diff --git a/dependencies/CMakeLists.txt b/dependencies/CMakeLists.txt index c13e96cc..bc5044be 100644 --- a/dependencies/CMakeLists.txt +++ b/dependencies/CMakeLists.txt @@ -133,6 +133,9 @@ endif() if(ENABLE_PROTOBUF_SERVER) set(USE_SYSTEM_PROTO_LIBS ${DEFAULT_USE_SYSTEM_PROTO_LIBS} CACHE BOOL "use protobuf library from system") + + # defines for 3rd party sub-modules + set(ABSL_PROPAGATE_CXX_STD ON CACHE BOOL "Build abseil-cpp with C++ version requirements propagated") if (USE_SYSTEM_PROTO_LIBS) find_package(Protobuf REQUIRED) @@ -161,9 +164,6 @@ if(ENABLE_PROTOBUF_SERVER) # define the protobuf library set(PROTOBUF_LIBRARIES protobuf::libprotobuf) - # defines for 3rd party sub-modules - set(ABSL_PROPAGATE_CXX_STD ON CACHE BOOL "Build abseil-cpp with C++ version requirements propagated") - endif() # redefine at parent scope @@ -270,7 +270,7 @@ if(ENABLE_DEV_NETWORK) set(USE_SYSTEM_MBEDTLS_LIBS OFF) endif (NOT MBEDTLS_FOUND) else() - cmake_minimum_required(VERSION 3.2) + cmake_minimum_required(VERSION 3.5.1) set(CMAKE_POLICY_DEFAULT_CMP0071 NEW) diff --git a/include/api/JsonAPI.h b/include/api/JsonAPI.h index 6346ce72..3880fc42 100644 --- a/include/api/JsonAPI.h +++ b/include/api/JsonAPI.h @@ -88,6 +88,11 @@ private slots: /// void handleInstanceStateChange(InstanceState state, quint8 instance, const QString &name = QString()); + /// + /// @brief Stream a new LED Colors update + /// + void streamLedColorsUpdate(); + signals: /// /// Signal emits with the reply message provided with handleMessage() diff --git a/include/grabber/AudioGrabberWindows.h b/include/grabber/AudioGrabberWindows.h index 747212c2..9c3945b6 100644 --- a/include/grabber/AudioGrabberWindows.h +++ b/include/grabber/AudioGrabberWindows.h @@ -39,8 +39,8 @@ class AudioGrabberWindows : public AudioGrabber HANDLE notificationEvent; std::atomic isRunning{ false }; -static BOOL CALLBACK DirectSoundEnumProcessor(LPGUID deviceIdGuid, LPCTSTR deviceDescStr, - LPCTSTR deviceModelStr, LPVOID context) +static BOOL CALLBACK DirectSoundEnumProcessor(LPGUID deviceIdGuid, LPCWSTR deviceDescStr, + LPCWSTR deviceModelStr, LPVOID context) { // Skip undefined audio devices if (deviceIdGuid == NULL) @@ -50,12 +50,15 @@ static BOOL CALLBACK DirectSoundEnumProcessor(LPGUID deviceIdGuid, LPCTSTR devic AudioGrabber::DeviceProperties device; + // Process Device Information + QString deviceName = QString::fromWCharArray(deviceDescStr); + // Process Device ID LPOLESTR deviceIdStr; HRESULT res = StringFromCLSID(*deviceIdGuid, &deviceIdStr); if (FAILED(res)) { - Error(Logger::getInstance("AUDIOGRABBER"), "Failed to get CLSID-string for %s with error: 0x%08x: %s", deviceDescStr, res, std::system_category().message(res).c_str()); + Error(Logger::getInstance("AUDIOGRABBER"), "Failed to get CLSID-string for %s with error: 0x%08x: %s", QSTRING_CSTR(deviceName), res, std::system_category().message(res).c_str()); return FALSE; } @@ -63,10 +66,7 @@ static BOOL CALLBACK DirectSoundEnumProcessor(LPGUID deviceIdGuid, LPCTSTR devic CoTaskMemFree(deviceIdStr); - // Process Device Information - QString deviceName = QString::fromLocal8Bit(deviceDescStr); - - Debug(Logger::getInstance("AUDIOGRABBER"), "Found Audio Device: %s", deviceDescStr); + Debug(Logger::getInstance("AUDIOGRABBER"), "Found Audio Device: %s", QSTRING_CSTR(deviceName)); device.id = deviceId; device.name = deviceName; diff --git a/include/hyperion/ImageToLedsMap.h b/include/hyperion/ImageToLedsMap.h index 17662f28..45e7bb5a 100644 --- a/include/hyperion/ImageToLedsMap.h +++ b/include/hyperion/ImageToLedsMap.h @@ -413,9 +413,13 @@ namespace hyperion } // Compute the average of each color channel - const uint8_t avgRed = uint8_t(std::min(std::lround(sqrt(static_cast(cummRed/pixelNum))), 255L)); - const uint8_t avgGreen = uint8_t(std::min(std::lround(sqrt(static_cast(cummGreen/pixelNum))), 255L)); - const uint8_t avgBlue = uint8_t(std::min(std::lround(sqrt(static_cast(cummBlue/pixelNum))), 255L)); + + #ifdef WIN32 + #undef min + #endif + const uint8_t avgRed = static_cast(std::min(std::lround(std::sqrt(static_cast(cummRed / pixelNum))), 255L)); + const uint8_t avgGreen = static_cast(std::min(std::lround(sqrt(static_cast(cummGreen / pixelNum))), 255L)); + const uint8_t avgBlue = static_cast(std::min(std::lround(sqrt(static_cast(cummBlue / pixelNum))), 255L)); // Return the computed color return {avgRed, avgGreen, avgBlue}; diff --git a/include/utils/global_defines.h b/include/utils/global_defines.h index e5a6808e..e948fb97 100644 --- a/include/utils/global_defines.h +++ b/include/utils/global_defines.h @@ -1,6 +1,6 @@ #pragma once -#define QSTRING_CSTR(str) str.toLocal8Bit().constData() +#define QSTRING_CSTR(str) str.toUtf8().constData() typedef QList< int > QIntList; diff --git a/libsrc/api/JsonAPI.cpp b/libsrc/api/JsonAPI.cpp index 212dc14b..75863ca2 100644 --- a/libsrc/api/JsonAPI.cpp +++ b/libsrc/api/JsonAPI.cpp @@ -140,6 +140,8 @@ void JsonAPI::initialize() connect(this, &JsonAPI::toggleSuspendAll, _instanceManager, &HyperionIManager::triggerToggleSuspend); connect(this, &JsonAPI::idleAll, _instanceManager, &HyperionIManager::triggerIdle); connect(this, &JsonAPI::toggleIdleAll, _instanceManager, &HyperionIManager::triggerToggleIdle); + + connect(_ledStreamTimer, &QTimer::timeout, this, &JsonAPI::streamLedColorsUpdate, Qt::UniqueConnection); } bool JsonAPI::handleInstanceSwitch(quint8 inst, bool forced) @@ -404,7 +406,7 @@ void JsonAPI::handleServerInfoCommand(const QJsonObject &message, const QString activePriorities.removeAll(PriorityMuxer::LOWEST_PRIORITY); int currentPriority = _hyperion->getCurrentPriority(); - for(int priority : qAsConst(activePriorities)) + for(int priority : std::as_const(activePriorities)) { const Hyperion::InputInfo &priorityInfo = _hyperion->getPriorityInfo(priority); @@ -1139,6 +1141,11 @@ void JsonAPI::handleComponentStateCommand(const QJsonObject &message, const QStr sendSuccessReply(command, tan); } +void JsonAPI::streamLedColorsUpdate() +{ + emit streamLedcolorsUpdate(_currentLedValues); +} + void JsonAPI::handleLedColorsCommand(const QJsonObject &message, const QString &command, int tan) { // create result @@ -1154,21 +1161,21 @@ void JsonAPI::handleLedColorsCommand(const QJsonObject &message, const QString & _streaming_leds_reply["tan"] = tan; connect(_hyperion, &Hyperion::rawLedColors, this, [=](const std::vector &ledValues) { - _currentLedValues = ledValues; - // necessary because Qt::UniqueConnection for lambdas does not work until 5.9 - // see: https://bugreports.qt.io/browse/QTBUG-52438 - if (!_ledStreamConnection) - _ledStreamConnection = connect(_ledStreamTimer, &QTimer::timeout, this, [=]() { - emit streamLedcolorsUpdate(_currentLedValues); - }, - Qt::UniqueConnection); + if (ledValues != _currentLedValues) + { + _currentLedValues = ledValues; + if (!_ledStreamTimer->isActive() || _ledStreamTimer->interval() != streaming_interval) + { + _ledStreamTimer->start(streaming_interval); + } + } + else + { + _ledStreamTimer->stop(); + } + }); - // start the timer - if (!_ledStreamTimer->isActive() || _ledStreamTimer->interval() != streaming_interval) - _ledStreamTimer->start(streaming_interval); - }, - Qt::UniqueConnection); // push once _hyperion->update(); } @@ -1387,7 +1394,7 @@ void JsonAPI::handleAuthorizeCommand(const QJsonObject &message, const QString & if (API::getPendingTokenRequests(vec)) { QJsonArray arr; - for (const auto &entry : qAsConst(vec)) + for (const auto &entry : std::as_const(vec)) { QJsonObject obj; obj["comment"] = entry.comment; diff --git a/libsrc/api/JsonCB.cpp b/libsrc/api/JsonCB.cpp index 965abf37..e3c4b32a 100644 --- a/libsrc/api/JsonCB.cpp +++ b/libsrc/api/JsonCB.cpp @@ -199,7 +199,7 @@ void JsonCB::handlePriorityUpdate(int currentPriority, const PriorityMuxer::Inpu activePriorities.removeAll(PriorityMuxer::LOWEST_PRIORITY); - for (int priority : qAsConst(activePriorities)) { + for (int priority : std::as_const(activePriorities)) { const Hyperion::InputInfo& priorityInfo = activeInputs[priority]; diff --git a/libsrc/db/DBManager.cpp b/libsrc/db/DBManager.cpp index a8711c15..f4494967 100644 --- a/libsrc/db/DBManager.cpp +++ b/libsrc/db/DBManager.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #ifdef _WIN32 #include @@ -425,15 +426,15 @@ void DBManager::doAddBindValue(QSqlQuery& query, const QVariantList& variants) c auto t = variant.userType(); switch(t) { - case QVariant::UInt: - case QVariant::Int: - case QVariant::Bool: + case QMetaType::UInt: + case QMetaType::Int: + case QMetaType::Bool: query.addBindValue(variant.toInt()); break; - case QVariant::Double: + case QMetaType::Double: query.addBindValue(variant.toFloat()); break; - case QVariant::ByteArray: + case QMetaType::QByteArray: query.addBindValue(variant.toByteArray()); break; default: diff --git a/libsrc/effectengine/EffectFileHandler.cpp b/libsrc/effectengine/EffectFileHandler.cpp index e1389e83..3d1c77eb 100644 --- a/libsrc/effectengine/EffectFileHandler.cpp +++ b/libsrc/effectengine/EffectFileHandler.cpp @@ -224,7 +224,7 @@ void EffectFileHandler::updateEffects() } QMap availableEffects; - for (const QString& path : qAsConst(efxPathList)) + for (const QString& path : std::as_const(efxPathList)) { QDir directory(path); if (!directory.exists()) @@ -241,8 +241,8 @@ void EffectFileHandler::updateEffects() else { int efxCount = 0; - QStringList filenames = directory.entryList(QStringList() << "*.json", QDir::Files, QDir::Name | QDir::IgnoreCase); - for (const QString& filename : qAsConst(filenames)) + const QStringList filenames = directory.entryList(QStringList() << "*.json", QDir::Files, QDir::Name | QDir::IgnoreCase); + for (const QString& filename : filenames) { EffectDefinition def; if (loadEffectDefinition(path, filename, def)) @@ -268,8 +268,8 @@ void EffectFileHandler::updateEffects() QString schemaPath = path + "schema" + '/'; directory.setPath(schemaPath); - QStringList schemaFileNames = directory.entryList(QStringList() << "*.json", QDir::Files, QDir::Name | QDir::IgnoreCase); - for (const QString& schemaFileName : qAsConst(schemaFileNames)) + const QStringList schemaFileNames = directory.entryList(QStringList() << "*.json", QDir::Files, QDir::Name | QDir::IgnoreCase); + for (const QString& schemaFileName : schemaFileNames) { EffectSchema pyEffect; if (loadEffectSchema(path, directory.filePath(schemaFileName), pyEffect)) @@ -282,7 +282,7 @@ void EffectFileHandler::updateEffects() } } - for (const auto& item : qAsConst(availableEffects)) + for (const auto& item : std::as_const(availableEffects)) { _availableEffects.push_back(item); } diff --git a/libsrc/forwarder/MessageForwarder.cpp b/libsrc/forwarder/MessageForwarder.cpp index b795cbe8..3720ad54 100644 --- a/libsrc/forwarder/MessageForwarder.cpp +++ b/libsrc/forwarder/MessageForwarder.cpp @@ -269,7 +269,7 @@ int MessageForwarder::startJsonTargets(const QJsonObject& config) if (!_jsonTargets.isEmpty()) { - for (const auto& targetHost : qAsConst(_jsonTargets)) + for (const auto& targetHost : std::as_const(_jsonTargets)) { Info(_log, "Forwarding now to JSON-target host: %s port: %u", QSTRING_CSTR(targetHost.host.toString()), targetHost.port); } @@ -286,7 +286,7 @@ void MessageForwarder::stopJsonTargets() if (!_jsonTargets.isEmpty()) { disconnect(_hyperion, &Hyperion::forwardJsonMessage, nullptr, nullptr); - for (const auto& targetHost : qAsConst(_jsonTargets)) + for (const auto& targetHost : std::as_const(_jsonTargets)) { Info(_log, "Stopped forwarding to JSON-target host: %s port: %u", QSTRING_CSTR(targetHost.host.toString()), targetHost.port); } @@ -373,7 +373,7 @@ int MessageForwarder::startFlatbufferTargets(const QJsonObject& config) if (!_flatbufferTargets.isEmpty()) { - for (const auto& targetHost : qAsConst(_flatbufferTargets)) + for (const auto& targetHost : std::as_const(_flatbufferTargets)) { Info(_log, "Forwarding now to Flatbuffer-target host: %s port: %u", QSTRING_CSTR(targetHost.host.toString()), targetHost.port); } @@ -399,7 +399,7 @@ void MessageForwarder::stopFlatbufferTargets() _messageForwarderFlatBufHelper = nullptr; } - for (const auto& targetHost : qAsConst(_flatbufferTargets)) + for (const auto& targetHost : std::as_const(_flatbufferTargets)) { Info(_log, "Stopped forwarding to Flatbuffer-target host: %s port: %u", QSTRING_CSTR(targetHost.host.toString()), targetHost.port); } @@ -412,7 +412,7 @@ void MessageForwarder::forwardJsonMessage(const QJsonObject& message) if (_forwarder_enabled) { QTcpSocket client; - for (const auto& targetHost : qAsConst(_jsonTargets)) + for (const auto& targetHost : std::as_const(_jsonTargets)) { client.connectToHost(targetHost.host, targetHost.port); if (client.waitForConnected(CONNECT_TIMEOUT.count())) diff --git a/libsrc/grabber/audio/AudioGrabber.cpp b/libsrc/grabber/audio/AudioGrabber.cpp index 1e625a1e..4f4eccbd 100644 --- a/libsrc/grabber/audio/AudioGrabber.cpp +++ b/libsrc/grabber/audio/AudioGrabber.cpp @@ -9,6 +9,15 @@ // Constants namespace { const uint16_t RESOLUTION = 255; + + //Constants vuMeter + const QJsonArray DEFAULT_HOTCOLOR { 255,0,0 }; + const QJsonArray DEFAULT_WARNCOLOR { 255,255,0 }; + const QJsonArray DEFAULT_SAFECOLOR { 0,255,0 }; + const int DEFAULT_WARNVALUE { 80 }; + const int DEFAULT_SAFEVALUE { 45 }; + const int DEFAULT_MULTIPLIER { 0 }; + const int DEFAULT_TOLERANCE { 20 }; } #if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0)) @@ -28,12 +37,12 @@ AudioGrabber::AudioGrabber() , _deviceProperties() , _device("none") , _hotColor(QColorConstants::Red) - , _warnValue(80) + , _warnValue(DEFAULT_WARNVALUE) , _warnColor(QColorConstants::Yellow) - , _safeValue(45) + , _safeValue(DEFAULT_SAFEVALUE) , _safeColor(QColorConstants::Green) - , _multiplier(0) - , _tolerance(20) + , _multiplier(DEFAULT_MULTIPLIER) + , _tolerance(DEFAULT_TOLERANCE) , _dynamicMultiplier(INT16_MAX) , _started(false) { @@ -61,18 +70,27 @@ void AudioGrabber::setDevice(const QString& device) void AudioGrabber::setConfiguration(const QJsonObject& config) { - QJsonArray hotColorArray = config["hotColor"].toArray(QJsonArray::fromVariantList(QList({ QVariant(255), QVariant(0), QVariant(0) }))); - QJsonArray warnColorArray = config["warnColor"].toArray(QJsonArray::fromVariantList(QList({ QVariant(255), QVariant(255), QVariant(0) }))); - QJsonArray safeColorArray = config["safeColor"].toArray(QJsonArray::fromVariantList(QList({ QVariant(0), QVariant(255), QVariant(0) }))); + QString audioEffect = config["audioEffect"].toString(); + QJsonObject audioEffectConfig = config[audioEffect].toObject(); - _hotColor = QColor(hotColorArray.at(0).toInt(), hotColorArray.at(1).toInt(), hotColorArray.at(2).toInt()); - _warnColor = QColor(warnColorArray.at(0).toInt(), warnColorArray.at(1).toInt(), warnColorArray.at(2).toInt()); - _safeColor = QColor(safeColorArray.at(0).toInt(), safeColorArray.at(1).toInt(), safeColorArray.at(2).toInt()); + if (audioEffect == "vuMeter") + { + QJsonArray hotColorArray = audioEffectConfig.value("hotColor").toArray(DEFAULT_HOTCOLOR); + QJsonArray warnColorArray = audioEffectConfig.value("warnColor").toArray(DEFAULT_WARNCOLOR); + QJsonArray safeColorArray = audioEffectConfig.value("safeColor").toArray(DEFAULT_SAFECOLOR); - _warnValue = config["warnValue"].toInt(80); - _safeValue = config["safeValue"].toInt(45); - _multiplier = config["multiplier"].toDouble(0); - _tolerance = config["tolerance"].toInt(20); + _hotColor = QColor(hotColorArray.at(0).toInt(), hotColorArray.at(1).toInt(), hotColorArray.at(2).toInt()); + _warnColor = QColor(warnColorArray.at(0).toInt(), warnColorArray.at(1).toInt(), warnColorArray.at(2).toInt()); + _safeColor = QColor(safeColorArray.at(0).toInt(), safeColorArray.at(1).toInt(), safeColorArray.at(2).toInt()); + _warnValue = audioEffectConfig["warnValue"].toInt(DEFAULT_WARNVALUE); + _safeValue = audioEffectConfig["safeValue"].toInt(DEFAULT_SAFEVALUE); + _multiplier = audioEffectConfig["multiplier"].toDouble(DEFAULT_MULTIPLIER); + _tolerance = audioEffectConfig["tolerance"].toInt(DEFAULT_MULTIPLIER); + } + else + { + Error(_log, "Unknow Audio-Effect: \"%s\" configured", QSTRING_CSTR(audioEffect)); + } } void AudioGrabber::resetMultiplier() diff --git a/libsrc/grabber/audio/AudioGrabberWindows.cpp b/libsrc/grabber/audio/AudioGrabberWindows.cpp index 07837bd1..8a2228c3 100644 --- a/libsrc/grabber/audio/AudioGrabberWindows.cpp +++ b/libsrc/grabber/audio/AudioGrabberWindows.cpp @@ -1,4 +1,7 @@ #include + +#include + #include #include #include @@ -61,7 +64,10 @@ bool AudioGrabberWindows::configureCaptureInterface() // wFormatTag, nChannels, nSamplesPerSec, mAvgBytesPerSec, // nBlockAlign, wBitsPerSample, cbSize - notificationSize = max(1024, audioFormat.nAvgBytesPerSec / 8); + #ifdef WIN32 + #undef max + #endif + notificationSize = std::max(static_cast(1024), static_cast(audioFormat.nAvgBytesPerSec / 8)); notificationSize -= notificationSize % audioFormat.nBlockAlign; bufferCaptureSize = notificationSize * AUDIO_NOTIFICATION_COUNT; diff --git a/libsrc/grabber/audio/CMakeLists.txt b/libsrc/grabber/audio/CMakeLists.txt index 187fa9d0..714c5883 100644 --- a/libsrc/grabber/audio/CMakeLists.txt +++ b/libsrc/grabber/audio/CMakeLists.txt @@ -2,8 +2,8 @@ SET( CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/include/grabber ) SET( CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/grabber/audio ) - if (WIN32) + add_definitions(-DUNICODE -D_UNICODE) FILE ( GLOB AUDIO_GRABBER_SOURCES "${CURRENT_HEADER_DIR}/Audio*Windows.h" "${CURRENT_HEADER_DIR}/AudioGrabber.h" "${CURRENT_HEADER_DIR}/AudioWrapper.h" "${CURRENT_SOURCE_DIR}/*.h" "${CURRENT_SOURCE_DIR}/*Windows.cpp" "${CURRENT_SOURCE_DIR}/AudioGrabber.cpp" "${CURRENT_SOURCE_DIR}/AudioWrapper.cpp") elseif(${CMAKE_SYSTEM} MATCHES "Linux") FILE ( GLOB AUDIO_GRABBER_SOURCES "${CURRENT_HEADER_DIR}/Audio*Linux.h" "${CURRENT_HEADER_DIR}/AudioGrabber.h" "${CURRENT_HEADER_DIR}/AudioWrapper.h" "${CURRENT_SOURCE_DIR}/*.h" "${CURRENT_SOURCE_DIR}/*Linux.cpp" "${CURRENT_SOURCE_DIR}/AudioGrabber.cpp" "${CURRENT_SOURCE_DIR}/AudioWrapper.cpp") diff --git a/libsrc/grabber/qt/QtGrabber.cpp b/libsrc/grabber/qt/QtGrabber.cpp index b3f35182..cb6e0c5c 100644 --- a/libsrc/grabber/qt/QtGrabber.cpp +++ b/libsrc/grabber/qt/QtGrabber.cpp @@ -103,7 +103,7 @@ bool QtGrabber::setupDisplay() Info(_log, "Available Displays:"); int index = 0; - for (auto* screen : qAsConst(screens)) + for (auto* screen : std::as_const(screens)) { const QRect geo = screen->geometry(); Info(_log, "Display %d: Name: %s Resolution: [%dx%d], Geometry: (L,T,R,B) %d,%d,%d,%d Depth:%dbit", index, QSTRING_CSTR(screen->name()), geo.width(), geo.height(), geo.x(), geo.y(), geo.x() + geo.width(), geo.y() + geo.height(), screen->depth()); diff --git a/libsrc/hyperion/ComponentRegister.cpp b/libsrc/hyperion/ComponentRegister.cpp index fd2f261d..9a040caf 100644 --- a/libsrc/hyperion/ComponentRegister.cpp +++ b/libsrc/hyperion/ComponentRegister.cpp @@ -61,7 +61,7 @@ ComponentRegister::ComponentRegister(Hyperion* hyperion) vect << COMP_FORWARDER; #endif - for(auto e : qAsConst(vect)) + for(auto e : std::as_const(vect)) { _componentStates.emplace(e, (e == COMP_ALL)); } diff --git a/libsrc/hyperion/SettingsManager.cpp b/libsrc/hyperion/SettingsManager.cpp index b9d78edc..e9fa5805 100644 --- a/libsrc/hyperion/SettingsManager.cpp +++ b/libsrc/hyperion/SettingsManager.cpp @@ -58,9 +58,9 @@ SettingsManager::SettingsManager(quint8 instance, QObject* parent, bool readonly } // transform json to string lists - QStringList keyList = defaultConfig.keys(); + const QStringList keyList = defaultConfig.keys(); QStringList defValueList; - for (const auto& key : qAsConst(keyList)) + for (const auto& key : keyList) { if (defaultConfig[key].isObject()) { @@ -73,7 +73,7 @@ SettingsManager::SettingsManager(quint8 instance, QObject* parent, bool readonly } // fill database with default data if required - for (const auto& key : qAsConst(keyList)) + for (const auto& key : keyList) { QString val = defValueList.takeFirst(); // prevent overwrite @@ -86,7 +86,7 @@ SettingsManager::SettingsManager(quint8 instance, QObject* parent, bool readonly // need to validate all data in database construct the entire data object // TODO refactor schemaChecker to accept QJsonArray in validate(); QJsonDocument container? To validate them per entry... QJsonObject dbConfig; - for (const auto& key : qAsConst(keyList)) + for (const auto& key : keyList) { QJsonDocument doc = _sTable->getSettingsRecord(key); if (doc.isArray()) @@ -242,9 +242,9 @@ bool SettingsManager::saveSettings(QJsonObject config, bool correct) _qconfig = config; // extract keys and data - QStringList keyList = config.keys(); + const QStringList keyList = config.keys(); QStringList newValueList; - for (const auto& key : qAsConst(keyList)) + for (const auto& key : keyList) { if (config[key].isObject()) { @@ -258,7 +258,7 @@ bool SettingsManager::saveSettings(QJsonObject config, bool correct) bool rc = true; // compare database data with new data to emit/save changes accordingly - for (const auto& key : qAsConst(keyList)) + for (const auto& key : keyList) { QString data = newValueList.takeFirst(); if (_sTable->getSettingsRecordString(key) != data) @@ -269,7 +269,15 @@ bool SettingsManager::saveSettings(QJsonObject config, bool correct) } else { - emit settingsChanged(settings::stringToType(key), QJsonDocument::fromJson(data.toLocal8Bit())); + QJsonParseError error; + QJsonDocument jsonDocument = QJsonDocument::fromJson(data.toUtf8(), &error); + if (error.error != QJsonParseError::NoError) { + Error(_log, "Error parsing JSON: %s", QSTRING_CSTR(error.errorString())); + rc = false; + } + else { + emit settingsChanged(settings::stringToType(key), jsonDocument); + } } } } @@ -618,10 +626,10 @@ bool SettingsManager::handleConfigUpgrade(QJsonObject& config) QJsonArray json; if (newForwarderConfig.contains("json")) { - QJsonArray oldJson = newForwarderConfig["json"].toArray(); + const QJsonArray oldJson = newForwarderConfig["json"].toArray(); QJsonObject newJsonConfig; - for (const QJsonValue& value : qAsConst(oldJson)) + for (const QJsonValue& value : oldJson) { if (value.isString()) { @@ -661,10 +669,10 @@ bool SettingsManager::handleConfigUpgrade(QJsonObject& config) QJsonArray flatbuffer; if (newForwarderConfig.contains("flat")) { - QJsonArray oldFlatbuffer = newForwarderConfig["flat"].toArray(); + const QJsonArray oldFlatbuffer = newForwarderConfig["flat"].toArray(); QJsonObject newFlattbufferConfig; - for (const QJsonValue& value : qAsConst(oldFlatbuffer)) + for (const QJsonValue& value : oldFlatbuffer) { if (value.isString()) { diff --git a/libsrc/leddevice/dev_net/LedDevicePhilipsHue.cpp b/libsrc/leddevice/dev_net/LedDevicePhilipsHue.cpp index 8f73ae5f..ba008ab0 100644 --- a/libsrc/leddevice/dev_net/LedDevicePhilipsHue.cpp +++ b/libsrc/leddevice/dev_net/LedDevicePhilipsHue.cpp @@ -1126,7 +1126,7 @@ bool LedDevicePhilipsHue::setLights() if( !lArray.empty() ) { - for (const QJsonValue &id : qAsConst(lArray)) + for (const QJsonValue &id : std::as_const(lArray)) { int lightId = id.toString().toInt(); if( lightId > 0 ) diff --git a/libsrc/leddevice/dev_net/LedDeviceWled.cpp b/libsrc/leddevice/dev_net/LedDeviceWled.cpp index 3ada5091..e23a8c9b 100644 --- a/libsrc/leddevice/dev_net/LedDeviceWled.cpp +++ b/libsrc/leddevice/dev_net/LedDeviceWled.cpp @@ -352,12 +352,12 @@ bool LedDeviceWled::powerOn() } else { - QJsonArray propertiesSegments = _originalStateProperties[STATE_SEG].toArray(); + const QJsonArray propertiesSegments = _originalStateProperties[STATE_SEG].toArray(); bool isStreamSegmentIdFound { false }; QJsonArray segments; - for (const auto& segmentItem : qAsConst(propertiesSegments)) + for (const auto& segmentItem : propertiesSegments) { QJsonObject segmentObj = segmentItem.toObject(); @@ -505,9 +505,9 @@ bool LedDeviceWled::restoreState() if (_isStreamToSegment) { - QJsonArray propertiesSegments = _originalStateProperties[STATE_SEG].toArray(); + const QJsonArray propertiesSegments = _originalStateProperties[STATE_SEG].toArray(); QJsonArray segments; - for (const auto& segmentItem : qAsConst(propertiesSegments)) + for (const auto& segmentItem : propertiesSegments) { QJsonObject segmentObj = segmentItem.toObject(); diff --git a/libsrc/utils/Logger.cpp b/libsrc/utils/Logger.cpp index 86b4e903..b34981c9 100644 --- a/libsrc/utils/Logger.cpp +++ b/libsrc/utils/Logger.cpp @@ -65,7 +65,7 @@ void Logger::deleteInstance(const QString & name, const QString & subName) if (name.isEmpty()) { - for (auto *logger : qAsConst(LoggerMap)) { + for (auto *logger : std::as_const(LoggerMap)) { delete logger; } diff --git a/libsrc/utils/jsonschema/QJsonSchemaChecker.cpp b/libsrc/utils/jsonschema/QJsonSchemaChecker.cpp index 685ab4c7..8cd0be75 100644 --- a/libsrc/utils/jsonschema/QJsonSchemaChecker.cpp +++ b/libsrc/utils/jsonschema/QJsonSchemaChecker.cpp @@ -59,13 +59,13 @@ QPair QJsonSchemaChecker::validate(const QJsonObject& value, bool ig QJsonObject QJsonSchemaChecker::getAutoCorrectedConfig(const QJsonObject& value, bool ignoreRequired) { _ignoreRequired = ignoreRequired; - QStringList sequence = QStringList() << "remove" << "modify" << "create"; + const QStringList sequence = QStringList() << "remove" << "modify" << "create"; _error = false; _schemaError = false; _messages.clear(); _autoCorrected = value; - for (const QString& correct : qAsConst(sequence)) + for (const QString& correct : sequence) { _correct = correct; _currentPath.clear(); diff --git a/src/hyperion-aml/CMakeLists.txt b/src/hyperion-aml/CMakeLists.txt index 37bed4af..cdea66fa 100644 --- a/src/hyperion-aml/CMakeLists.txt +++ b/src/hyperion-aml/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1.0) +cmake_minimum_required(VERSION 3.5.0) project(hyperion-aml) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Network Widgets REQUIRED) diff --git a/src/hyperion-dispmanx/CMakeLists.txt b/src/hyperion-dispmanx/CMakeLists.txt index 17720483..07862bbd 100644 --- a/src/hyperion-dispmanx/CMakeLists.txt +++ b/src/hyperion-dispmanx/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1.0) +cmake_minimum_required(VERSION 3.5.0) project(hyperion-dispmanx) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Network Widgets REQUIRED) diff --git a/src/hyperion-framebuffer/CMakeLists.txt b/src/hyperion-framebuffer/CMakeLists.txt index 5667203a..14ea2ce9 100644 --- a/src/hyperion-framebuffer/CMakeLists.txt +++ b/src/hyperion-framebuffer/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1.0) +cmake_minimum_required(VERSION 3.5.0) project(hyperion-framebuffer) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Network Widgets REQUIRED) diff --git a/src/hyperion-osx/CMakeLists.txt b/src/hyperion-osx/CMakeLists.txt index 12f17a9b..efb15cd1 100644 --- a/src/hyperion-osx/CMakeLists.txt +++ b/src/hyperion-osx/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1.0) +cmake_minimum_required(VERSION 3.5.0) project(hyperion-osx) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Gui Network Widgets REQUIRED) diff --git a/src/hyperion-qt/CMakeLists.txt b/src/hyperion-qt/CMakeLists.txt index 6cc4b386..f35b8534 100644 --- a/src/hyperion-qt/CMakeLists.txt +++ b/src/hyperion-qt/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1.0) +cmake_minimum_required(VERSION 3.5.0) project(hyperion-qt) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Gui Network Widgets REQUIRED) diff --git a/src/hyperion-remote/CMakeLists.txt b/src/hyperion-remote/CMakeLists.txt index a7ce5cfe..a2805cad 100644 --- a/src/hyperion-remote/CMakeLists.txt +++ b/src/hyperion-remote/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1.0) +cmake_minimum_required(VERSION 3.5.0) project(hyperion-remote) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Network Widgets REQUIRED) diff --git a/src/hyperion-remote/hyperion-remote.cpp b/src/hyperion-remote/hyperion-remote.cpp index f47fbb14..e7fdc453 100644 --- a/src/hyperion-remote/hyperion-remote.cpp +++ b/src/hyperion-remote/hyperion-remote.cpp @@ -57,9 +57,9 @@ void showHelp(Option & option){ int getInstaneIdbyName(const QJsonObject & reply, const QString & name){ if(reply.contains("instance")){ - QJsonArray list = reply.value("instance").toArray(); + const QJsonArray list = reply.value("instance").toArray(); - for ( const auto &entry : qAsConst(list) ) { + for ( const auto &entry : list ) { const QJsonObject obj = entry.toObject(); if(obj["friendly_name"] == name && obj["running"].toBool()) { diff --git a/src/hyperion-v4l2/CMakeLists.txt b/src/hyperion-v4l2/CMakeLists.txt index 9c8783dd..1404d2ad 100644 --- a/src/hyperion-v4l2/CMakeLists.txt +++ b/src/hyperion-v4l2/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1.0) +cmake_minimum_required(VERSION 3.5.0) project(hyperion-v4l2) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Network Widgets REQUIRED) diff --git a/src/hyperion-x11/CMakeLists.txt b/src/hyperion-x11/CMakeLists.txt index a7459ce6..88095ae3 100644 --- a/src/hyperion-x11/CMakeLists.txt +++ b/src/hyperion-x11/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1.0) +cmake_minimum_required(VERSION 3.5.0) project(hyperion-x11) find_package(X11 REQUIRED) diff --git a/src/hyperion-xcb/CMakeLists.txt b/src/hyperion-xcb/CMakeLists.txt index cd374d5a..f378aef2 100644 --- a/src/hyperion-xcb/CMakeLists.txt +++ b/src/hyperion-xcb/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1.0) +cmake_minimum_required(VERSION 3.5.0) project(hyperion-xcb) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Network Widgets REQUIRED) diff --git a/src/hyperiond/console.h b/src/hyperiond/console.h index 98469960..e61156ae 100644 --- a/src/hyperiond/console.h +++ b/src/hyperiond/console.h @@ -15,4 +15,5 @@ void CreateConsole() freopen_s(&fDummy, "CONOUT$", "w", stderr); freopen_s(&fDummy, "CONIN$", "r", stdin); SetConsoleTitle(TEXT("Hyperion")); + SetConsoleOutputCP(CP_UTF8); } diff --git a/src/hyperiond/main.cpp b/src/hyperiond/main.cpp index 4719cd22..fa9352b9 100644 --- a/src/hyperiond/main.cpp +++ b/src/hyperiond/main.cpp @@ -268,9 +268,9 @@ int main(int argc, char** argv) if (directory.exists() && destDir.exists()) { std::cout << "Extract to folder: " << destDir.absolutePath().toStdString() << std::endl; - QStringList filenames = directory.entryList(QStringList() << "*", QDir::Files, QDir::Name | QDir::IgnoreCase); + const QStringList filenames = directory.entryList(QStringList() << "*", QDir::Files, QDir::Name | QDir::IgnoreCase); QString destFileName; - for (const QString & filename : qAsConst(filenames)) + for (const QString & filename : filenames) { destFileName = destDir.dirName()+"/"+filename; if (QFile::exists(destFileName))