Compare commits
4 Commits
0.1.0
...
01812e6bf9
Author | SHA1 | Date | |
---|---|---|---|
01812e6bf9 | |||
044bb34390 | |||
7192c8a1b7 | |||
c9fc9346b7 |
7
.editorconfig
Normal file
7
.editorconfig
Normal file
@ -0,0 +1,7 @@
|
||||
[*]
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 4
|
36
.github/workflows/windows.yml
vendored
36
.github/workflows/windows.yml
vendored
@ -7,9 +7,11 @@ jobs:
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
vs: ['2022']
|
||||
msvc_arch: ['x64']
|
||||
qt_ver: ['6.7.3']
|
||||
include:
|
||||
- qt_ver: '6.8.0'
|
||||
vs: '2022'
|
||||
aqt_arch: 'win64_msvc2022_64'
|
||||
msvc_arch: 'x64'
|
||||
|
||||
runs-on: windows-2022
|
||||
|
||||
@ -18,9 +20,9 @@ jobs:
|
||||
- name: Install Qt
|
||||
uses: jurplel/install-qt-action@v4
|
||||
with:
|
||||
arch: 'win64_msvc2019_64'
|
||||
arch: ${{ matrix.aqt_arch }}
|
||||
version: ${{ matrix.qt_ver }}
|
||||
modules: 'qtmultimedia'
|
||||
modules: 'qtmultimedia qt5compat'
|
||||
- name: Build
|
||||
shell: cmd
|
||||
run: |
|
||||
@ -33,12 +35,16 @@ jobs:
|
||||
:: ------ dep ------
|
||||
set CMAKE_PREFIX_PATH=%PWD%/dependencies_bin
|
||||
mkdir dependencies_src
|
||||
:: ===== uchardet =====
|
||||
echo ::group::build uchardet
|
||||
git clone -q https://gitlab.freedesktop.org/BLumia/uchardet.git --branch msvc dependencies_src/uchardet
|
||||
cmake .\dependencies_src\uchardet -Bbuild_dependencies/uchardet -DBUILD_BINARY=OFF -DCMAKE_INSTALL_PREFIX="dependencies_bin" || goto :error
|
||||
cmake --build build_dependencies/uchardet --config Release --target=install -j || goto :error
|
||||
echo ::endgroup::
|
||||
:: ===== ECM =====
|
||||
git clone -q https://invent.kde.org/frameworks/extra-cmake-modules.git dependencies_src/extra-cmake-modules
|
||||
cmake .\dependencies_src\extra-cmake-modules -Bbuild_dependencies/extra-cmake-modules -DCMAKE_INSTALL_PREFIX="dependencies_bin" -DBUILD_TESTING=OFF || goto :error
|
||||
cmake --build build_dependencies/extra-cmake-modules --config Release --target=install || goto :error
|
||||
:: ===== Gperf (required by KCodecs) =====
|
||||
choco install gperf
|
||||
:: ===== KCodecs =====
|
||||
git clone -q https://invent.kde.org/frameworks/kcodecs.git dependencies_src/kcodecs
|
||||
cmake .\dependencies_src\kcodecs -Bbuild_dependencies/kcodecs -DCMAKE_INSTALL_PREFIX="dependencies_bin" -DBUILD_TESTING=OFF || goto :error
|
||||
cmake --build build_dependencies/kcodecs --config Release --target=install || goto :error
|
||||
:: ===== pkg-config =====
|
||||
choco install pkgconfiglite
|
||||
set PKG_CONFIG_PATH=%PWD%/dependencies_bin/lib/pkgconfig
|
||||
@ -47,16 +53,16 @@ jobs:
|
||||
cmake .\dependencies_src\taglib -Bbuild_dependencies/taglib -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX="dependencies_bin" || goto :error
|
||||
cmake --build build_dependencies/taglib --config Release --target=install -j || goto :error
|
||||
:: ------ app ------
|
||||
cmake -Bbuild . -DCMAKE_INSTALL_PREFIX="%PWD%\build\" || goto :error
|
||||
cmake -Bbuild . -DUSE_QTEXTCODEC=ON -DCMAKE_INSTALL_PREFIX="%PWD%\build\" || goto :error
|
||||
cmake --build build --config Release -j || goto :error
|
||||
cmake --build build --config Release --target=install
|
||||
cmake --build build --config Release --target=install || goto :error
|
||||
:: ------ pkg ------
|
||||
windeployqt --verbose=2 --no-quick-import --no-translations --no-opengl-sw --no-system-d3d-compiler --no-system-dxc-compiler --multimedia --skip-plugin-types tls,networkinformation build\bin\pmusic.exe
|
||||
windeployqt --verbose=2 --no-quick-import --no-translations --no-opengl-sw --no-system-d3d-compiler --no-system-dxc-compiler --multimedia --core5compat --skip-plugin-types tls,networkinformation build\bin\pmusic.exe
|
||||
robocopy ./dependencies_bin/bin build/bin *.dll
|
||||
if ErrorLevel 8 (exit /B 1)
|
||||
copy LICENSE build/bin/
|
||||
exit /B 0
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: "windows-msvc${{ matrix.vs }}-qt${{ matrix.qt_ver }}-cmake-package"
|
||||
name: "${{ matrix.aqt_arch }}-qt${{ matrix.qt_ver }}-cmake-package"
|
||||
path: build/bin/*
|
||||
|
@ -14,10 +14,22 @@ set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
option(USE_QTEXTCODEC "Use QTextCodec instead of QStringConverter, in case Qt is not built with ICU" OFF)
|
||||
|
||||
find_package(Qt6 6.6 COMPONENTS Widgets Multimedia Network LinguistTools REQUIRED)
|
||||
find_package(uchardet)
|
||||
find_package(KF6Codecs 6.1.0)
|
||||
find_package(PkgConfig)
|
||||
|
||||
option(KISSFFT_PKGCONFIG OFF)
|
||||
option(KISSFFT_STATIC ON)
|
||||
option(KISSFFT_TEST OFF)
|
||||
option(KISSFFT_TOOLS OFF)
|
||||
add_subdirectory(kissfft EXCLUDE_FROM_ALL)
|
||||
|
||||
if (USE_QTEXTCODEC)
|
||||
find_package(Qt6 6.6 COMPONENTS Core5Compat REQUIRED)
|
||||
endif()
|
||||
|
||||
if (PKG_CONFIG_FOUND)
|
||||
pkg_check_modules(TagLib taglib IMPORTED_TARGET)
|
||||
endif ()
|
||||
@ -30,6 +42,7 @@ set (PMUSIC_CPP_FILES
|
||||
singleapplicationmanager.cpp
|
||||
lrcbar.cpp
|
||||
lyricsmanager.cpp
|
||||
fftspectrum.cpp
|
||||
)
|
||||
|
||||
set (PMUSIC_HEADER_FILES
|
||||
@ -39,6 +52,7 @@ set (PMUSIC_HEADER_FILES
|
||||
singleapplicationmanager.h
|
||||
lrcbar.h
|
||||
lyricsmanager.h
|
||||
fftspectrum.h
|
||||
)
|
||||
|
||||
set (PMUSIC_UI_FILES
|
||||
@ -73,13 +87,17 @@ else ()
|
||||
target_link_libraries(${EXE_NAME} PRIVATE PkgConfig::TagLib)
|
||||
endif ()
|
||||
|
||||
if (NOT uchardet_FOUND)
|
||||
target_compile_definitions(${EXE_NAME} PRIVATE NO_UCHARDET=1)
|
||||
else ()
|
||||
target_link_libraries (${EXE_NAME} PRIVATE uchardet::libuchardet)
|
||||
if (TARGET KF6::Codecs)
|
||||
target_compile_definitions(${EXE_NAME} PRIVATE HAVE_KCODECS=1)
|
||||
target_link_libraries (${EXE_NAME} PRIVATE KF6::Codecs)
|
||||
endif ()
|
||||
|
||||
target_link_libraries(${EXE_NAME} PRIVATE Qt::Widgets Qt::Multimedia Qt::Network)
|
||||
target_link_libraries(${EXE_NAME} PRIVATE Qt::Widgets Qt::Multimedia Qt::Network kissfft::kissfft)
|
||||
|
||||
if (USE_QTEXTCODEC)
|
||||
target_compile_definitions(${EXE_NAME} PRIVATE USE_QTEXTCODEC=1)
|
||||
target_link_libraries(${EXE_NAME} PRIVATE Qt6::Core5Compat)
|
||||
endif()
|
||||
|
||||
# Install settings
|
||||
if (WIN32)
|
||||
|
16
appveyor.yml
16
appveyor.yml
@ -22,12 +22,20 @@ build_script:
|
||||
# prepare
|
||||
- mkdir 3rdparty
|
||||
- choco install ninja
|
||||
- choco install gperf
|
||||
- choco install pkgconfiglite
|
||||
- cd 3rdparty
|
||||
# build uchardet
|
||||
- git clone -q https://gitlab.freedesktop.org/uchardet/uchardet.git
|
||||
- cd uchardet
|
||||
- cmake -G "Ninja" . -DCMAKE_INSTALL_PREFIX=%PACKAGE_INSTALL_ROOT% -DBUILD_BINARY=OFF
|
||||
# install ECM
|
||||
- git clone -q https://invent.kde.org/frameworks/extra-cmake-modules.git
|
||||
- git rev-parse HEAD
|
||||
- cd extra-cmake-modules
|
||||
- cmake -G "Ninja" . -DCMAKE_INSTALL_PREFIX=%PACKAGE_INSTALL_ROOT% -DBUILD_TESTING=OFF
|
||||
- cmake --build . --target install
|
||||
- cd %APPVEYOR_BUILD_FOLDER%
|
||||
# build kcodecs
|
||||
- git clone -q https://invent.kde.org/frameworks/kcodecs.git
|
||||
- cd kcodecs
|
||||
- cmake -G "Ninja" . -DCMAKE_INSTALL_PREFIX=%PACKAGE_INSTALL_ROOT% -DBUILD_TESTING=OFF
|
||||
- cmake --build . --target install
|
||||
- cd %APPVEYOR_BUILD_FOLDER%
|
||||
# build taglib
|
||||
|
89
fftspectrum.cpp
Normal file
89
fftspectrum.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
// SPDX-FileCopyrightText: 2024 Gary Wang <git@blumia.net>
|
||||
//
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "fftspectrum.h"
|
||||
|
||||
#include <QAudioBuffer>
|
||||
#include <QAudioBufferOutput>
|
||||
#include <QPainter>
|
||||
|
||||
#include <kissfft.hh>
|
||||
|
||||
FFTSpectrum::FFTSpectrum(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, m_audioBufferOutput(new QAudioBufferOutput(this))
|
||||
{
|
||||
connect(this, &FFTSpectrum::mediaPlayerChanged, this, [=]() {
|
||||
if (m_mediaPlayer) {
|
||||
m_mediaPlayer->setAudioBufferOutput(m_audioBufferOutput);
|
||||
}
|
||||
});
|
||||
|
||||
connect(m_audioBufferOutput, &QAudioBufferOutput::audioBufferReceived, this, [=](const QAudioBuffer& buffer) {
|
||||
const QAudioFormat&& fmt = buffer.format();
|
||||
const QAudioFormat::SampleFormat sampleFormat = fmt.sampleFormat();
|
||||
int channelCount = fmt.channelCount();
|
||||
const int frameCount = buffer.frameCount();
|
||||
kissfft<float> fft(frameCount, false);
|
||||
std::vector<kissfft<float>::cpx_t> samples(frameCount);
|
||||
std::vector<kissfft<float>::cpx_t> mass(frameCount);
|
||||
if (sampleFormat == QAudioFormat::Int16 && channelCount == 1) {
|
||||
const QAudioBuffer::S16M* data = buffer.constData<QAudioBuffer::S16M>();
|
||||
for (int i = 0; i < frameCount; ++i) {
|
||||
samples[i].real(data[i].value(QAudioFormat::FrontCenter) / float(32768));
|
||||
samples[i].imag(0);
|
||||
}
|
||||
} else if (sampleFormat == QAudioFormat::Float && channelCount == 2) {
|
||||
const QAudioBuffer::F32S* data = buffer.constData<QAudioBuffer::F32S>();
|
||||
for (int i = 0; i < frameCount; ++i) {
|
||||
samples[i].real(data[i].value(QAudioFormat::FrontLeft));
|
||||
samples[i].imag(0);
|
||||
}
|
||||
}
|
||||
fft.transform(samples.data(), mass.data());
|
||||
m_freq.resize(frameCount);
|
||||
for (int i = 0; i < frameCount; i++) {
|
||||
m_freq[i] = sqrt(mass[i].real() * mass[i].real() + mass[i].imag() * mass[i].imag());
|
||||
}
|
||||
for (auto& val : m_freq) {
|
||||
val = log10(val + 1);
|
||||
}
|
||||
qDebug() << m_freq.size() << "updated";
|
||||
update();
|
||||
qDebug() << sampleFormat << channelCount;
|
||||
});
|
||||
|
||||
resize(490, 420);
|
||||
}
|
||||
|
||||
FFTSpectrum::~FFTSpectrum()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void FFTSpectrum::setMediaPlayer(QMediaPlayer* player)
|
||||
{
|
||||
m_mediaPlayer = player;
|
||||
emit mediaPlayerChanged();
|
||||
}
|
||||
|
||||
void FFTSpectrum::paintEvent(QPaintEvent* e)
|
||||
{
|
||||
QPainter painter(this);
|
||||
painter.fillRect(rect(), Qt::black);
|
||||
|
||||
if (!m_freq.empty()) {
|
||||
int width = this->width();
|
||||
int height = this->height();
|
||||
int barWidth = std::max(1ULL, width / m_freq.size());
|
||||
qDebug() << m_freq.size() << barWidth << m_freq << "freq";
|
||||
|
||||
for (int i = 0; i < m_freq.size(); i++) {
|
||||
int barHeight = static_cast<int>(m_freq[i] * height);
|
||||
painter.fillRect(i * barWidth, height - barHeight, barWidth, barHeight, Qt::green);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
31
fftspectrum.h
Normal file
31
fftspectrum.h
Normal file
@ -0,0 +1,31 @@
|
||||
// SPDX-FileCopyrightText: 2024 Gary Wang <git@blumia.net>
|
||||
//
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include <QMediaPlayer>
|
||||
|
||||
class QAudioBufferOutput;
|
||||
class FFTSpectrum : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QMediaPlayer * mediaPlayer MEMBER m_mediaPlayer WRITE setMediaPlayer NOTIFY mediaPlayerChanged)
|
||||
public:
|
||||
explicit FFTSpectrum(QWidget* parent);
|
||||
~FFTSpectrum();
|
||||
|
||||
void setMediaPlayer(QMediaPlayer* player);
|
||||
|
||||
signals:
|
||||
void mediaPlayerChanged();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* e) override;
|
||||
|
||||
private:
|
||||
QMediaPlayer* m_mediaPlayer = nullptr;
|
||||
QAudioBufferOutput* m_audioBufferOutput = nullptr;
|
||||
std::vector<float> m_freq;
|
||||
};
|
@ -9,8 +9,14 @@
|
||||
#include <QRegularExpression>
|
||||
#include <QStringConverter>
|
||||
|
||||
#ifndef NO_UCHARDET
|
||||
#include <uchardet/uchardet.h>
|
||||
#ifdef HAVE_KCODECS
|
||||
#include <KCharsets>
|
||||
#include <KCodecs>
|
||||
#include <KEncodingProber>
|
||||
#endif
|
||||
|
||||
#ifdef USE_QTEXTCODEC
|
||||
#include <QTextCodec>
|
||||
#endif
|
||||
|
||||
Q_LOGGING_CATEGORY(lcLyrics, "pmusic.lyrics")
|
||||
@ -44,24 +50,38 @@ bool LyricsManager::loadLyrics(QString filepath)
|
||||
return false;
|
||||
}
|
||||
QByteArray fileContent(file.readAll());
|
||||
#ifndef NO_UCHARDET
|
||||
uchardet_t handle = uchardet_new();
|
||||
uchardet_handle_data(handle, fileContent.data(), fileContent.length());
|
||||
uchardet_data_end(handle);
|
||||
const char* encoding = uchardet_get_charset(handle);
|
||||
qCDebug(lcLyrics) << "Detected encoding:" << (encoding == NULL ? "unknown" : encoding);
|
||||
QStringList lines;
|
||||
if (QStringConverter::availableCodecs().contains(QString(encoding))) {
|
||||
auto toUtf16 = QStringDecoder(encoding);
|
||||
#ifdef HAVE_KCODECS
|
||||
KEncodingProber prober(KEncodingProber::Universal);
|
||||
prober.feed(fileContent);
|
||||
QByteArray encoding(prober.encoding());
|
||||
qCDebug(lcLyrics) << "Detected encoding:" << QString(encoding) << "with confidence" << prober.confidence();
|
||||
#ifdef USE_QTEXTCODEC
|
||||
qCDebug(lcLyrics) << "QTextCodec is used instead of QStringConverter.";
|
||||
QTextCodec *codec = QTextCodec::codecForName(encoding);
|
||||
if (codec) {
|
||||
lines = codec->toUnicode(fileContent).split('\n');
|
||||
} else {
|
||||
lines = QString(fileContent).split('\n');
|
||||
qCDebug(lcLyrics) << "No codec for the detected encoding. Available codecs are:" << QTextCodec::availableCodecs();
|
||||
qCDebug(lcLyrics) << "KCodecs offers these encodings:" << KCharsets::charsets()->availableEncodingNames();
|
||||
}
|
||||
#else // NOT USE_QTEXTCODEC
|
||||
auto toUtf16 = QStringDecoder(encoding);
|
||||
// Don't use `QStringConverter::availableCodecs().contains(QString(encoding))` here, since the charset
|
||||
// encoding name might not match, e.g. GB18030 (from availableCodecs) != gb18030 (from KEncodingProber)
|
||||
if (toUtf16.isValid()) {
|
||||
QString decodedResult = toUtf16(fileContent);
|
||||
lines = decodedResult.split('\n');
|
||||
} else {
|
||||
qCDebug(lcLyrics) << "No codec for the detected encoding. Available codecs are:" << QStringConverter::availableCodecs();
|
||||
qCDebug(lcLyrics) << "KCodecs offers these encodings:" << KCharsets::charsets()->availableEncodingNames();
|
||||
lines = QString(fileContent).split('\n');
|
||||
}
|
||||
uchardet_delete(handle);
|
||||
#else
|
||||
QStringList lines = QString(fileContent).split('\n');
|
||||
#endif
|
||||
#endif // USE_QTEXTCODEC
|
||||
#else // NOT HAVE_KCODECS
|
||||
lines = QString(fileContent).split('\n');
|
||||
#endif // HAVE_KCODECS
|
||||
file.close();
|
||||
|
||||
// parse lyrics timestamp
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "./ui_mainwindow.h"
|
||||
|
||||
#include "playlistmanager.h"
|
||||
#include "fftspectrum.h"
|
||||
#include "lrcbar.h"
|
||||
|
||||
// taglib
|
||||
@ -17,6 +18,7 @@
|
||||
#include <QMediaPlayer>
|
||||
#include <QMediaMetaData>
|
||||
#include <QAudioOutput>
|
||||
#include <QAudioBuffer>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QFileDialog>
|
||||
#include <QTime>
|
||||
@ -41,13 +43,15 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
, m_mediaDevices(new QMediaDevices(this))
|
||||
, m_mediaPlayer(new QMediaPlayer(this))
|
||||
, m_audioOutput(new QAudioOutput(this))
|
||||
, m_fftSpectrum(new FFTSpectrum(this))
|
||||
, m_lrcbar(new LrcBar(nullptr))
|
||||
, m_playlistManager(new PlaylistManager(this))
|
||||
{
|
||||
ui->setupUi(this);
|
||||
m_playlistManager->setAutoLoadFilterSuffixes({
|
||||
"*.mp3", "*.wav", "*.aiff", "*.ape", "*.flac", "*.ogg", "*.oga", "*.mpga", "*.aac"
|
||||
"*.mp3", "*.wav", "*.aiff", "*.ape", "*.flac", "*.ogg", "*.oga", "*.mpga", "*.aac", "*.tta"
|
||||
});
|
||||
m_fftSpectrum->setMediaPlayer(m_mediaPlayer);
|
||||
m_mediaPlayer->setAudioOutput(m_audioOutput);
|
||||
m_mediaPlayer->setLoops(QMediaPlayer::Infinite);
|
||||
ui->playlistView->setModel(m_playlistManager->model());
|
||||
@ -438,6 +442,7 @@ void MainWindow::initConnections()
|
||||
setAudioMetadataForDisplay(metadata.stringValue(QMediaMetaData::Title),
|
||||
metadata.stringValue(QMediaMetaData::Author),
|
||||
metadata.stringValue(QMediaMetaData::AlbumTitle));
|
||||
setAudioPropertyInfoForDisplay(-1, metadata.value(QMediaMetaData::AudioBitRate).toInt() / 1000, -1, metadata.stringValue(QMediaMetaData::FileFormat));
|
||||
#endif // NO_TAGLIB
|
||||
QVariant coverArt(metadata.value(QMediaMetaData::ThumbnailImage));
|
||||
if (!coverArt.isNull()) {
|
||||
@ -616,12 +621,16 @@ void MainWindow::on_actionHelp_triggered()
|
||||
"\n\n" %
|
||||
tr("Based on the following free software libraries:") %
|
||||
"\n\n" %
|
||||
QStringLiteral("- [Qt](https://www.qt.io/) %1\n").arg(QT_VERSION_STR) %
|
||||
QStringLiteral("- [Qt](https://www.qt.io/) %1 with the following module(s):\n").arg(QT_VERSION_STR) %
|
||||
QStringLiteral(" - multimedia\n") %
|
||||
#ifdef USE_QTEXTCODEC
|
||||
QStringLiteral(" - core5compat\n") %
|
||||
#endif
|
||||
#ifndef NO_TAGLIB
|
||||
QStringLiteral("- [TagLib](https://github.com/taglib/taglib)\n") %
|
||||
#endif // NO_TAGLIB
|
||||
#ifndef NO_UCHARDET
|
||||
QStringLiteral("- [uchardet](https://www.freedesktop.org/wiki/Software/uchardet/)\n") %
|
||||
#ifdef HAVE_KCODECS
|
||||
QStringLiteral("- [KCodecs](https://invent.kde.org/frameworks/kcodecs)\n") %
|
||||
#endif // NO_TAGLIB
|
||||
"\n"
|
||||
"[Source Code](https://github.com/BLumia/pineapple-music)\n"
|
||||
|
@ -17,6 +17,7 @@ class QAudioOutput;
|
||||
class QPropertyAnimation;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class FFTSpectrum;
|
||||
class LrcBar;
|
||||
class PlaylistManager;
|
||||
class MainWindow : public QMainWindow
|
||||
@ -92,6 +93,7 @@ private:
|
||||
QMediaDevices *m_mediaDevices;
|
||||
QMediaPlayer *m_mediaPlayer;
|
||||
QAudioOutput *m_audioOutput;
|
||||
FFTSpectrum* m_fftSpectrum;
|
||||
LrcBar *m_lrcbar;
|
||||
QPropertyAnimation *m_fadeOutAnimation;
|
||||
PlaylistManager *m_playlistManager;
|
||||
|
Reference in New Issue
Block a user