diff options
Diffstat (limited to 'qmidiplayer-desktop')
-rw-r--r-- | qmidiplayer-desktop/CMakeLists.txt | 7 | ||||
-rw-r--r-- | qmidiplayer-desktop/qmpchannelswindow.cpp | 14 | ||||
-rw-r--r-- | qmidiplayer-desktop/qmpefxwindow.cpp | 56 | ||||
-rw-r--r-- | qmidiplayer-desktop/qmpefxwindow.hpp | 10 | ||||
-rw-r--r-- | qmidiplayer-desktop/qmpinfowindow.cpp | 13 | ||||
-rw-r--r-- | qmidiplayer-desktop/qmpmainwindow.cpp | 65 | ||||
-rw-r--r-- | qmidiplayer-desktop/qmpmainwindow.hpp | 3 | ||||
-rw-r--r-- | qmidiplayer-desktop/qmpsettings.cpp | 2 |
8 files changed, 76 insertions, 94 deletions
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 <cstdio> -#include <functional> #include <set> #include <QCheckBox> #include <QPushButton> @@ -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<int>(&QSpinBox::valueChanged), this, &qmpEfxWindow::spinValueChange); + connect(ui->sbDamp, qOverload<int>(&QSpinBox::valueChanged), this, &qmpEfxWindow::spinValueChange); + connect(ui->sbWidth, qOverload<int>(&QSpinBox::valueChanged), this, &qmpEfxWindow::spinValueChange); + connect(ui->sbLevelR, qOverload<int>(&QSpinBox::valueChanged), this, &qmpEfxWindow::spinValueChange); + connect(ui->sbFeedBack, qOverload<int>(&QSpinBox::valueChanged), this, &qmpEfxWindow::spinValueChange); + connect(ui->sbRate, qOverload<double>(&QDoubleSpinBox::valueChanged), this, &qmpEfxWindow::spinValueChange); + connect(ui->sbDepth, qOverload<double>(&QDoubleSpinBox::valueChanged), this, &qmpEfxWindow::spinValueChange); + connect(ui->sbLevelC, qOverload<int>(&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 <QTextCodec> #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 <cstdio> #include <cmath> -#include <functional> +#include <unicode/ustring.h> +#include <unicode/unistr.h> +#include <unicode/ucnv.h> #include <QUrl> #include <QFileInfo> #include <QMimeData> #include <QFont> -#include <QTextCodec> #include <QDirIterator> #include <QMessageBox> #include <QCheckBox> @@ -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<std::string> 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<QPair<QString, QString>>(); +#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 && |