From f7def0d883fa5cab62ef61b40b9f857245be8e6c Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Sun, 26 Nov 2023 21:29:16 -0500 Subject: Initial Qt 6 port. Many bug fixes. --- qmidiplayer-desktop/CMakeLists.txt | 7 +++- qmidiplayer-desktop/qmpchannelswindow.cpp | 14 ++----- qmidiplayer-desktop/qmpefxwindow.cpp | 56 ++++---------------------- qmidiplayer-desktop/qmpefxwindow.hpp | 10 +---- qmidiplayer-desktop/qmpinfowindow.cpp | 13 +------ qmidiplayer-desktop/qmpmainwindow.cpp | 65 ++++++++++++++++++++++++------- qmidiplayer-desktop/qmpmainwindow.hpp | 3 ++ qmidiplayer-desktop/qmpsettings.cpp | 2 + 8 files changed, 76 insertions(+), 94 deletions(-) (limited to 'qmidiplayer-desktop') diff --git a/qmidiplayer-desktop/CMakeLists.txt b/qmidiplayer-desktop/CMakeLists.txt index d3ee116..5def90f 100644 --- a/qmidiplayer-desktop/CMakeLists.txt +++ b/qmidiplayer-desktop/CMakeLists.txt @@ -57,6 +57,7 @@ set(CMAKE_AUTOUIC ON) include_directories(${fluidsynth_INCLUDE_DIRS}) include_directories(${rtmidi_INCLUDE_DIRS}) +include_directories(${ICU_INCLUDE_DIR}) include_directories(${PROJECT_SOURCE_DIR}/include/) include_directories(${PROJECT_SOURCE_DIR}/core/) @@ -71,8 +72,10 @@ add_executable(qmidiplayer ) target_link_libraries(qmidiplayer - Qt5::Widgets + Qt${QT_VERSION_MAJOR}::Widgets qmpcore + ICU::uc + ICU::i18n ${fluidsynth_LIBRARIES} ${rtmidi_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} @@ -90,7 +93,7 @@ PRIVATE ) file(GLOB qmpdesktop_TS_FILES translations/*.ts) -qt5_create_translation(qmpdesktop_QM_FILES ${qmpdesktop_SOURCES} ${qmpdesktop_TS_FILES}) +qt_create_translation(qmpdesktop_QM_FILES ${qmpdesktop_SOURCES} ${qmpdesktop_TS_FILES}) add_custom_target(translations ALL DEPENDS ${qmpdesktop_QM_FILES}) install(TARGETS qmidiplayer) diff --git a/qmidiplayer-desktop/qmpchannelswindow.cpp b/qmidiplayer-desktop/qmpchannelswindow.cpp index 8957254..7743084 100644 --- a/qmidiplayer-desktop/qmpchannelswindow.cpp +++ b/qmidiplayer-desktop/qmpchannelswindow.cpp @@ -1,5 +1,4 @@ #include -#include #include #include #include @@ -14,23 +13,16 @@ qmpChannelsModel::qmpChannelsModel(QObject *parent): QAbstractTableModel(parent) evh = qmpMainWindow::getInstance()->getPlayer()->registerEventHandler( [this](const void *_e, void *) { + const SEvent *e = (const SEvent *)(_e); + if ((e->type & 0xF0) == 0xC0) + emit dataChanged(index(e->type & 0x0F, 4), index(e->type & 0x0F, 4), {Qt::ItemDataRole::DisplayRole}); if (!updatequeued) { updatequeued = true; - const SEvent *e = (const SEvent *)(_e); - if ((e->p1 & 0xF0) == 0xC0) - emit dataChanged(index(e->p1 & 0xF0, 4), index(e->p1 & 0xF0, 4), {Qt::ItemDataRole::DisplayRole}); QMetaObject::invokeMethod(this, &qmpChannelsModel::updateChannelActivity, Qt::ConnectionType::QueuedConnection); } } , nullptr, false); - QTimer *t = new QTimer(this); - t->setInterval(500); - t->setSingleShot(false); - connect(t, &QTimer::timeout, [this]() - { - emit this->dataChanged(this->index(0, 4), this->index(15, 4), {Qt::ItemDataRole::DisplayRole}); - }); memset(mute, 0, sizeof(mute)); memset(solo, 0, sizeof(solo)); } diff --git a/qmidiplayer-desktop/qmpefxwindow.cpp b/qmidiplayer-desktop/qmpefxwindow.cpp index 0a281cd..2cea976 100644 --- a/qmidiplayer-desktop/qmpefxwindow.cpp +++ b/qmidiplayer-desktop/qmpefxwindow.cpp @@ -35,6 +35,14 @@ qmpEfxWindow::qmpEfxWindow(QWidget *parent) : 0, true ); + connect(ui->sbRoom, qOverload(&QSpinBox::valueChanged), this, &qmpEfxWindow::spinValueChange); + connect(ui->sbDamp, qOverload(&QSpinBox::valueChanged), this, &qmpEfxWindow::spinValueChange); + connect(ui->sbWidth, qOverload(&QSpinBox::valueChanged), this, &qmpEfxWindow::spinValueChange); + connect(ui->sbLevelR, qOverload(&QSpinBox::valueChanged), this, &qmpEfxWindow::spinValueChange); + connect(ui->sbFeedBack, qOverload(&QSpinBox::valueChanged), this, &qmpEfxWindow::spinValueChange); + connect(ui->sbRate, qOverload(&QDoubleSpinBox::valueChanged), this, &qmpEfxWindow::spinValueChange); + connect(ui->sbDepth, qOverload(&QDoubleSpinBox::valueChanged), this, &qmpEfxWindow::spinValueChange); + connect(ui->sbLevelC, qOverload(&QSpinBox::valueChanged), this, &qmpEfxWindow::spinValueChange); if (!settings->getOptionRaw("DialogStatus/EfxW", QRect()).toRect().isNull()) setGeometry(settings->getOptionRaw("DialogStatus/EfxW", QRect()).toRect()); if (settings->getOptionRaw("DialogStatus/EfxWShown", 0).toInt()) @@ -218,54 +226,6 @@ void qmpEfxWindow::on_dLevelC_valueChanged() dailValueChange(); } -void qmpEfxWindow::on_sbRoom_valueChanged(QString s) -{ - s = QString(); - spinValueChange(); -} - -void qmpEfxWindow::on_sbDamp_valueChanged(QString s) -{ - s = QString(); - spinValueChange(); -} - -void qmpEfxWindow::on_sbWidth_valueChanged(QString s) -{ - s = QString(); - spinValueChange(); -} - -void qmpEfxWindow::on_sbLevelR_valueChanged(QString s) -{ - s = QString(); - spinValueChange(); -} - -void qmpEfxWindow::on_sbFeedBack_valueChanged(QString s) -{ - s = QString(); - spinValueChange(); -} - -void qmpEfxWindow::on_sbRate_valueChanged(QString s) -{ - s = QString(); - spinValueChange(); -} - -void qmpEfxWindow::on_sbDepth_valueChanged(QString s) -{ - s = QString(); - spinValueChange(); -} - -void qmpEfxWindow::on_sbLevelC_valueChanged(QString s) -{ - s = QString(); - spinValueChange(); -} - void qmpEfxWindow::on_cbEnabledC_stateChanged() { sendEfxChange(); diff --git a/qmidiplayer-desktop/qmpefxwindow.hpp b/qmidiplayer-desktop/qmpefxwindow.hpp index 9e5e8bf..3b74df3 100644 --- a/qmidiplayer-desktop/qmpefxwindow.hpp +++ b/qmidiplayer-desktop/qmpefxwindow.hpp @@ -46,22 +46,14 @@ private slots: void on_dRate_valueChanged(); void on_dDepth_valueChanged(); void on_dLevelC_valueChanged(); - void on_sbRoom_valueChanged(QString s); - void on_sbDamp_valueChanged(QString s); - void on_sbWidth_valueChanged(QString s); - void on_sbLevelR_valueChanged(QString s); - void on_sbFeedBack_valueChanged(QString s); - void on_sbRate_valueChanged(QString s); - void on_sbDepth_valueChanged(QString s); - void on_sbLevelC_valueChanged(QString s); void on_cbEnabledC_stateChanged(); void on_cbEnabledR_stateChanged(); void on_rbSine_toggled(); void on_rbTriangle_toggled(); + void spinValueChange(); private: void dailValueChange(); - void spinValueChange(); Ui::qmpEfxWindow *ui; double rr, rd, rw, rl; int cfb, ct, initialized; diff --git a/qmidiplayer-desktop/qmpinfowindow.cpp b/qmidiplayer-desktop/qmpinfowindow.cpp index 654c8f4..fe46c18 100644 --- a/qmidiplayer-desktop/qmpinfowindow.cpp +++ b/qmidiplayer-desktop/qmpinfowindow.cpp @@ -1,4 +1,3 @@ -#include #include "qmpinfowindow.hpp" #include "ui_qmpinfowindow.h" #include "qmpmainwindow.hpp" @@ -51,20 +50,12 @@ void qmpInfoWindow::updateInfo() ui->lbFileName->setText(QString("File name: ") + qmpMainWindow::getInstance()->getFileName()); if (player->getTitle()) { - if (textencoding != "Unicode") - ui->lbTitle->setText(QString("Title: ") + - QTextCodec::codecForName(textencoding.c_str())->toUnicode(player->getTitle())); - else - ui->lbTitle->setText(QString("Title: ") + player->getTitle()); + ui->lbTitle->setText(QString("Title: %1").arg(qmpMainWindow::decodeString(player->getTitle()))); } else ui->lbTitle->setText(QString("Title: ")); if (player->getCopyright()) { - if (textencoding != "Unicode") - ui->lbCopyright->setText(QString("Copyright: ") + - QTextCodec::codecForName(textencoding.c_str())->toUnicode(player->getCopyright())); - else - ui->lbCopyright->setText(QString("Copyright: ") + player->getCopyright()); + ui->lbCopyright->setText(QString("Copyright: %1").arg(qmpMainWindow::decodeString(player->getCopyright()))); } else ui->lbCopyright->setText(QString("Copyright: ")); ui->lbTempo->setText(QString("Tempo: ") + QString::number(player->getTempo(), 'g', 5)); diff --git a/qmidiplayer-desktop/qmpmainwindow.cpp b/qmidiplayer-desktop/qmpmainwindow.cpp index c02a206..9b18e0d 100644 --- a/qmidiplayer-desktop/qmpmainwindow.cpp +++ b/qmidiplayer-desktop/qmpmainwindow.cpp @@ -1,11 +1,12 @@ #include #include -#include +#include +#include +#include #include #include #include #include -#include #include #include #include @@ -406,19 +407,11 @@ void qmpMainWindow::switchTrack(QString s, bool interrupt) } std::string qmpMainWindow::getTitle() { - if (settings->getOptionEnumIntOptName("Midi/TextEncoding") == "Unicode") - return std::string(player->getTitle()); - return QTextCodec::codecForName( - settings->getOptionEnumIntOptName("Midi/TextEncoding").c_str())-> - toUnicode(player->getTitle()).toStdString(); + return decodeStdString(player->getTitle()); } std::wstring qmpMainWindow::getWTitle() { - if (settings->getOptionEnumIntOptName("Midi/TextEncoding") == "Unicode") - return QString(player->getTitle()).toStdWString(); - return QTextCodec::codecForName( - settings->getOptionEnumIntOptName("Midi/TextEncoding").c_str())-> - toUnicode(player->getTitle()).toStdWString(); + return decodeStdWString(player->getTitle()); } void qmpMainWindow::playerSetup(IFluidSettings *fs) @@ -505,7 +498,16 @@ void qmpMainWindow::registerMidiOptions() settings->registerOptionBool("MIDI", "Send system exclusive messages", "Midi/SendSysEx", true); settings->registerOptionBool("MIDI", "Wait for remaining voice before stopping", "Midi/WaitVoice", true); settings->registerOptionInt("MIDI", "Fluidsynth Device ID", "FluidSynth/DeviceID", 0x00, 0x7E, 0x10); - settings->registerOptionEnumInt("MIDI", "Text encoding", "Midi/TextEncoding", {"Unicode", "Big5", "Big5-HKSCS", "CP949", "EUC-JP", "EUC-KR", "GB18030", "KOI8-R", "KOI8-U", "Macintosh", "Shift-JIS"}, 0); + UErrorCode e = U_ZERO_ERROR; + auto ucnvc = ucnv_countAvailable(); + std::vector converters; + for (auto i = 0; i < ucnvc; ++i) + { + auto n = ucnv_getAvailableName(i); + auto sn = ucnv_getStandardName(n, "MIME", &e); + if (sn) converters.push_back(std::string(sn)); + } + settings->registerOptionEnumInt("MIDI", "Text encoding", "Midi/TextEncoding", converters, 0); } void qmpMainWindow::registerBehaviorOptions() @@ -517,6 +519,43 @@ void qmpMainWindow::registerBehaviorOptions() settings->registerOptionEnumInt("Behavior", "Icon Theme", "Behavior/IconTheme", {"Auto", "Dark", "Light"}, 0); } +QString qmpMainWindow::decodeString(const char *str) +{ + std::string enc("utf-8"); + if (ref && ref->settings) + enc = ref->settings->getOptionEnumIntOptName("Midi/TextEncoding"); + icu::UnicodeString us(str, enc.c_str()); + std::string r; + return QString::fromUtf8(us.toUTF8String(r).c_str()); +} + +std::string qmpMainWindow::decodeStdString(const char *str) +{ + std::string enc("utf-8"); + if (ref && ref->settings) + enc = ref->settings->getOptionEnumIntOptName("Midi/TextEncoding"); + icu::UnicodeString us(str, enc.c_str()); + std::string r; + us.toUTF8String(r); + return r; +} + +std::wstring qmpMainWindow::decodeStdWString(const char *str) +{ + std::string enc("utf-8"); + if (ref && ref->settings) + enc = ref->settings->getOptionEnumIntOptName("Midi/TextEncoding"); + icu::UnicodeString us(str, enc.c_str()); + std::wstring r; + int32_t sz = 0; + UErrorCode e = U_ZERO_ERROR; + u_strToWCS(nullptr, 0, &sz, us.getBuffer(), us.length(), &e); + r.resize(sz + 1); + e = U_ZERO_ERROR; + u_strToWCS(r.data(), r.size(), nullptr, us.getBuffer(), us.length(), &e); + return r; +} + void qmpMainWindow::on_pbPlayPause_clicked() { if (stopped) diff --git a/qmidiplayer-desktop/qmpmainwindow.hpp b/qmidiplayer-desktop/qmpmainwindow.hpp index 7a34cb6..757ec14 100644 --- a/qmidiplayer-desktop/qmpmainwindow.hpp +++ b/qmidiplayer-desktop/qmpmainwindow.hpp @@ -312,6 +312,9 @@ public: { return ref; } + static QString decodeString(const char* str); + static std::string decodeStdString(const char* str); + static std::wstring decodeStdWString(const char* str); }; class qmpRenderFunc: public qmpFuncBaseIntf diff --git a/qmidiplayer-desktop/qmpsettings.cpp b/qmidiplayer-desktop/qmpsettings.cpp index 6ce542a..70cd720 100644 --- a/qmidiplayer-desktop/qmpsettings.cpp +++ b/qmidiplayer-desktop/qmpsettings.cpp @@ -7,7 +7,9 @@ QSettings *qmpSettings::settings = nullptr; qmpSettings::qmpSettings() { +#if QT_VERSION_MAJOR < 6 qRegisterMetaTypeStreamOperators>(); +#endif QString confpath = QStandardPaths::writableLocation(QStandardPaths::StandardLocation::ConfigLocation) + QString("/qmprc"); settings = new QSettings(confpath, QSettings::IniFormat); if (settings->value("ConfigurationFileRevision").toInt() != QMP_CONFIGURATION_FILE_REV && -- cgit v1.2.3