Skip to content

Commit

Permalink
Initial Qt 6 port. Many bug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
chirs241097 committed Nov 27, 2023
1 parent 60989e5 commit f7def0d
Show file tree
Hide file tree
Showing 15 changed files with 125 additions and 126 deletions.
32 changes: 23 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,36 @@ project(QMidiPlayer VERSION 0.8.7 LANGUAGES C CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

include(FindPkgConfig)
find_package(Qt5 REQUIRED COMPONENTS Widgets LinguistTools)
find_package(Threads REQUIRED)
pkg_search_module(fluidsynth REQUIRED fluidsynth>=2.0.0)
pkg_search_module(rtmidi REQUIRED rtmidi)
set(OPTIONAL_QT_DEPS "")

option(BUILD_VISUALIZATION "Build visualization plugin" ON)
if(WIN32)
set(OPTIONAL_QT_DEPS "WinExtras")
option(BUILD_WINEXTRA "Build Windows extra library" ON)
option(BUILD_BACKTRACE "Build backtrace library" OFF)
endif()
if(UNIX)
option(BUILD_PORTABLE "Instruct the built binary not to search system directories" OFF)
option(BUILD_PORTABLE "Instruct the built binary not to search system directories" OFF)
endif()

option(USE_QT6 "Build with Qt 6" OFF)

include(FindPkgConfig)
if (USE_QT6)
find_package(QT NAMES Qt6 REQUIRED)
find_package(Qt6 REQUIRED COMPONENTS Widgets LinguistTools OPTIONAL_COMPONENTS DBus ${OPTIONAL_QT_DEPS})
else()
find_package(QT NAMES Qt5 REQUIRED)
find_package(Qt5 5.15 REQUIRED COMPONENTS Widgets LinguistTools OPTIONAL_COMPONENTS DBus ${OPTIONAL_QT_DEPS})
endif()
find_package(Threads REQUIRED)
find_package(ICU COMPONENTS uc i18n REQUIRED)
pkg_search_module(fluidsynth REQUIRED fluidsynth>=2.0.0)
pkg_search_module(rtmidi REQUIRED rtmidi)

add_definitions(-DAPP_VERSION=\"${PROJECT_VERSION}\")
add_definitions(-DPLUGIN_VERSION=\"${PROJECT_VERSION}\")
Expand All @@ -32,14 +44,16 @@ add_definitions(-DRC_VER_PATCH=${PROJECT_VERSION_PATCH})
add_subdirectory(core)
add_subdirectory(qmidiplayer-desktop)
add_subdirectory(sample-plugin)
add_subdirectory(mpris-plugin)
if (Qt${QT_VERSION_MAJOR}DBus_FOUND)
add_subdirectory(mpris-plugin)
endif()
add_subdirectory(midifmt-plugin)
add_subdirectory(simple-visualization)
if(BUILD_VISUALIZATION)
add_subdirectory(visualization)
endif()
if(WIN32)
if(BUILD_WINEXTRA)
if(BUILD_WINEXTRA AND Qt${QT_VERSION_MAJOR}WinExtras_FOUND)
add_subdirectory(windows-extra)
endif()
if(BUILD_BACKTRACE)
Expand Down
8 changes: 3 additions & 5 deletions mpris-plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,16 @@ set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

find_package(Qt5 REQUIRED COMPONENTS DBus)

include_directories(${PROJECT_SOURCE_DIR}/include/)

add_library(qmpmpris MODULE
${qmpmpris_SOURCES}
)

target_link_libraries(qmpmpris
Qt5::Core
Qt5::Widgets
Qt5::DBus
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::DBus
)

install(TARGETS qmpmpris LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/qmidiplayer/)
1 change: 0 additions & 1 deletion mpris-plugin/qmpmprisimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ QVariantMap QMPPlayer::getMetadata()
qlonglong QMPPlayer::getPosition()
{
::PlaybackStatus ps = api->getPlaybackStatus();
fprintf(stderr, "%lu\n", ps.curtime_ms);
return ps.curtime_ms * 1000;
}

Expand Down
7 changes: 5 additions & 2 deletions qmidiplayer-desktop/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/)

Expand All @@ -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}
Expand All @@ -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)
Expand Down
14 changes: 3 additions & 11 deletions qmidiplayer-desktop/qmpchannelswindow.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <cstdio>
#include <functional>
#include <set>
#include <QCheckBox>
#include <QPushButton>
Expand All @@ -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));
}
Expand Down
56 changes: 8 additions & 48 deletions qmidiplayer-desktop/qmpefxwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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();
Expand Down
10 changes: 1 addition & 9 deletions qmidiplayer-desktop/qmpefxwindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 2 additions & 11 deletions qmidiplayer-desktop/qmpinfowindow.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <QTextCodec>
#include "qmpinfowindow.hpp"
#include "ui_qmpinfowindow.h"
#include "qmpmainwindow.hpp"
Expand Down Expand Up @@ -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));
Expand Down
65 changes: 52 additions & 13 deletions qmidiplayer-desktop/qmpmainwindow.cpp
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions qmidiplayer-desktop/qmpmainwindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ public slots:
{
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
Expand Down
2 changes: 2 additions & 0 deletions qmidiplayer-desktop/qmpsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
Loading

0 comments on commit f7def0d

Please sign in to comment.