Compare commits
1 Commits
master
...
01812e6bf9
Author | SHA1 | Date | |
---|---|---|---|
01812e6bf9 |
@ -1,7 +1,7 @@
|
|||||||
[*]
|
[*]
|
||||||
end_of_line = lf
|
end_of_line = lf
|
||||||
charset = utf-8
|
charset = utf-8
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
insert_final_newline = true
|
insert_final_newline = true
|
||||||
indent_style = space
|
indent_style = space
|
||||||
indent_size = 4
|
indent_size = 4
|
19
.github/workflows/windows.yml
vendored
19
.github/workflows/windows.yml
vendored
@ -8,7 +8,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- qt_ver: '6.9.0'
|
- qt_ver: '6.8.0'
|
||||||
vs: '2022'
|
vs: '2022'
|
||||||
aqt_arch: 'win64_msvc2022_64'
|
aqt_arch: 'win64_msvc2022_64'
|
||||||
msvc_arch: 'x64'
|
msvc_arch: 'x64'
|
||||||
@ -35,26 +35,25 @@ jobs:
|
|||||||
:: ------ dep ------
|
:: ------ dep ------
|
||||||
set CMAKE_PREFIX_PATH=%PWD%/dependencies_bin
|
set CMAKE_PREFIX_PATH=%PWD%/dependencies_bin
|
||||||
mkdir dependencies_src
|
mkdir dependencies_src
|
||||||
echo ::group::===== ECM =====
|
:: ===== ECM =====
|
||||||
git clone -q https://invent.kde.org/frameworks/extra-cmake-modules.git dependencies_src/extra-cmake-modules
|
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 .\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
|
cmake --build build_dependencies/extra-cmake-modules --config Release --target=install || goto :error
|
||||||
echo ::endgroup::
|
:: ===== Gperf (required by KCodecs) =====
|
||||||
echo ::group::===== Gperf (required by KCodecs) =====
|
|
||||||
choco install gperf
|
choco install gperf
|
||||||
echo ::endgroup::
|
:: ===== KCodecs =====
|
||||||
echo ::group::===== KCodecs =====
|
|
||||||
git clone -q https://invent.kde.org/frameworks/kcodecs.git dependencies_src/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 .\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
|
cmake --build build_dependencies/kcodecs --config Release --target=install || goto :error
|
||||||
echo ::endgroup::
|
:: ===== pkg-config =====
|
||||||
echo ::group::===== taglib =====
|
choco install pkgconfiglite
|
||||||
|
set PKG_CONFIG_PATH=%PWD%/dependencies_bin/lib/pkgconfig
|
||||||
|
:: ===== taglib =====
|
||||||
git clone --recurse-submodules -q https://github.com/taglib/taglib.git dependencies_src/taglib
|
git clone --recurse-submodules -q https://github.com/taglib/taglib.git dependencies_src/taglib
|
||||||
cmake .\dependencies_src\taglib -Bbuild_dependencies/taglib -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX="dependencies_bin" || goto :error
|
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
|
cmake --build build_dependencies/taglib --config Release --target=install -j || goto :error
|
||||||
echo ::endgroup::
|
|
||||||
:: ------ app ------
|
:: ------ app ------
|
||||||
cmake -Bbuild . -DUSE_QTEXTCODEC=ON -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 -j || goto :error
|
||||||
cmake --build build --config Release --target=install || goto :error
|
cmake --build build --config Release --target=install || goto :error
|
||||||
:: ------ pkg ------
|
:: ------ pkg ------
|
||||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -6,6 +6,3 @@
|
|||||||
|
|
||||||
# User config file
|
# User config file
|
||||||
CMakeLists.txt.user*
|
CMakeLists.txt.user*
|
||||||
|
|
||||||
# Why, macOS, why?
|
|
||||||
.DS_Store
|
|
||||||
|
294
CMakeLists.txt
294
CMakeLists.txt
@ -1,162 +1,136 @@
|
|||||||
cmake_minimum_required(VERSION 3.12)
|
cmake_minimum_required(VERSION 3.12)
|
||||||
|
|
||||||
project(pineapple-music LANGUAGES CXX VERSION 0.3.0)
|
project(pineapple-music LANGUAGES CXX)
|
||||||
|
|
||||||
include (GNUInstallDirs)
|
include (GNUInstallDirs)
|
||||||
include (FeatureSummary)
|
include (FeatureSummary)
|
||||||
include (FetchContent)
|
|
||||||
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
|
||||||
|
set(CMAKE_AUTOUIC ON)
|
||||||
set(CMAKE_AUTOUIC ON)
|
set(CMAKE_AUTOMOC ON)
|
||||||
set(CMAKE_AUTOMOC ON)
|
set(CMAKE_AUTORCC ON)
|
||||||
set(CMAKE_AUTORCC ON)
|
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
||||||
|
option(USE_QTEXTCODEC "Use QTextCodec instead of QStringConverter, in case Qt is not built with ICU" OFF)
|
||||||
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(Qt6 6.6 COMPONENTS Widgets Multimedia Network LinguistTools REQUIRED)
|
find_package(KF6Codecs 6.1.0)
|
||||||
find_package(FFmpeg COMPONENTS avutil avformat)
|
find_package(PkgConfig)
|
||||||
find_package(TagLib 2.0.0)
|
|
||||||
find_package(KF6Codecs 6.1.0)
|
option(KISSFFT_PKGCONFIG OFF)
|
||||||
|
option(KISSFFT_STATIC ON)
|
||||||
FetchContent_Declare(
|
option(KISSFFT_TEST OFF)
|
||||||
kissfft
|
option(KISSFFT_TOOLS OFF)
|
||||||
GIT_REPOSITORY https://github.com/mborgerding/kissfft.git
|
add_subdirectory(kissfft EXCLUDE_FROM_ALL)
|
||||||
GIT_TAG f5f2a3b2f2cd02bf80639adb12cbeed125bdf420
|
|
||||||
)
|
if (USE_QTEXTCODEC)
|
||||||
set(KISSFFT_PKGCONFIG OFF CACHE BOOL "dep(kissfft): pkgconfig support")
|
find_package(Qt6 6.6 COMPONENTS Core5Compat REQUIRED)
|
||||||
set(KISSFFT_STATIC ON CACHE BOOL "dep(kissfft): static linking")
|
endif()
|
||||||
set(KISSFFT_TEST OFF CACHE BOOL "dep(kissfft): enable testing")
|
|
||||||
set(KISSFFT_TOOLS OFF CACHE BOOL "dep(kissfft): build tools")
|
if (PKG_CONFIG_FOUND)
|
||||||
FetchContent_MakeAvailable(kissfft)
|
pkg_check_modules(TagLib taglib IMPORTED_TARGET)
|
||||||
|
endif ()
|
||||||
if (USE_QTEXTCODEC)
|
|
||||||
find_package(Qt6 6.6 COMPONENTS Core5Compat REQUIRED)
|
set (PMUSIC_CPP_FILES
|
||||||
endif()
|
main.cpp
|
||||||
|
mainwindow.cpp
|
||||||
set (PMUSIC_CPP_FILES
|
seekableslider.cpp
|
||||||
main.cpp
|
playlistmanager.cpp
|
||||||
mainwindow.cpp
|
singleapplicationmanager.cpp
|
||||||
seekableslider.cpp
|
lrcbar.cpp
|
||||||
playlistmanager.cpp
|
|
||||||
singleapplicationmanager.cpp
|
|
||||||
lrcbar.cpp
|
|
||||||
lyricsmanager.cpp
|
lyricsmanager.cpp
|
||||||
fftspectrum.cpp
|
fftspectrum.cpp
|
||||||
playbackprogressindicator.cpp
|
)
|
||||||
)
|
|
||||||
|
set (PMUSIC_HEADER_FILES
|
||||||
set (PMUSIC_HEADER_FILES
|
mainwindow.h
|
||||||
mainwindow.h
|
seekableslider.h
|
||||||
seekableslider.h
|
playlistmanager.h
|
||||||
playlistmanager.h
|
singleapplicationmanager.h
|
||||||
singleapplicationmanager.h
|
lrcbar.h
|
||||||
lrcbar.h
|
|
||||||
lyricsmanager.h
|
lyricsmanager.h
|
||||||
fftspectrum.h
|
fftspectrum.h
|
||||||
playbackprogressindicator.h
|
)
|
||||||
)
|
|
||||||
|
set (PMUSIC_UI_FILES
|
||||||
set (PMUSIC_UI_FILES
|
mainwindow.ui
|
||||||
mainwindow.ui
|
)
|
||||||
)
|
|
||||||
|
set (EXE_NAME pmusic)
|
||||||
set (EXE_NAME pmusic)
|
|
||||||
|
# Translation
|
||||||
# Translation
|
file (GLOB PMUSIC_TS_FILES languages/*.ts)
|
||||||
file (GLOB PMUSIC_TS_FILES languages/*.ts)
|
set (PMUSIC_CPP_FILES_FOR_I18N ${PMUSIC_CPP_FILES} ${PMUSIC_UI_FILES})
|
||||||
set (PMUSIC_CPP_FILES_FOR_I18N ${PMUSIC_CPP_FILES} ${PMUSIC_UI_FILES})
|
|
||||||
|
add_executable(${EXE_NAME} WIN32
|
||||||
add_executable(${EXE_NAME}
|
${PMUSIC_HEADER_FILES}
|
||||||
${PMUSIC_HEADER_FILES}
|
${PMUSIC_CPP_FILES}
|
||||||
${PMUSIC_CPP_FILES}
|
${PMUSIC_UI_FILES}
|
||||||
${PMUSIC_UI_FILES}
|
resources.qrc
|
||||||
resources.qrc
|
)
|
||||||
)
|
|
||||||
|
qt_add_translations(${EXE_NAME}
|
||||||
qt_add_translations(${EXE_NAME}
|
TS_FILES
|
||||||
TS_FILES
|
${PMUSIC_TS_FILES}
|
||||||
${PMUSIC_TS_FILES}
|
)
|
||||||
)
|
|
||||||
|
if (WIN32)
|
||||||
if (WIN32)
|
target_sources(${EXE_NAME} PRIVATE assets/pineapple-music.rc)
|
||||||
target_sources(${EXE_NAME} PRIVATE assets/pineapple-music.rc)
|
endif ()
|
||||||
endif ()
|
|
||||||
|
if (NOT TagLib_FOUND)
|
||||||
if (NOT TagLib_FOUND)
|
target_compile_definitions(${EXE_NAME} PRIVATE NO_TAGLIB=1)
|
||||||
target_compile_definitions(${EXE_NAME} PRIVATE NO_TAGLIB=1)
|
else ()
|
||||||
else ()
|
target_link_libraries(${EXE_NAME} PRIVATE PkgConfig::TagLib)
|
||||||
target_link_libraries(${EXE_NAME} PRIVATE TagLib::tag)
|
endif ()
|
||||||
endif ()
|
|
||||||
|
if (TARGET KF6::Codecs)
|
||||||
if (TARGET KF6::Codecs)
|
target_compile_definitions(${EXE_NAME} PRIVATE HAVE_KCODECS=1)
|
||||||
target_compile_definitions(${EXE_NAME} PRIVATE HAVE_KCODECS=1)
|
target_link_libraries (${EXE_NAME} PRIVATE KF6::Codecs)
|
||||||
target_link_libraries (${EXE_NAME} PRIVATE KF6::Codecs)
|
endif ()
|
||||||
endif ()
|
|
||||||
|
target_link_libraries(${EXE_NAME} PRIVATE Qt::Widgets Qt::Multimedia Qt::Network kissfft::kissfft)
|
||||||
if (FFmpeg_FOUND)
|
|
||||||
target_compile_definitions(${EXE_NAME} PRIVATE HAVE_FFMPEG=1)
|
if (USE_QTEXTCODEC)
|
||||||
target_link_libraries (${EXE_NAME} PRIVATE FFmpeg::avutil FFmpeg::avformat)
|
target_compile_definitions(${EXE_NAME} PRIVATE USE_QTEXTCODEC=1)
|
||||||
endif ()
|
target_link_libraries(${EXE_NAME} PRIVATE Qt6::Core5Compat)
|
||||||
|
endif()
|
||||||
target_link_libraries(${EXE_NAME} PRIVATE Qt::Widgets Qt::Multimedia Qt::Network kissfft::kissfft)
|
|
||||||
|
# Install settings
|
||||||
if (USE_QTEXTCODEC)
|
if (WIN32)
|
||||||
target_compile_definitions(${EXE_NAME} PRIVATE USE_QTEXTCODEC=1)
|
# FIXME: try to avoid install to a "bin" subfolder under windows...
|
||||||
target_link_libraries(${EXE_NAME} PRIVATE Qt6::Core5Compat)
|
# when fixed, don't forget to update the CI config file...
|
||||||
endif()
|
elseif (UNIX)
|
||||||
|
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
||||||
# Install settings
|
set(CMAKE_INSTALL_PREFIX /usr)
|
||||||
if (WIN32)
|
endif ()
|
||||||
set_target_properties(${EXE_NAME} PROPERTIES
|
|
||||||
WIN32_EXECUTABLE TRUE
|
# install icon
|
||||||
)
|
install(
|
||||||
elseif (APPLE)
|
FILES icons/app-icon.svg
|
||||||
set_source_files_properties(assets/icons/app-icon.icns PROPERTIES
|
DESTINATION "${CMAKE_INSTALL_DATADIR}/icons/hicolor/48x48/apps"
|
||||||
MACOSX_PACKAGE_LOCATION "Resources"
|
RENAME net.blumia.pineapple-music.svg
|
||||||
)
|
)
|
||||||
target_sources(${EXE_NAME} PUBLIC assets/icons/app-icon.icns)
|
|
||||||
# See https://cmake.org/cmake/help/v3.15/prop_tgt/MACOSX_BUNDLE_INFO_PLIST.html
|
# install shortcut
|
||||||
set_target_properties(${EXE_NAME} PROPERTIES
|
install(
|
||||||
MACOSX_BUNDLE TRUE
|
FILES dist/net.blumia.pineapple-music.desktop
|
||||||
MACOSX_BUNDLE_BUNDLE_NAME "Pineapple Music"
|
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications"
|
||||||
MACOSX_BUNDLE_GUI_IDENTIFIER net.blumia.pineapple-music
|
)
|
||||||
MACOSX_BUNDLE_ICON_FILE app-icon.icns # contains the .icns file name, *without* the path.
|
endif()
|
||||||
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
|
|
||||||
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
set (INSTALL_TARGETS_DEFAULT_ARGS
|
||||||
)
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
elseif (UNIX)
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Devel
|
||||||
set(CMAKE_INSTALL_PREFIX /usr)
|
)
|
||||||
endif ()
|
|
||||||
|
install (
|
||||||
# install icon
|
TARGETS ${EXE_NAME}
|
||||||
install(
|
${INSTALL_TARGETS_DEFAULT_ARGS}
|
||||||
FILES icons/app-icon.svg
|
)
|
||||||
DESTINATION "${CMAKE_INSTALL_DATADIR}/icons/hicolor/48x48/apps"
|
|
||||||
RENAME net.blumia.pineapple-music.svg
|
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
|
||||||
)
|
|
||||||
|
|
||||||
# install shortcut
|
|
||||||
install(
|
|
||||||
FILES dist/net.blumia.pineapple-music.desktop
|
|
||||||
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications"
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set (INSTALL_TARGETS_DEFAULT_ARGS
|
|
||||||
BUNDLE DESTINATION .
|
|
||||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
||||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
||||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Devel
|
|
||||||
)
|
|
||||||
|
|
||||||
install (
|
|
||||||
TARGETS ${EXE_NAME}
|
|
||||||
${INSTALL_TARGETS_DEFAULT_ARGS}
|
|
||||||
)
|
|
||||||
|
|
||||||
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
|
|
||||||
|
18
README.md
18
README.md
@ -2,26 +2,12 @@
|
|||||||
|
|
||||||
Since **I** just need a simple player which *just works* right now, so I did many things in a dirty way. Don't feel so weird if you saw something I did in this project is using a bad approach.
|
Since **I** just need a simple player which *just works* right now, so I did many things in a dirty way. Don't feel so weird if you saw something I did in this project is using a bad approach.
|
||||||
|
|
||||||
### Features
|
### Feature Notice
|
||||||
|
|
||||||
We have the following features:
|
|
||||||
|
|
||||||
- [Sidecar](https://en.wikipedia.org/wiki/Sidecar_file) lyrics file (`.lrc`) support with an optional desktop lyrics bar widget
|
|
||||||
- Sidecar chapter file support
|
|
||||||
- [YouTube-style chapter](https://support.google.com/youtube/answer/9884579) saved to a plain text file with `.chp` suffix
|
|
||||||
- PotPlayer `.pbf` file, `[Bookmark]`s as chapters
|
|
||||||
- Auto-load all audio files in the same folder of the file that you attempted to play, into a playlist
|
|
||||||
|
|
||||||
These features are not available, some of them are TBD and others are not planned:
|
|
||||||
|
|
||||||
- File format support will be limited by the [FFmpeg version that Qt 6 uses](https://doc.qt.io/qt-6/qtmultimedia-attribution-ffmpeg.html).
|
- File format support will be limited by the [FFmpeg version that Qt 6 uses](https://doc.qt.io/qt-6/qtmultimedia-attribution-ffmpeg.html).
|
||||||
- ...which if you use Qt's official binary, only contains the LGPLv2.1+ part. (already good enough, tho)
|
- ...which if you use Qt's official binary, only contains the LGPLv2.1+ part. (already good enough, tho)
|
||||||
- No music library management support and there won't be one!
|
- No music library management support and there won't be one!
|
||||||
- It'll auto-load music files in the same folder of the file that you attempted to play, so organize your music files on a folder-basis.
|
- It'll auto-load music files in the same folder of the file that you attempted to play, so organize your music files on a folder-basis.
|
||||||
- Limited system integration:
|
|
||||||
- No [SMTC](https://learn.microsoft.com/en-us/uwp/api/windows.media.systemmediatransportcontrols) support under Windows for now
|
|
||||||
- No [MPRIS](https://www.freedesktop.org/wiki/Specifications/mpris-spec/) support under Linux desktop for now
|
|
||||||
- No "playback progress on taskbar icon" and "taskbar thumbnail buttons" support whatever on Windows or Linux desktop for now
|
|
||||||
- Limited lyrics (`.lrc`) loading support:
|
- Limited lyrics (`.lrc`) loading support:
|
||||||
- Currently no `.tlrc` (for translated lyrics) or `.rlrc` (for romanized lyrics) support.
|
- Currently no `.tlrc` (for translated lyrics) or `.rlrc` (for romanized lyrics) support.
|
||||||
- Multi-line lyrics and duplicated timestamps are not supported
|
- Multi-line lyrics and duplicated timestamps are not supported
|
||||||
@ -34,7 +20,7 @@ Current state, we need:
|
|||||||
- `cmake` as the build system.
|
- `cmake` as the build system.
|
||||||
- `qt6` with `qt6-multimedia` since we use it for playback.
|
- `qt6` with `qt6-multimedia` since we use it for playback.
|
||||||
- `taglib` to get the audio file properties.
|
- `taglib` to get the audio file properties.
|
||||||
- `kissfft` for FFT support (will be downloaded at configure-time by `cmake`).
|
- `pkg-config` to find the installed taglib.
|
||||||
|
|
||||||
Then we can build it with any proper c++ compiler like g++ or msvc.
|
Then we can build it with any proper c++ compiler like g++ or msvc.
|
||||||
|
|
||||||
|
@ -3,10 +3,11 @@ image:
|
|||||||
environment:
|
environment:
|
||||||
CMAKE_INSTALL_ROOT: C:\projects\cmake
|
CMAKE_INSTALL_ROOT: C:\projects\cmake
|
||||||
PACKAGE_INSTALL_ROOT: C:\projects\pir
|
PACKAGE_INSTALL_ROOT: C:\projects\pir
|
||||||
|
PKG_CONFIG_PATH: C:\projects\pir\lib\pkgconfig
|
||||||
matrix:
|
matrix:
|
||||||
- build_name: mingw1120_64_qt6_7
|
- build_name: mingw1120_64_qt6_7
|
||||||
QTPATH: C:\Qt\6.8\mingw_64
|
QTPATH: C:\Qt\6.7\mingw_64
|
||||||
MINGW64: C:\Qt\Tools\mingw1310_64
|
MINGW64: C:\Qt\Tools\mingw1120_64
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- mkdir %CMAKE_INSTALL_ROOT%
|
- mkdir %CMAKE_INSTALL_ROOT%
|
||||||
@ -22,6 +23,7 @@ build_script:
|
|||||||
- mkdir 3rdparty
|
- mkdir 3rdparty
|
||||||
- choco install ninja
|
- choco install ninja
|
||||||
- choco install gperf
|
- choco install gperf
|
||||||
|
- choco install pkgconfiglite
|
||||||
- cd 3rdparty
|
- cd 3rdparty
|
||||||
# install ECM
|
# install ECM
|
||||||
- git clone -q https://invent.kde.org/frameworks/extra-cmake-modules.git
|
- git clone -q https://invent.kde.org/frameworks/extra-cmake-modules.git
|
||||||
|
Binary file not shown.
@ -5,20 +5,15 @@
|
|||||||
#include "fftspectrum.h"
|
#include "fftspectrum.h"
|
||||||
|
|
||||||
#include <QAudioBuffer>
|
#include <QAudioBuffer>
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
|
|
||||||
#include <QAudioBufferOutput>
|
#include <QAudioBufferOutput>
|
||||||
#endif // QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
#include <kissfft.hh>
|
#include <kissfft.hh>
|
||||||
|
|
||||||
FFTSpectrum::FFTSpectrum(QWidget* parent)
|
FFTSpectrum::FFTSpectrum(QWidget* parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
|
|
||||||
, m_audioBufferOutput(new QAudioBufferOutput(this))
|
, m_audioBufferOutput(new QAudioBufferOutput(this))
|
||||||
#endif // #if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
|
|
||||||
{
|
{
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
|
|
||||||
connect(this, &FFTSpectrum::mediaPlayerChanged, this, [=]() {
|
connect(this, &FFTSpectrum::mediaPlayerChanged, this, [=]() {
|
||||||
if (m_mediaPlayer) {
|
if (m_mediaPlayer) {
|
||||||
m_mediaPlayer->setAudioBufferOutput(m_audioBufferOutput);
|
m_mediaPlayer->setAudioBufferOutput(m_audioBufferOutput);
|
||||||
@ -26,60 +21,25 @@ FFTSpectrum::FFTSpectrum(QWidget* parent)
|
|||||||
});
|
});
|
||||||
|
|
||||||
connect(m_audioBufferOutput, &QAudioBufferOutput::audioBufferReceived, this, [=](const QAudioBuffer& buffer) {
|
connect(m_audioBufferOutput, &QAudioBufferOutput::audioBufferReceived, this, [=](const QAudioBuffer& buffer) {
|
||||||
if (!isVisible()) return;
|
const QAudioFormat&& fmt = buffer.format();
|
||||||
const QAudioFormat& fmt = buffer.format();
|
|
||||||
const QAudioFormat::SampleFormat sampleFormat = fmt.sampleFormat();
|
const QAudioFormat::SampleFormat sampleFormat = fmt.sampleFormat();
|
||||||
QAudioFormat::ChannelConfig channelConfig = fmt.channelConfig();
|
int channelCount = fmt.channelCount();
|
||||||
const QFlags supportedChannelConfig({ QAudioFormat::ChannelConfigMono, QAudioFormat::ChannelConfigStereo });
|
|
||||||
const int frameCount = buffer.frameCount();
|
const int frameCount = buffer.frameCount();
|
||||||
kissfft<float> fft(frameCount, false);
|
kissfft<float> fft(frameCount, false);
|
||||||
std::vector<kissfft<float>::cpx_t> samples(frameCount);
|
std::vector<kissfft<float>::cpx_t> samples(frameCount);
|
||||||
std::vector<kissfft<float>::cpx_t> mass(frameCount);
|
std::vector<kissfft<float>::cpx_t> mass(frameCount);
|
||||||
if (sampleFormat == QAudioFormat::Int16 && supportedChannelConfig.testFlag(channelConfig)) {
|
if (sampleFormat == QAudioFormat::Int16 && channelCount == 1) {
|
||||||
if (channelConfig == QAudioFormat::ChannelConfigMono) {
|
const QAudioBuffer::S16M* data = buffer.constData<QAudioBuffer::S16M>();
|
||||||
const QAudioBuffer::S16M* data = buffer.constData<QAudioBuffer::S16M>();
|
for (int i = 0; i < frameCount; ++i) {
|
||||||
for (int i = 0; i < frameCount; ++i) {
|
samples[i].real(data[i].value(QAudioFormat::FrontCenter) / float(32768));
|
||||||
samples[i].real(data[i].value(QAudioFormat::FrontCenter) / float(32768));
|
samples[i].imag(0);
|
||||||
samples[i].imag(0);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const QAudioBuffer::S16S* data = buffer.constData<QAudioBuffer::S16S>();
|
|
||||||
for (int i = 0; i < frameCount; ++i) {
|
|
||||||
samples[i].real(data[i].value(QAudioFormat::FrontLeft) / float(32768));
|
|
||||||
samples[i].imag(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (sampleFormat == QAudioFormat::Int32 && supportedChannelConfig.testFlag(channelConfig)) {
|
} else if (sampleFormat == QAudioFormat::Float && channelCount == 2) {
|
||||||
if (channelConfig == QAudioFormat::ChannelConfigMono) {
|
const QAudioBuffer::F32S* data = buffer.constData<QAudioBuffer::F32S>();
|
||||||
const QAudioBuffer::S32M* data = buffer.constData<QAudioBuffer::S32M>();
|
for (int i = 0; i < frameCount; ++i) {
|
||||||
for (int i = 0; i < frameCount; ++i) {
|
samples[i].real(data[i].value(QAudioFormat::FrontLeft));
|
||||||
samples[i].real(data[i].value(QAudioFormat::FrontCenter) / float(2147483647));
|
samples[i].imag(0);
|
||||||
samples[i].imag(0);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const QAudioBuffer::S32S* data = buffer.constData<QAudioBuffer::S32S>();
|
|
||||||
for (int i = 0; i < frameCount; ++i) {
|
|
||||||
samples[i].real(data[i].value(QAudioFormat::FrontLeft) / float(2147483647));
|
|
||||||
samples[i].imag(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (sampleFormat == QAudioFormat::Float && supportedChannelConfig.testFlag(channelConfig)) {
|
|
||||||
if (channelConfig == QAudioFormat::ChannelConfigMono) {
|
|
||||||
const QAudioBuffer::F32M* data = buffer.constData<QAudioBuffer::F32M>();
|
|
||||||
for (int i = 0; i < frameCount; ++i) {
|
|
||||||
samples[i].real(data[i].value(QAudioFormat::FrontCenter));
|
|
||||||
samples[i].imag(0);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
qWarning() << "Unsupported format or channel config:" << sampleFormat << channelConfig;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
fft.transform(samples.data(), mass.data());
|
fft.transform(samples.data(), mass.data());
|
||||||
m_freq.resize(frameCount);
|
m_freq.resize(frameCount);
|
||||||
@ -89,9 +49,11 @@ FFTSpectrum::FFTSpectrum(QWidget* parent)
|
|||||||
for (auto& val : m_freq) {
|
for (auto& val : m_freq) {
|
||||||
val = log10(val + 1);
|
val = log10(val + 1);
|
||||||
}
|
}
|
||||||
|
qDebug() << m_freq.size() << "updated";
|
||||||
update();
|
update();
|
||||||
|
qDebug() << sampleFormat << channelCount;
|
||||||
});
|
});
|
||||||
#endif // QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
|
|
||||||
resize(490, 420);
|
resize(490, 420);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,15 +71,17 @@ void FFTSpectrum::setMediaPlayer(QMediaPlayer* player)
|
|||||||
void FFTSpectrum::paintEvent(QPaintEvent* e)
|
void FFTSpectrum::paintEvent(QPaintEvent* e)
|
||||||
{
|
{
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
|
painter.fillRect(rect(), Qt::black);
|
||||||
|
|
||||||
if (!m_freq.empty()) {
|
if (!m_freq.empty()) {
|
||||||
int width = this->width();
|
int width = this->width();
|
||||||
int height = this->height();
|
int height = this->height();
|
||||||
int barWidth = std::max(1, (int)(width / m_freq.size()));
|
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++) {
|
for (int i = 0; i < m_freq.size(); i++) {
|
||||||
int barHeight = static_cast<int>(sqrt(m_freq[i]) * height * 0.5);
|
int barHeight = static_cast<int>(m_freq[i] * height);
|
||||||
QColor color(70, 130, 180, std::min(255, (int)(140 * m_freq[i]) + 90));
|
painter.fillRect(i * barWidth, height - barHeight, barWidth, barHeight, Qt::green);
|
||||||
painter.fillRect(i * barWidth, height - barHeight, barWidth, barHeight, color);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,8 @@ bool LyricsManager::loadLyrics(QString filepath)
|
|||||||
QRegularExpressionMatch match = lrcRegex.match(line);
|
QRegularExpressionMatch match = lrcRegex.match(line);
|
||||||
while (match.hasMatch()) {
|
while (match.hasMatch()) {
|
||||||
tagSectionPassed = true;
|
tagSectionPassed = true;
|
||||||
timestamps.append(parseTimeToMilliseconds(match.captured(1)));
|
QTime timestamp(QTime::fromString(match.captured(1), "m:s.zz"));
|
||||||
|
timestamps.append(timestamp.msecsSinceStartOfDay());
|
||||||
currentLrc = match.captured(2);
|
currentLrc = match.captured(2);
|
||||||
match = lrcRegex.match(currentLrc);
|
match = lrcRegex.match(currentLrc);
|
||||||
}
|
}
|
||||||
@ -176,23 +177,6 @@ double LyricsManager::maskPercent(int curTimeMs)
|
|||||||
return (double)(curTimeMs - currentLyricsTime()) / (m_nextLyricsTime - m_currentLyricsTime);
|
return (double)(curTimeMs - currentLyricsTime()) / (m_nextLyricsTime - m_currentLyricsTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
int LyricsManager::parseTimeToMilliseconds(const QString &timeString)
|
|
||||||
{
|
|
||||||
QRegularExpression timeRegex(R"((\d{2,3}):(\d{2})\.(\d{2,3}))");
|
|
||||||
QRegularExpressionMatch match = timeRegex.match(timeString);
|
|
||||||
|
|
||||||
if (match.hasMatch()) {
|
|
||||||
int minutes = match.captured(1).toInt();
|
|
||||||
int seconds = match.captured(2).toInt();
|
|
||||||
int milliseconds = match.captured(3).toInt();
|
|
||||||
|
|
||||||
return minutes * 60000 + seconds * 1000 + milliseconds;
|
|
||||||
} else {
|
|
||||||
qCWarning(lcLyricsParser) << "Invalid time format:" << timeString;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void LyricsManager::reset()
|
void LyricsManager::reset()
|
||||||
{
|
{
|
||||||
m_currentLyricsTime = 0;
|
m_currentLyricsTime = 0;
|
||||||
|
@ -25,8 +25,6 @@ public:
|
|||||||
QString lyrics(int lineOffset = 0) const;
|
QString lyrics(int lineOffset = 0) const;
|
||||||
double maskPercent(int curTimeMs);
|
double maskPercent(int curTimeMs);
|
||||||
|
|
||||||
static int parseTimeToMilliseconds(const QString& timeString);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|
||||||
|
1
main.cpp
1
main.cpp
@ -21,6 +21,7 @@ int main(int argc, char *argv[])
|
|||||||
if (translator.load(QLocale(), QLatin1String("pineapple-music"), QLatin1String("_"), QLatin1String(":/i18n"))) {
|
if (translator.load(QLocale(), QLatin1String("pineapple-music"), QLatin1String("_"), QLatin1String(":/i18n"))) {
|
||||||
a.installTranslator(&translator);
|
a.installTranslator(&translator);
|
||||||
}
|
}
|
||||||
|
a.installTranslator(&translator);
|
||||||
|
|
||||||
// parse commandline arguments
|
// parse commandline arguments
|
||||||
QCommandLineParser parser;
|
QCommandLineParser parser;
|
||||||
|
108
mainwindow.cpp
108
mainwindow.cpp
@ -18,6 +18,7 @@
|
|||||||
#include <QMediaPlayer>
|
#include <QMediaPlayer>
|
||||||
#include <QMediaMetaData>
|
#include <QMediaMetaData>
|
||||||
#include <QAudioOutput>
|
#include <QAudioOutput>
|
||||||
|
#include <QAudioBuffer>
|
||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
@ -32,8 +33,6 @@
|
|||||||
#include <QAudioDevice>
|
#include <QAudioDevice>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
#include <QSettings>
|
|
||||||
#include <QGraphicsDropShadowEffect>
|
|
||||||
|
|
||||||
constexpr QSize miniSize(490, 160);
|
constexpr QSize miniSize(490, 160);
|
||||||
constexpr QSize fullSize(490, 420);
|
constexpr QSize fullSize(490, 420);
|
||||||
@ -59,18 +58,10 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
|
|
||||||
ui->actionHelp->setShortcut(QKeySequence::HelpContents);
|
ui->actionHelp->setShortcut(QKeySequence::HelpContents);
|
||||||
addAction(ui->actionHelp);
|
addAction(ui->actionHelp);
|
||||||
ui->actionOpen->setShortcut(QKeySequence::Open);
|
|
||||||
addAction(ui->actionOpen);
|
|
||||||
|
|
||||||
ui->titleLabel->setGraphicsEffect(createLabelShadowEffect());
|
|
||||||
ui->propLabel->setGraphicsEffect(createLabelShadowEffect());
|
|
||||||
ui->nowTimeLabel->setGraphicsEffect(createLabelShadowEffect());
|
|
||||||
ui->totalTimeLabel->setGraphicsEffect(createLabelShadowEffect());
|
|
||||||
|
|
||||||
setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint);
|
setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint);
|
||||||
setAttribute(Qt::WA_TranslucentBackground, true);
|
setAttribute(Qt::WA_TranslucentBackground, true);
|
||||||
|
|
||||||
loadConfig();
|
|
||||||
loadSkinData();
|
loadSkinData();
|
||||||
initConnections();
|
initConnections();
|
||||||
initUiAndAnimation();
|
initUiAndAnimation();
|
||||||
@ -80,7 +71,6 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
{
|
{
|
||||||
saveConfig();
|
|
||||||
delete m_lrcbar;
|
delete m_lrcbar;
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
@ -114,12 +104,12 @@ void MainWindow::setAudioPropertyInfoForDisplay(int sampleRate, int bitrate, int
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (sampleRate > 0) {
|
if (sampleRate >= 0) {
|
||||||
uiStrs << QString("%1 Hz").arg(sampleRate);
|
uiStrs << QString("%1 Hz").arg(sampleRate);
|
||||||
tooltipStrs << tr("Sample Rate: %1 Hz").arg(sampleRate);
|
tooltipStrs << tr("Sample Rate: %1 Hz").arg(sampleRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bitrate > 0) {
|
if (bitrate >= 0) {
|
||||||
uiStrs << QString("%1 Kbps").arg(bitrate);
|
uiStrs << QString("%1 Kbps").arg(bitrate);
|
||||||
tooltipStrs << tr("Bitrate: %1 Kbps").arg(bitrate);
|
tooltipStrs << tr("Bitrate: %1 Kbps").arg(bitrate);
|
||||||
}
|
}
|
||||||
@ -242,12 +232,6 @@ void MainWindow::dropEvent(QDropEvent *e)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileName.endsWith(".chp") || fileName.endsWith(".pbf")) {
|
|
||||||
QList<std::pair<qint64, QString>> chapters(PlaybackProgressIndicator::tryLoadSidecarChapterFile(fileName));
|
|
||||||
ui->playbackProgressIndicator->setChapters(chapters);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QModelIndex & modelIndex = m_playlistManager->loadPlaylist(urls);
|
const QModelIndex & modelIndex = m_playlistManager->loadPlaylist(urls);
|
||||||
if (modelIndex.isValid()) {
|
if (modelIndex.isValid()) {
|
||||||
loadByModelIndex(modelIndex);
|
loadByModelIndex(modelIndex);
|
||||||
@ -270,22 +254,14 @@ void MainWindow::loadFile()
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_playlistManager->loadPlaylist(urlList);
|
m_playlistManager->loadPlaylist(urlList);
|
||||||
const QUrl & firstUrl = urlList.first();
|
m_mediaPlayer->setSource(urlList.first());
|
||||||
loadFile(firstUrl);
|
m_lrcbar->loadLyrics(urlList.first().toLocalFile());
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::loadFile(const QUrl &url)
|
|
||||||
{
|
|
||||||
const QString filePath = url.toLocalFile();
|
|
||||||
m_mediaPlayer->setSource(url);
|
|
||||||
m_lrcbar->loadLyrics(filePath);
|
|
||||||
QList<std::pair<qint64, QString>> chapters(PlaybackProgressIndicator::tryLoadChapters(filePath));
|
|
||||||
ui->playbackProgressIndicator->setChapters(chapters);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::loadByModelIndex(const QModelIndex & index)
|
void MainWindow::loadByModelIndex(const QModelIndex & index)
|
||||||
{
|
{
|
||||||
loadFile(m_playlistManager->urlByIndex(index));
|
m_mediaPlayer->setSource(m_playlistManager->urlByIndex(index));
|
||||||
|
m_lrcbar->loadLyrics(m_playlistManager->localFileByIndex(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::play()
|
void MainWindow::play()
|
||||||
@ -373,6 +349,14 @@ void MainWindow::on_stopBtn_clicked()
|
|||||||
m_mediaPlayer->stop();
|
m_mediaPlayer->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_playbackSlider_valueChanged(int value)
|
||||||
|
{
|
||||||
|
qint64 currPos = m_mediaPlayer->duration() == 0 ? value : m_mediaPlayer->position() * ui->playbackSlider->maximum() / m_mediaPlayer->duration();
|
||||||
|
if (qAbs(currPos - value) > 2) {
|
||||||
|
m_mediaPlayer->setPosition(ui->playbackSlider->value() * 1.0 / ui->playbackSlider->maximum() * m_mediaPlayer->duration());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::on_prevBtn_clicked()
|
void MainWindow::on_prevBtn_clicked()
|
||||||
{
|
{
|
||||||
QModelIndex index(m_playlistManager->previousIndex());
|
QModelIndex index(m_playlistManager->previousIndex());
|
||||||
@ -420,10 +404,6 @@ void MainWindow::initConnections()
|
|||||||
m_audioOutput->setDevice(m_mediaDevices->defaultAudioOutput());
|
m_audioOutput->setDevice(m_mediaDevices->defaultAudioOutput());
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(ui->playbackProgressIndicator, &PlaybackProgressIndicator::seekingRequested, this, [=](qint64 pos){
|
|
||||||
m_mediaPlayer->setPosition(pos);
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(m_mediaPlayer, &QMediaPlayer::sourceChanged, this, [=](){
|
connect(m_mediaPlayer, &QMediaPlayer::sourceChanged, this, [=](){
|
||||||
QUrl fileUrl(m_mediaPlayer->source());
|
QUrl fileUrl(m_mediaPlayer->source());
|
||||||
|
|
||||||
@ -441,8 +421,6 @@ void MainWindow::initConnections()
|
|||||||
if (!fileRef.isNull() && fileRef.audioProperties()) {
|
if (!fileRef.isNull() && fileRef.audioProperties()) {
|
||||||
TagLib::AudioProperties *prop = fileRef.audioProperties();
|
TagLib::AudioProperties *prop = fileRef.audioProperties();
|
||||||
setAudioPropertyInfoForDisplay(prop->sampleRate(), prop->bitrate(), prop->channels(), suffix);
|
setAudioPropertyInfoForDisplay(prop->sampleRate(), prop->bitrate(), prop->channels(), suffix);
|
||||||
} else {
|
|
||||||
qDebug() << "No Audio Properties from TagLib";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fileRef.isNull() && fileRef.tag()) {
|
if (!fileRef.isNull() && fileRef.tag()) {
|
||||||
@ -450,10 +428,6 @@ void MainWindow::initConnections()
|
|||||||
setAudioMetadataForDisplay(QString::fromStdString(tag->title().to8Bit(true)),
|
setAudioMetadataForDisplay(QString::fromStdString(tag->title().to8Bit(true)),
|
||||||
QString::fromStdString(tag->artist().to8Bit(true)),
|
QString::fromStdString(tag->artist().to8Bit(true)),
|
||||||
QString::fromStdString(tag->album().to8Bit(true)));
|
QString::fromStdString(tag->album().to8Bit(true)));
|
||||||
m_urlMissingTagLibMetadata.clear();
|
|
||||||
} else {
|
|
||||||
qDebug() << "No Audio Metadata from TagLib";
|
|
||||||
m_urlMissingTagLibMetadata = fileUrl;
|
|
||||||
}
|
}
|
||||||
#endif // NO_TAGLIB
|
#endif // NO_TAGLIB
|
||||||
}
|
}
|
||||||
@ -465,17 +439,11 @@ void MainWindow::initConnections()
|
|||||||
// see `02 Yoiyami Hanabi.mp3`'s Title. So we don't use Qt's one if tablib is available.
|
// see `02 Yoiyami Hanabi.mp3`'s Title. So we don't use Qt's one if tablib is available.
|
||||||
qDebug() << metadata.stringValue(QMediaMetaData::Title) << metadata.stringValue(QMediaMetaData::Author);
|
qDebug() << metadata.stringValue(QMediaMetaData::Title) << metadata.stringValue(QMediaMetaData::Author);
|
||||||
#ifdef NO_TAGLIB
|
#ifdef NO_TAGLIB
|
||||||
bool needMetadataFromQt = true;
|
setAudioMetadataForDisplay(metadata.stringValue(QMediaMetaData::Title),
|
||||||
#else
|
metadata.stringValue(QMediaMetaData::Author),
|
||||||
bool needMetadataFromQt = m_urlMissingTagLibMetadata == m_mediaPlayer->source();
|
metadata.stringValue(QMediaMetaData::AlbumTitle));
|
||||||
|
setAudioPropertyInfoForDisplay(-1, metadata.value(QMediaMetaData::AudioBitRate).toInt() / 1000, -1, metadata.stringValue(QMediaMetaData::FileFormat));
|
||||||
#endif // NO_TAGLIB
|
#endif // NO_TAGLIB
|
||||||
if (needMetadataFromQt) {
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
QVariant coverArt(metadata.value(QMediaMetaData::ThumbnailImage));
|
QVariant coverArt(metadata.value(QMediaMetaData::ThumbnailImage));
|
||||||
if (!coverArt.isNull()) {
|
if (!coverArt.isNull()) {
|
||||||
ui->coverLabel->setPixmap(QPixmap::fromImage(coverArt.value<QImage>()));
|
ui->coverLabel->setPixmap(QPixmap::fromImage(coverArt.value<QImage>()));
|
||||||
@ -491,7 +459,7 @@ void MainWindow::initConnections()
|
|||||||
connect(m_mediaPlayer, &QMediaPlayer::positionChanged, this, [=](qint64 pos) {
|
connect(m_mediaPlayer, &QMediaPlayer::positionChanged, this, [=](qint64 pos) {
|
||||||
ui->nowTimeLabel->setText(ms2str(pos));
|
ui->nowTimeLabel->setText(ms2str(pos));
|
||||||
if (m_mediaPlayer->duration() != 0) {
|
if (m_mediaPlayer->duration() != 0) {
|
||||||
ui->playbackProgressIndicator->setPosition(pos);
|
ui->playbackSlider->setSliderPosition(ui->playbackSlider->maximum() * pos / m_mediaPlayer->duration());
|
||||||
}
|
}
|
||||||
m_lrcbar->playbackPositionChanged(pos, m_mediaPlayer->duration());
|
m_lrcbar->playbackPositionChanged(pos, m_mediaPlayer->duration());
|
||||||
});
|
});
|
||||||
@ -505,7 +473,6 @@ void MainWindow::initConnections()
|
|||||||
});
|
});
|
||||||
|
|
||||||
connect(m_mediaPlayer, &QMediaPlayer::durationChanged, this, [=](qint64 dua) {
|
connect(m_mediaPlayer, &QMediaPlayer::durationChanged, this, [=](qint64 dua) {
|
||||||
ui->playbackProgressIndicator->setDuration(dua);
|
|
||||||
ui->totalTimeLabel->setText(ms2str(dua));
|
ui->totalTimeLabel->setText(ms2str(dua));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -564,27 +531,9 @@ void MainWindow::initConnections()
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::loadConfig()
|
|
||||||
{
|
|
||||||
QDir configDir(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation));
|
|
||||||
QSettings settings(configDir.filePath("settings.ini"), QSettings::IniFormat);
|
|
||||||
ui->volumeSlider->setValue(settings.value("volume", 100).toInt());
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::saveConfig()
|
|
||||||
{
|
|
||||||
QDir configDir(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation));
|
|
||||||
if (!configDir.exists()) {
|
|
||||||
configDir.mkpath(".");
|
|
||||||
}
|
|
||||||
QSettings settings(configDir.filePath("settings.ini"), QSettings::IniFormat);
|
|
||||||
settings.setValue("volume", ui->volumeSlider->value());
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::loadSkinData()
|
void MainWindow::loadSkinData()
|
||||||
{
|
{
|
||||||
QDir configDir(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation));
|
QFile file(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/skin.dat");
|
||||||
QFile file(configDir.filePath("skin.dat"));
|
|
||||||
bool canOpen = file.open(QIODevice::ReadOnly);
|
bool canOpen = file.open(QIODevice::ReadOnly);
|
||||||
if (!canOpen) return;
|
if (!canOpen) return;
|
||||||
QDataStream stream(&file);
|
QDataStream stream(&file);
|
||||||
@ -660,10 +609,6 @@ void MainWindow::on_lrcBtn_clicked()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionOpen_triggered()
|
|
||||||
{
|
|
||||||
loadFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::on_actionHelp_triggered()
|
void MainWindow::on_actionHelp_triggered()
|
||||||
{
|
{
|
||||||
@ -690,18 +635,9 @@ void MainWindow::on_actionHelp_triggered()
|
|||||||
"\n"
|
"\n"
|
||||||
"[Source Code](https://github.com/BLumia/pineapple-music)\n"
|
"[Source Code](https://github.com/BLumia/pineapple-music)\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Copyright © 2025 [BLumia](https://github.com/BLumia/)"
|
"Copyright © 2024 [BLumia](https://github.com/BLumia/)"
|
||||||
);
|
);
|
||||||
infoBox.setTextFormat(Qt::MarkdownText);
|
infoBox.setTextFormat(Qt::MarkdownText);
|
||||||
infoBox.exec();
|
infoBox.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
QGraphicsDropShadowEffect *MainWindow::createLabelShadowEffect()
|
|
||||||
{
|
|
||||||
QGraphicsDropShadowEffect * effect = new QGraphicsDropShadowEffect(this);
|
|
||||||
effect->setBlurRadius(3);
|
|
||||||
effect->setColor(QColor(0, 0, 0, 180));
|
|
||||||
effect->setOffset(1, 1);
|
|
||||||
return effect;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
10
mainwindow.h
10
mainwindow.h
@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QUrl>
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
namespace Ui { class MainWindow; }
|
namespace Ui { class MainWindow; }
|
||||||
@ -16,7 +15,6 @@ class QMediaDevices;
|
|||||||
class QMediaPlayer;
|
class QMediaPlayer;
|
||||||
class QAudioOutput;
|
class QAudioOutput;
|
||||||
class QPropertyAnimation;
|
class QPropertyAnimation;
|
||||||
class QGraphicsDropShadowEffect;
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
class FFTSpectrum;
|
class FFTSpectrum;
|
||||||
@ -56,7 +54,6 @@ protected:
|
|||||||
void dropEvent(QDropEvent *e) override;
|
void dropEvent(QDropEvent *e) override;
|
||||||
|
|
||||||
void loadFile();
|
void loadFile();
|
||||||
void loadFile(const QUrl &url);
|
|
||||||
void loadByModelIndex(const QModelIndex &index);
|
void loadByModelIndex(const QModelIndex &index);
|
||||||
void play();
|
void play();
|
||||||
|
|
||||||
@ -70,6 +67,7 @@ private slots:
|
|||||||
void on_playBtn_clicked();
|
void on_playBtn_clicked();
|
||||||
void on_volumeSlider_valueChanged(int value);
|
void on_volumeSlider_valueChanged(int value);
|
||||||
void on_stopBtn_clicked();
|
void on_stopBtn_clicked();
|
||||||
|
void on_playbackSlider_valueChanged(int value);
|
||||||
void on_prevBtn_clicked();
|
void on_prevBtn_clicked();
|
||||||
void on_nextBtn_clicked();
|
void on_nextBtn_clicked();
|
||||||
void on_volumeBtn_clicked();
|
void on_volumeBtn_clicked();
|
||||||
@ -78,20 +76,16 @@ private slots:
|
|||||||
void on_playListBtn_clicked();
|
void on_playListBtn_clicked();
|
||||||
void on_playlistView_activated(const QModelIndex &index);
|
void on_playlistView_activated(const QModelIndex &index);
|
||||||
void on_lrcBtn_clicked();
|
void on_lrcBtn_clicked();
|
||||||
void on_actionOpen_triggered();
|
|
||||||
void on_actionHelp_triggered();
|
void on_actionHelp_triggered();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void playbackModeChanged(enum PlaybackMode mode);
|
void playbackModeChanged(enum PlaybackMode mode);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QGraphicsDropShadowEffect * createLabelShadowEffect();
|
|
||||||
|
|
||||||
bool m_clickedOnWindow = false;
|
bool m_clickedOnWindow = false;
|
||||||
bool m_playbackSliderPressed = false;
|
bool m_playbackSliderPressed = false;
|
||||||
QLinearGradient m_bgLinearGradient;
|
QLinearGradient m_bgLinearGradient;
|
||||||
QPixmap m_skin;
|
QPixmap m_skin;
|
||||||
QUrl m_urlMissingTagLibMetadata;
|
|
||||||
enum PlaybackMode m_playbackMode = CurrentItemInLoop;
|
enum PlaybackMode m_playbackMode = CurrentItemInLoop;
|
||||||
|
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
@ -107,8 +101,6 @@ private:
|
|||||||
void initUiAndAnimation();
|
void initUiAndAnimation();
|
||||||
void initConnections();
|
void initConnections();
|
||||||
|
|
||||||
void loadConfig();
|
|
||||||
void saveConfig();
|
|
||||||
void loadSkinData();
|
void loadSkinData();
|
||||||
void saveSkinData();
|
void saveSkinData();
|
||||||
|
|
||||||
|
@ -72,7 +72,6 @@ QSlider::add-page:vertical {
|
|||||||
/****** PushButton ******/
|
/****** PushButton ******/
|
||||||
|
|
||||||
QPushButton {
|
QPushButton {
|
||||||
color: white;
|
|
||||||
border: 0px solid grey;
|
border: 0px solid grey;
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
}
|
}
|
||||||
@ -107,7 +106,6 @@ QLabel#coverLabel {
|
|||||||
/****** ListView ******/
|
/****** ListView ******/
|
||||||
|
|
||||||
QListView {
|
QListView {
|
||||||
color: white;
|
|
||||||
background: rgba(0, 0, 0, 50);
|
background: rgba(0, 0, 0, 50);
|
||||||
}</string>
|
}</string>
|
||||||
</property>
|
</property>
|
||||||
@ -371,7 +369,14 @@ QListView {
|
|||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="PlaybackProgressIndicator" name="playbackProgressIndicator" native="true"/>
|
<widget class="SeekableSlider" name="playbackSlider">
|
||||||
|
<property name="maximum">
|
||||||
|
<number>1000</number>
|
||||||
|
</property>
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Orientation::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="playbackControlLayout">
|
<layout class="QHBoxLayout" name="playbackControlLayout">
|
||||||
@ -654,10 +659,7 @@ QListView {
|
|||||||
</widget>
|
</widget>
|
||||||
<action name="actionHelp">
|
<action name="actionHelp">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Help</string>
|
<string>help</string>
|
||||||
</property>
|
|
||||||
<property name="toolTip">
|
|
||||||
<string>Help</string>
|
|
||||||
</property>
|
</property>
|
||||||
<property name="shortcut">
|
<property name="shortcut">
|
||||||
<string>F1</string>
|
<string>F1</string>
|
||||||
@ -666,20 +668,6 @@ QListView {
|
|||||||
<enum>QAction::MenuRole::NoRole</enum>
|
<enum>QAction::MenuRole::NoRole</enum>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionOpen">
|
|
||||||
<property name="icon">
|
|
||||||
<iconset theme="document-open"/>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Open</string>
|
|
||||||
</property>
|
|
||||||
<property name="shortcut">
|
|
||||||
<string>Ctrl+O</string>
|
|
||||||
</property>
|
|
||||||
<property name="menuRole">
|
|
||||||
<enum>QAction::MenuRole::NoRole</enum>
|
|
||||||
</property>
|
|
||||||
</action>
|
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
@ -687,12 +675,6 @@ QListView {
|
|||||||
<extends>QSlider</extends>
|
<extends>QSlider</extends>
|
||||||
<header>seekableslider.h</header>
|
<header>seekableslider.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
|
||||||
<class>PlaybackProgressIndicator</class>
|
|
||||||
<extends>QWidget</extends>
|
|
||||||
<header>playbackprogressindicator.h</header>
|
|
||||||
<container>1</container>
|
|
||||||
</customwidget>
|
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="resources.qrc"/>
|
<include location="resources.qrc"/>
|
||||||
|
@ -1,311 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: 2025 Gary Wang <git@blumia.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
#include "playbackprogressindicator.h"
|
|
||||||
|
|
||||||
#include <QDir>
|
|
||||||
#include <QFile>
|
|
||||||
#include <QFileInfo>
|
|
||||||
#include <QPainter>
|
|
||||||
#include <QPainterPath>
|
|
||||||
#include <QRegularExpression>
|
|
||||||
|
|
||||||
#ifdef HAVE_FFMPEG
|
|
||||||
extern "C" {
|
|
||||||
#include <libavformat/avformat.h>
|
|
||||||
#include <libavutil/avutil.h>
|
|
||||||
#include <libavutil/dict.h>
|
|
||||||
#include <libavutil/time.h> // Contains AV_TIME_BASE and AV_TIME_BASE_Q
|
|
||||||
} // extern "C"
|
|
||||||
#endif // HAVE_FFMPEG
|
|
||||||
|
|
||||||
PlaybackProgressIndicator::PlaybackProgressIndicator(QWidget *parent) :
|
|
||||||
QWidget(parent)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlaybackProgressIndicator::setPosition(qint64 pos)
|
|
||||||
{
|
|
||||||
m_position = pos;
|
|
||||||
emit positionChanged(m_position);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlaybackProgressIndicator::setDuration(qint64 dur)
|
|
||||||
{
|
|
||||||
m_duration = dur;
|
|
||||||
emit durationChanged(m_duration);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlaybackProgressIndicator::setChapters(QList<std::pair<qint64, QString> > chapters)
|
|
||||||
{
|
|
||||||
qDebug() << chapters;
|
|
||||||
m_chapterModel.clear();
|
|
||||||
for (const std::pair<qint64, QString> & chapter : chapters) {
|
|
||||||
QStandardItem * chapterItem = new QStandardItem(chapter.second);
|
|
||||||
chapterItem->setData(chapter.first, StartTimeMsRole);
|
|
||||||
m_chapterModel.appendRow(chapterItem);
|
|
||||||
}
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<std::pair<qint64, QString> > PlaybackProgressIndicator::tryLoadChapters(const QString &filePath)
|
|
||||||
{
|
|
||||||
auto chapters = tryLoadSidecarChapterFile(filePath);
|
|
||||||
if (chapters.size() == 0) {
|
|
||||||
chapters = tryLoadChaptersFromMetadata(filePath);
|
|
||||||
}
|
|
||||||
return chapters;
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<std::pair<qint64, QString> > PlaybackProgressIndicator::tryLoadSidecarChapterFile(const QString &filePath)
|
|
||||||
{
|
|
||||||
if (filePath.endsWith(".chp", Qt::CaseInsensitive)) {
|
|
||||||
return parseCHPChapterFile(filePath);
|
|
||||||
} else if (filePath.endsWith(".pbf", Qt::CaseInsensitive)) {
|
|
||||||
return parsePBFChapterFile(filePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
QFileInfo fileInfo(filePath);
|
|
||||||
fileInfo.setFile(fileInfo.dir().filePath(fileInfo.completeBaseName() + ".chp"));
|
|
||||||
if (fileInfo.exists()) {
|
|
||||||
return parseCHPChapterFile(fileInfo.absoluteFilePath());
|
|
||||||
}
|
|
||||||
fileInfo.setFile(fileInfo.dir().filePath(fileInfo.completeBaseName() + ".pbf"));
|
|
||||||
if (fileInfo.exists()) {
|
|
||||||
return parsePBFChapterFile(fileInfo.absoluteFilePath());
|
|
||||||
}
|
|
||||||
fileInfo.setFile(filePath + ".chp");
|
|
||||||
if (fileInfo.exists()) {
|
|
||||||
return parseCHPChapterFile(fileInfo.absoluteFilePath());
|
|
||||||
}
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef HAVE_FFMPEG
|
|
||||||
|
|
||||||
// Helper function to convert FFmpeg time (in time_base units) to milliseconds
|
|
||||||
qint64 convertTimestampToMilliseconds(int64_t timestamp, AVRational time_base) {
|
|
||||||
// Convert to seconds first, then to milliseconds and cast to qint64
|
|
||||||
return static_cast<qint64>((double)timestamp * av_q2d(time_base) * 1000.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper function to print FFmpeg errors
|
|
||||||
void printFFmpegError(int errnum) {
|
|
||||||
char errbuf[AV_ERROR_MAX_STRING_SIZE];
|
|
||||||
av_strerror(errnum, errbuf, sizeof(errbuf));
|
|
||||||
qCritical() << "FFmpeg error:" << errbuf;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // HAVE_FFMPEG
|
|
||||||
|
|
||||||
QList<std::pair<qint64, QString> > PlaybackProgressIndicator::tryLoadChaptersFromMetadata(const QString &filePath)
|
|
||||||
{
|
|
||||||
#ifdef HAVE_FFMPEG
|
|
||||||
if (!QFile::exists(filePath)) {
|
|
||||||
qCritical() << "Error: File not found" << filePath;
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
AVFormatContext* format_ctx = nullptr; // FFmpeg format context
|
|
||||||
int ret = 0; // Return value for FFmpeg functions
|
|
||||||
|
|
||||||
qInfo() << "Attempting to open file:" << filePath;
|
|
||||||
|
|
||||||
// Open the input file and read the header.
|
|
||||||
// The last two arguments (AVInputFormat*, AVDictionary**) are optional.
|
|
||||||
// Passing nullptr for them means FFmpeg will try to guess the format
|
|
||||||
// and no options will be passed to the demuxer.
|
|
||||||
ret = avformat_open_input(&format_ctx, filePath.toUtf8().constData(), nullptr, nullptr);
|
|
||||||
if (ret < 0) {
|
|
||||||
qCritical() << "Could not open input file:" << filePath;
|
|
||||||
printFFmpegError(ret);
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
qInfo() << "File opened successfully.";
|
|
||||||
|
|
||||||
// Read stream information from the file.
|
|
||||||
// This populates format_ctx->streams and other metadata, including chapters.
|
|
||||||
ret = avformat_find_stream_info(format_ctx, nullptr);
|
|
||||||
if (ret < 0) {
|
|
||||||
qCritical() << "Could not find stream information for file:" << filePath;
|
|
||||||
printFFmpegError(ret);
|
|
||||||
avformat_close_input(&format_ctx); // Close the context before returning
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
qInfo() << "Stream information found.";
|
|
||||||
|
|
||||||
QList<std::pair<qint64, QString>> chapterList;
|
|
||||||
|
|
||||||
// Check if there are any chapters
|
|
||||||
if (format_ctx->nb_chapters == 0) {
|
|
||||||
qInfo() << "No chapters found in file:" << filePath;
|
|
||||||
} else {
|
|
||||||
qInfo() << "Found" << format_ctx->nb_chapters << "chapters.";
|
|
||||||
// Iterate through each chapter
|
|
||||||
for (unsigned int i = 0; i < format_ctx->nb_chapters; ++i) {
|
|
||||||
AVChapter* chapter = format_ctx->chapters[i];
|
|
||||||
|
|
||||||
// Chapter timestamps are typically in AV_TIME_BASE units by default
|
|
||||||
// unless the chapter itself has a specific time_base.
|
|
||||||
// For simplicity and common cases, we use AV_TIME_BASE_Q.
|
|
||||||
qint64 start_ms = convertTimestampToMilliseconds(chapter->start, chapter->time_base);
|
|
||||||
|
|
||||||
// Get the chapter title from its metadata.
|
|
||||||
// av_dict_get(dictionary, key, prev, flags)
|
|
||||||
// prev is used for iterating through multiple entries with the same key,
|
|
||||||
// we want the first one so we pass nullptr. flags=0 for case-insensitive.
|
|
||||||
AVDictionaryEntry* title_tag = av_dict_get(chapter->metadata, "title", nullptr, 0);
|
|
||||||
QString chapter_title = (title_tag && title_tag->value) ? QString::fromUtf8(title_tag->value) : "Untitled Chapter";
|
|
||||||
|
|
||||||
chapterList.append(std::make_pair(start_ms, chapter_title));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close the input file.
|
|
||||||
// This also frees the format_ctx and associated data.
|
|
||||||
avformat_close_input(&format_ctx);
|
|
||||||
qInfo() << "File closed.";
|
|
||||||
|
|
||||||
return chapterList;
|
|
||||||
#else
|
|
||||||
qInfo() << "FFmpeg not found during build.";
|
|
||||||
return {};
|
|
||||||
#endif // HAVE_FFMPEG
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<std::pair<qint64, QString> > PlaybackProgressIndicator::parseCHPChapterFile(const QString &filePath)
|
|
||||||
{
|
|
||||||
QList<std::pair<qint64, QString>> chapters;
|
|
||||||
QFile file(filePath);
|
|
||||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
||||||
return chapters;
|
|
||||||
}
|
|
||||||
|
|
||||||
QTextStream in(&file);
|
|
||||||
QRegularExpression timeRegex(R"((\d{1,2}):(\d{2})(?::(\d{2}))?(?:\.(\d{1,3}))?)");
|
|
||||||
|
|
||||||
while (!in.atEnd()) {
|
|
||||||
QString line = in.readLine().trimmed();
|
|
||||||
QRegularExpressionMatch match = timeRegex.match(line);
|
|
||||||
if (match.hasMatch()) {
|
|
||||||
int hours = match.capturedView(3).isEmpty() ? 0 : match.capturedView(1).toInt();
|
|
||||||
int minutes = match.capturedView(3).isEmpty() ? match.capturedView(1).toInt() : match.capturedView(2).toInt();
|
|
||||||
int seconds = match.capturedView(3).isEmpty() ? match.capturedView(2).toInt() : match.capturedView(3).toInt();
|
|
||||||
int milliseconds = 0;
|
|
||||||
|
|
||||||
QStringView millisecondsStr(match.capturedView(4));
|
|
||||||
if (!millisecondsStr.isEmpty()) {
|
|
||||||
milliseconds = millisecondsStr.toInt() * pow(10, 3 - millisecondsStr.length());
|
|
||||||
}
|
|
||||||
|
|
||||||
qint64 totalMilliseconds = (hours * 3600 + minutes * 60 + seconds) * 1000 + milliseconds;
|
|
||||||
|
|
||||||
QString chapterTitle = line.mid(match.capturedLength()).trimmed();
|
|
||||||
chapters.append(std::make_pair(totalMilliseconds, chapterTitle));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
file.close();
|
|
||||||
return chapters;
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<std::pair<qint64, QString> > PlaybackProgressIndicator::parsePBFChapterFile(const QString &filePath)
|
|
||||||
{
|
|
||||||
QList<std::pair<qint64, QString>> chapters;
|
|
||||||
QFile file(filePath);
|
|
||||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
||||||
return chapters;
|
|
||||||
}
|
|
||||||
|
|
||||||
QTextStream in(&file);
|
|
||||||
QRegularExpression chapterRegex(R"(^\d+=(\d+)\*([^*]*)\*.*$)");
|
|
||||||
|
|
||||||
while (!in.atEnd()) {
|
|
||||||
QString line = in.readLine().trimmed();
|
|
||||||
QRegularExpressionMatch match = chapterRegex.match(line);
|
|
||||||
if (match.hasMatch()) {
|
|
||||||
qint64 timestamp = match.captured(1).toLongLong();
|
|
||||||
QString title = match.captured(2).trimmed();
|
|
||||||
chapters.append(std::make_pair(timestamp, title));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
file.close();
|
|
||||||
return chapters;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlaybackProgressIndicator::paintEvent(QPaintEvent *event)
|
|
||||||
{
|
|
||||||
constexpr int progressBarHeight = 6;
|
|
||||||
constexpr QColor activeColor = QColor(85, 170, 0);
|
|
||||||
const QPointF topLeft(0, height() / 2.0 - progressBarHeight / 2.0);
|
|
||||||
const QSizeF barSize(width(), progressBarHeight);
|
|
||||||
|
|
||||||
const float currentProgress = m_duration <= 0 ? 0 : (m_seekingPosition >= 0 ? m_seekingPosition : m_position) / (float)m_duration;
|
|
||||||
const QSizeF progressSize(width() * currentProgress, progressBarHeight);
|
|
||||||
|
|
||||||
QPainterPath theProgress;
|
|
||||||
theProgress.addRoundedRect(QRectF(topLeft, progressSize), progressBarHeight / 2, progressBarHeight / 2);
|
|
||||||
|
|
||||||
QPainter painter(this);
|
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
|
||||||
painter.save();
|
|
||||||
|
|
||||||
// the bar itself
|
|
||||||
painter.setPen(Qt::gray);
|
|
||||||
painter.drawRoundedRect(QRectF(topLeft, barSize), progressBarHeight / 2, progressBarHeight / 2);
|
|
||||||
painter.fillPath(theProgress, activeColor);
|
|
||||||
|
|
||||||
// progress
|
|
||||||
painter.setPen(activeColor);
|
|
||||||
painter.drawPath(theProgress);
|
|
||||||
|
|
||||||
// chapter markers
|
|
||||||
if (m_duration > 0) {
|
|
||||||
painter.setPen(Qt::lightGray);
|
|
||||||
for (int i = 0; i < m_chapterModel.rowCount(); i++) {
|
|
||||||
qint64 chapterStartTime = m_chapterModel.item(i)->data(StartTimeMsRole).toInt();
|
|
||||||
if (chapterStartTime == 0) continue;
|
|
||||||
if (chapterStartTime > m_duration) break;
|
|
||||||
float chapterPercent = chapterStartTime / (float)m_duration;
|
|
||||||
float chapterPosX = width() * chapterPercent;
|
|
||||||
painter.drawLine(topLeft + QPoint(chapterPosX, 0),
|
|
||||||
topLeft + QPoint(chapterPosX, progressBarHeight));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
painter.restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlaybackProgressIndicator::mousePressEvent(QMouseEvent *event)
|
|
||||||
{
|
|
||||||
if (m_duration > 0) {
|
|
||||||
event->accept();
|
|
||||||
} else {
|
|
||||||
return QWidget::mousePressEvent(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlaybackProgressIndicator::mouseMoveEvent(QMouseEvent *event)
|
|
||||||
{
|
|
||||||
if (m_duration > 0) {
|
|
||||||
m_seekingPosition = event->position().x() * m_duration / width();
|
|
||||||
if (m_seekOnMove) {
|
|
||||||
emit seekingRequested(m_seekingPosition);
|
|
||||||
}
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
return QWidget::mouseMoveEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlaybackProgressIndicator::mouseReleaseEvent(QMouseEvent *event)
|
|
||||||
{
|
|
||||||
if (m_duration > 0) {
|
|
||||||
int seekingPosition = event->position().x() * m_duration / width();
|
|
||||||
m_seekingPosition = -1;
|
|
||||||
emit seekingRequested(seekingPosition);
|
|
||||||
}
|
|
||||||
update();
|
|
||||||
return QWidget::mouseReleaseEvent(event);
|
|
||||||
}
|
|
@ -1,58 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: 2025 Gary Wang <git@blumia.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QWidget>
|
|
||||||
#include <QMouseEvent>
|
|
||||||
#include <QStandardItemModel>
|
|
||||||
|
|
||||||
class PlaybackProgressIndicator : public QWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
Q_PROPERTY(bool seekOnMove MEMBER m_seekOnMove NOTIFY seekOnMoveChanged)
|
|
||||||
Q_PROPERTY(qint64 position MEMBER m_position NOTIFY positionChanged)
|
|
||||||
Q_PROPERTY(qint64 duration MEMBER m_duration NOTIFY durationChanged)
|
|
||||||
public:
|
|
||||||
enum Roles {
|
|
||||||
ChapterTitleRole = Qt::DisplayRole,
|
|
||||||
StartTimeMsRole = Qt::UserRole + 1,
|
|
||||||
};
|
|
||||||
|
|
||||||
explicit PlaybackProgressIndicator(QWidget *parent = nullptr);
|
|
||||||
~PlaybackProgressIndicator() = default;
|
|
||||||
|
|
||||||
void setPosition(qint64 pos);
|
|
||||||
void setDuration(qint64 dur);
|
|
||||||
void setChapters(QList<std::pair<qint64, QString>> chapters);
|
|
||||||
|
|
||||||
static QList<std::pair<qint64, QString>> tryLoadChapters(const QString & filePath);
|
|
||||||
static QList<std::pair<qint64, QString>> tryLoadSidecarChapterFile(const QString & filePath);
|
|
||||||
static QList<std::pair<qint64, QString>> tryLoadChaptersFromMetadata(const QString & filePath);
|
|
||||||
static QList<std::pair<qint64, QString>> parseCHPChapterFile(const QString & filePath);
|
|
||||||
static QList<std::pair<qint64, QString>> parsePBFChapterFile(const QString & filePath);
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void seekOnMoveChanged(bool sow);
|
|
||||||
void positionChanged(qint64 newPosition);
|
|
||||||
void durationChanged(qint64 newDuration);
|
|
||||||
void seekingRequested(qint64 position);
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void paintEvent(QPaintEvent *event) override;
|
|
||||||
void mousePressEvent(QMouseEvent *event) override;
|
|
||||||
void mouseMoveEvent(QMouseEvent *event) override;
|
|
||||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool m_seekOnMove = true;
|
|
||||||
qint64 m_position = -1;
|
|
||||||
qint64 m_seekingPosition = -1;
|
|
||||||
qint64 m_duration = -1;
|
|
||||||
QStandardItemModel m_chapterModel;
|
|
||||||
};
|
|
||||||
|
|
@ -1,253 +1,255 @@
|
|||||||
// SPDX-FileCopyrightText: 2025 Gary Wang <git@blumia.net>
|
// SPDX-FileCopyrightText: 2024 Gary Wang <git@blumia.net>
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
#include "playlistmanager.h"
|
#include "playlistmanager.h"
|
||||||
|
|
||||||
#include <QCollator>
|
#include <QCollator>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
PlaylistModel::PlaylistModel(QObject *parent)
|
PlaylistModel::PlaylistModel(QObject *parent)
|
||||||
: QAbstractListModel(parent)
|
: QAbstractListModel(parent)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PlaylistModel::~PlaylistModel()
|
PlaylistModel::~PlaylistModel()
|
||||||
= default;
|
{
|
||||||
|
|
||||||
void PlaylistModel::setPlaylist(const QList<QUrl> &urls)
|
}
|
||||||
{
|
|
||||||
beginResetModel();
|
void PlaylistModel::setPlaylist(const QList<QUrl> &urls)
|
||||||
m_playlist = urls;
|
{
|
||||||
endResetModel();
|
beginResetModel();
|
||||||
}
|
m_playlist = urls;
|
||||||
|
endResetModel();
|
||||||
QModelIndex PlaylistModel::loadPlaylist(const QList<QUrl> & urls)
|
}
|
||||||
{
|
|
||||||
if (urls.isEmpty()) return {};
|
QModelIndex PlaylistModel::loadPlaylist(const QList<QUrl> & urls)
|
||||||
if (urls.count() == 1) {
|
{
|
||||||
return loadPlaylist(urls.constFirst());
|
if (urls.isEmpty()) return QModelIndex();
|
||||||
} else {
|
if (urls.count() == 1) {
|
||||||
setPlaylist(urls);
|
return loadPlaylist(urls.constFirst());
|
||||||
return index(0);
|
} else {
|
||||||
}
|
setPlaylist(urls);
|
||||||
}
|
return index(0);
|
||||||
|
}
|
||||||
QModelIndex PlaylistModel::loadPlaylist(const QUrl &url)
|
}
|
||||||
{
|
|
||||||
QFileInfo info(url.toLocalFile());
|
QModelIndex PlaylistModel::loadPlaylist(const QUrl &url)
|
||||||
QDir dir(info.path());
|
{
|
||||||
QString && currentFileName = info.fileName();
|
QFileInfo info(url.toLocalFile());
|
||||||
|
QDir dir(info.path());
|
||||||
if (dir.path() == m_currentDir) {
|
QString && currentFileName = info.fileName();
|
||||||
int idx = indexOf(url);
|
|
||||||
return idx == -1 ? appendToPlaylist(url) : index(idx);
|
if (dir.path() == m_currentDir) {
|
||||||
}
|
int idx = indexOf(url);
|
||||||
|
return idx == -1 ? appendToPlaylist(url) : index(idx);
|
||||||
QStringList entryList = dir.entryList(
|
}
|
||||||
m_autoLoadSuffixes,
|
|
||||||
QDir::Files | QDir::NoSymLinks, QDir::NoSort);
|
QStringList entryList = dir.entryList(
|
||||||
|
m_autoLoadSuffixes,
|
||||||
QCollator collator;
|
QDir::Files | QDir::NoSymLinks, QDir::NoSort);
|
||||||
collator.setNumericMode(true);
|
|
||||||
|
QCollator collator;
|
||||||
std::sort(entryList.begin(), entryList.end(), collator);
|
collator.setNumericMode(true);
|
||||||
|
|
||||||
QList<QUrl> playlist;
|
std::sort(entryList.begin(), entryList.end(), collator);
|
||||||
|
|
||||||
int idx = -1;
|
QList<QUrl> playlist;
|
||||||
for (int i = 0; i < entryList.count(); i++) {
|
|
||||||
const QString & fileName = entryList.at(i);
|
int idx = -1;
|
||||||
const QString & oneEntry = dir.absoluteFilePath(fileName);
|
for (int i = 0; i < entryList.count(); i++) {
|
||||||
const QUrl & url = QUrl::fromLocalFile(oneEntry);
|
const QString & fileName = entryList.at(i);
|
||||||
playlist.append(url);
|
const QString & oneEntry = dir.absoluteFilePath(fileName);
|
||||||
if (fileName == currentFileName) {
|
const QUrl & url = QUrl::fromLocalFile(oneEntry);
|
||||||
idx = i;
|
playlist.append(url);
|
||||||
}
|
if (fileName == currentFileName) {
|
||||||
}
|
idx = i;
|
||||||
if (idx == -1) {
|
}
|
||||||
idx = playlist.count();
|
}
|
||||||
playlist.append(url);
|
if (idx == -1) {
|
||||||
}
|
idx = playlist.count();
|
||||||
m_currentDir = dir.path();
|
playlist.append(url);
|
||||||
|
}
|
||||||
setPlaylist(playlist);
|
m_currentDir = dir.path();
|
||||||
|
|
||||||
return index(idx);
|
setPlaylist(playlist);
|
||||||
}
|
|
||||||
|
return index(idx);
|
||||||
QModelIndex PlaylistModel::appendToPlaylist(const QUrl &url)
|
}
|
||||||
{
|
|
||||||
const int lastIndex = rowCount();
|
QModelIndex PlaylistModel::appendToPlaylist(const QUrl &url)
|
||||||
beginInsertRows(QModelIndex(), lastIndex, lastIndex);
|
{
|
||||||
m_playlist.append(url);
|
const int lastIndex = rowCount();
|
||||||
endInsertRows();
|
beginInsertRows(QModelIndex(), lastIndex, lastIndex);
|
||||||
return index(lastIndex);
|
m_playlist.append(url);
|
||||||
}
|
endInsertRows();
|
||||||
|
return index(lastIndex);
|
||||||
bool PlaylistModel::removeAt(int index)
|
}
|
||||||
{
|
|
||||||
if (index < 0 || index >= rowCount()) return false;
|
bool PlaylistModel::removeAt(int index)
|
||||||
beginRemoveRows(QModelIndex(), index, index);
|
{
|
||||||
m_playlist.removeAt(index);
|
if (index < 0 || index >= rowCount()) return false;
|
||||||
endRemoveRows();
|
beginRemoveRows(QModelIndex(), index, index);
|
||||||
return true;
|
m_playlist.removeAt(index);
|
||||||
}
|
endRemoveRows();
|
||||||
|
return true;
|
||||||
int PlaylistModel::indexOf(const QUrl &url) const
|
}
|
||||||
{
|
|
||||||
return m_playlist.indexOf(url);
|
int PlaylistModel::indexOf(const QUrl &url) const
|
||||||
}
|
{
|
||||||
|
return m_playlist.indexOf(url);
|
||||||
QUrl PlaylistModel::urlByIndex(int index) const
|
}
|
||||||
{
|
|
||||||
return m_playlist.value(index);
|
QUrl PlaylistModel::urlByIndex(int index) const
|
||||||
}
|
{
|
||||||
|
return m_playlist.value(index);
|
||||||
QStringList PlaylistModel::autoLoadFilterSuffixes() const
|
}
|
||||||
{
|
|
||||||
return m_autoLoadSuffixes;
|
QStringList PlaylistModel::autoLoadFilterSuffixes() const
|
||||||
}
|
{
|
||||||
|
return m_autoLoadSuffixes;
|
||||||
QHash<int, QByteArray> PlaylistModel::roleNames() const
|
}
|
||||||
{
|
|
||||||
QHash<int, QByteArray> result = QAbstractListModel::roleNames();
|
QHash<int, QByteArray> PlaylistModel::roleNames() const
|
||||||
result.insert(UrlRole, "url");
|
{
|
||||||
return result;
|
QHash<int, QByteArray> result = QAbstractListModel::roleNames();
|
||||||
}
|
result.insert(UrlRole, "url");
|
||||||
|
return result;
|
||||||
int PlaylistModel::rowCount(const QModelIndex &parent) const
|
}
|
||||||
{
|
|
||||||
return m_playlist.count();
|
int PlaylistModel::rowCount(const QModelIndex &parent) const
|
||||||
}
|
{
|
||||||
|
return m_playlist.count();
|
||||||
QVariant PlaylistModel::data(const QModelIndex &index, int role) const
|
}
|
||||||
{
|
|
||||||
if (!index.isValid()) return {};
|
QVariant PlaylistModel::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
switch (role) {
|
if (!index.isValid()) return QVariant();
|
||||||
case Qt::DisplayRole:
|
|
||||||
return m_playlist.at(index.row()).fileName();
|
switch (role) {
|
||||||
case UrlRole:
|
case Qt::DisplayRole:
|
||||||
return m_playlist.at(index.row());
|
return m_playlist.at(index.row()).fileName();
|
||||||
}
|
case UrlRole:
|
||||||
|
return m_playlist.at(index.row());
|
||||||
return {};
|
}
|
||||||
}
|
|
||||||
|
return QVariant();
|
||||||
PlaylistManager::PlaylistManager(QObject *parent)
|
}
|
||||||
: QObject(parent)
|
|
||||||
{
|
PlaylistManager::PlaylistManager(QObject *parent)
|
||||||
connect(&m_model, &PlaylistModel::rowsRemoved, this,
|
: QObject(parent)
|
||||||
[this](const QModelIndex &, int, int) {
|
{
|
||||||
if (m_model.rowCount() <= m_currentIndex) {
|
connect(&m_model, &PlaylistModel::rowsRemoved, this,
|
||||||
setProperty("currentIndex", m_currentIndex - 1);
|
[this](const QModelIndex &, int, int) {
|
||||||
}
|
if (m_model.rowCount() <= m_currentIndex) {
|
||||||
});
|
setProperty("currentIndex", m_currentIndex - 1);
|
||||||
|
}
|
||||||
auto onRowCountChanged = [this](){
|
});
|
||||||
emit totalCountChanged(m_model.rowCount());
|
|
||||||
};
|
auto onRowCountChanged = [this](){
|
||||||
|
emit totalCountChanged(m_model.rowCount());
|
||||||
connect(&m_model, &PlaylistModel::rowsInserted, this, onRowCountChanged);
|
};
|
||||||
connect(&m_model, &PlaylistModel::rowsRemoved, this, onRowCountChanged);
|
|
||||||
connect(&m_model, &PlaylistModel::modelReset, this, onRowCountChanged);
|
connect(&m_model, &PlaylistModel::rowsInserted, this, onRowCountChanged);
|
||||||
}
|
connect(&m_model, &PlaylistModel::rowsRemoved, this, onRowCountChanged);
|
||||||
|
connect(&m_model, &PlaylistModel::modelReset, this, onRowCountChanged);
|
||||||
PlaylistManager::~PlaylistManager()
|
}
|
||||||
{
|
|
||||||
|
PlaylistManager::~PlaylistManager()
|
||||||
}
|
{
|
||||||
|
|
||||||
PlaylistModel *PlaylistManager::model()
|
}
|
||||||
{
|
|
||||||
return &m_model;
|
PlaylistModel *PlaylistManager::model()
|
||||||
}
|
{
|
||||||
|
return &m_model;
|
||||||
void PlaylistManager::setPlaylist(const QList<QUrl> &urls)
|
}
|
||||||
{
|
|
||||||
m_model.setPlaylist(urls);
|
void PlaylistManager::setPlaylist(const QList<QUrl> &urls)
|
||||||
}
|
{
|
||||||
|
m_model.setPlaylist(urls);
|
||||||
QModelIndex PlaylistManager::loadPlaylist(const QList<QUrl> &urls)
|
}
|
||||||
{
|
|
||||||
QModelIndex idx = m_model.loadPlaylist(urls);
|
QModelIndex PlaylistManager::loadPlaylist(const QList<QUrl> &urls)
|
||||||
setProperty("currentIndex", idx.row());
|
{
|
||||||
return idx;
|
QModelIndex idx = m_model.loadPlaylist(urls);
|
||||||
}
|
setProperty("currentIndex", idx.row());
|
||||||
|
return idx;
|
||||||
QModelIndex PlaylistManager::loadPlaylist(const QUrl &url)
|
}
|
||||||
{
|
|
||||||
QModelIndex idx = m_model.loadPlaylist(url);
|
QModelIndex PlaylistManager::loadPlaylist(const QUrl &url)
|
||||||
setProperty("currentIndex", idx.row());
|
{
|
||||||
return idx;
|
QModelIndex idx = m_model.loadPlaylist(url);
|
||||||
}
|
setProperty("currentIndex", idx.row());
|
||||||
|
return idx;
|
||||||
int PlaylistManager::totalCount() const
|
}
|
||||||
{
|
|
||||||
return m_model.rowCount();
|
int PlaylistManager::totalCount() const
|
||||||
}
|
{
|
||||||
|
return m_model.rowCount();
|
||||||
QModelIndex PlaylistManager::previousIndex() const
|
}
|
||||||
{
|
|
||||||
int count = totalCount();
|
QModelIndex PlaylistManager::previousIndex() const
|
||||||
if (count == 0) return {};
|
{
|
||||||
|
int count = totalCount();
|
||||||
return m_model.index(m_currentIndex - 1 < 0 ? count - 1 : m_currentIndex - 1);
|
if (count == 0) return QModelIndex();
|
||||||
}
|
|
||||||
|
return m_model.index(m_currentIndex - 1 < 0 ? count - 1 : m_currentIndex - 1);
|
||||||
QModelIndex PlaylistManager::nextIndex() const
|
}
|
||||||
{
|
|
||||||
int count = totalCount();
|
QModelIndex PlaylistManager::nextIndex() const
|
||||||
if (count == 0) return {};
|
{
|
||||||
|
int count = totalCount();
|
||||||
return m_model.index(m_currentIndex + 1 == count ? 0 : m_currentIndex + 1);
|
if (count == 0) return QModelIndex();
|
||||||
}
|
|
||||||
|
return m_model.index(m_currentIndex + 1 == count ? 0 : m_currentIndex + 1);
|
||||||
QModelIndex PlaylistManager::curIndex() const
|
}
|
||||||
{
|
|
||||||
return m_model.index(m_currentIndex);
|
QModelIndex PlaylistManager::curIndex() const
|
||||||
}
|
{
|
||||||
|
return m_model.index(m_currentIndex);
|
||||||
void PlaylistManager::setCurrentIndex(const QModelIndex &index)
|
}
|
||||||
{
|
|
||||||
if (index.isValid() && index.row() >= 0 && index.row() < totalCount()) {
|
void PlaylistManager::setCurrentIndex(const QModelIndex &index)
|
||||||
setProperty("currentIndex", index.row());
|
{
|
||||||
}
|
if (index.isValid() && index.row() >= 0 && index.row() < totalCount()) {
|
||||||
}
|
setProperty("currentIndex", index.row());
|
||||||
|
}
|
||||||
QUrl PlaylistManager::urlByIndex(const QModelIndex &index)
|
}
|
||||||
{
|
|
||||||
return m_model.urlByIndex(index.row());
|
QUrl PlaylistManager::urlByIndex(const QModelIndex &index)
|
||||||
}
|
{
|
||||||
|
return m_model.urlByIndex(index.row());
|
||||||
QString PlaylistManager::localFileByIndex(const QModelIndex &index)
|
}
|
||||||
{
|
|
||||||
return urlByIndex(index).toLocalFile();
|
QString PlaylistManager::localFileByIndex(const QModelIndex &index)
|
||||||
}
|
{
|
||||||
|
return urlByIndex(index).toLocalFile();
|
||||||
bool PlaylistManager::removeAt(const QModelIndex &index)
|
}
|
||||||
{
|
|
||||||
return m_model.removeAt(index.row());
|
bool PlaylistManager::removeAt(const QModelIndex &index)
|
||||||
}
|
{
|
||||||
|
return m_model.removeAt(index.row());
|
||||||
void PlaylistManager::setAutoLoadFilterSuffixes(const QStringList &nameFilters)
|
}
|
||||||
{
|
|
||||||
m_model.setProperty("autoLoadFilterSuffixes", nameFilters);
|
void PlaylistManager::setAutoLoadFilterSuffixes(const QStringList &nameFilters)
|
||||||
}
|
{
|
||||||
|
m_model.setProperty("autoLoadFilterSuffixes", nameFilters);
|
||||||
QList<QUrl> PlaylistManager::convertToUrlList(const QStringList &files)
|
}
|
||||||
{
|
|
||||||
QList<QUrl> urlList;
|
QList<QUrl> PlaylistManager::convertToUrlList(const QStringList &files)
|
||||||
for (const QString & str : std::as_const(files)) {
|
{
|
||||||
QUrl url = QUrl::fromLocalFile(str);
|
QList<QUrl> urlList;
|
||||||
if (url.isValid()) {
|
for (const QString & str : std::as_const(files)) {
|
||||||
urlList.append(url);
|
QUrl url = QUrl::fromLocalFile(str);
|
||||||
}
|
if (url.isValid()) {
|
||||||
}
|
urlList.append(url);
|
||||||
|
}
|
||||||
return urlList;
|
}
|
||||||
}
|
|
||||||
|
return urlList;
|
||||||
|
}
|
||||||
|
@ -1,85 +1,85 @@
|
|||||||
// SPDX-FileCopyrightText: 2025 Gary Wang <git@blumia.net>
|
// SPDX-FileCopyrightText: 2024 Gary Wang <git@blumia.net>
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
class PlaylistModel : public QAbstractListModel
|
class PlaylistModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
enum PlaylistRole {
|
enum PlaylistRole {
|
||||||
UrlRole = Qt::UserRole
|
UrlRole = Qt::UserRole
|
||||||
};
|
};
|
||||||
Q_ENUM(PlaylistRole)
|
Q_ENUM(PlaylistRole)
|
||||||
Q_PROPERTY(QStringList autoLoadFilterSuffixes MEMBER m_autoLoadSuffixes NOTIFY autoLoadFilterSuffixesChanged)
|
Q_PROPERTY(QStringList autoLoadFilterSuffixes MEMBER m_autoLoadSuffixes NOTIFY autoLoadFilterSuffixesChanged)
|
||||||
|
|
||||||
explicit PlaylistModel(QObject *parent = nullptr);
|
explicit PlaylistModel(QObject *parent = nullptr);
|
||||||
~PlaylistModel() override;
|
~PlaylistModel();
|
||||||
|
|
||||||
void setPlaylist(const QList<QUrl> & urls);
|
void setPlaylist(const QList<QUrl> & urls);
|
||||||
QModelIndex loadPlaylist(const QList<QUrl> & urls);
|
QModelIndex loadPlaylist(const QList<QUrl> & urls);
|
||||||
QModelIndex loadPlaylist(const QUrl & url);
|
QModelIndex loadPlaylist(const QUrl & url);
|
||||||
QModelIndex appendToPlaylist(const QUrl & url);
|
QModelIndex appendToPlaylist(const QUrl & url);
|
||||||
bool removeAt(int index);
|
bool removeAt(int index);
|
||||||
int indexOf(const QUrl & url) const;
|
int indexOf(const QUrl & url) const;
|
||||||
QUrl urlByIndex(int index) const;
|
QUrl urlByIndex(int index) const;
|
||||||
QStringList autoLoadFilterSuffixes() const;
|
QStringList autoLoadFilterSuffixes() const;
|
||||||
|
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void autoLoadFilterSuffixesChanged(QStringList suffixes);
|
void autoLoadFilterSuffixesChanged(QStringList suffixes);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// model data
|
// model data
|
||||||
QList<QUrl> m_playlist;
|
QList<QUrl> m_playlist;
|
||||||
// properties
|
// properties
|
||||||
QStringList m_autoLoadSuffixes = {};
|
QStringList m_autoLoadSuffixes = {};
|
||||||
// internal
|
// internal
|
||||||
QString m_currentDir;
|
QString m_currentDir;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PlaylistManager : public QObject
|
class PlaylistManager : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
Q_PROPERTY(int currentIndex MEMBER m_currentIndex NOTIFY currentIndexChanged)
|
Q_PROPERTY(int currentIndex MEMBER m_currentIndex NOTIFY currentIndexChanged)
|
||||||
Q_PROPERTY(QStringList autoLoadFilterSuffixes WRITE setAutoLoadFilterSuffixes)
|
Q_PROPERTY(QStringList autoLoadFilterSuffixes WRITE setAutoLoadFilterSuffixes)
|
||||||
Q_PROPERTY(PlaylistModel * model READ model CONSTANT)
|
Q_PROPERTY(PlaylistModel * model READ model CONSTANT)
|
||||||
|
|
||||||
explicit PlaylistManager(QObject *parent = nullptr);
|
explicit PlaylistManager(QObject *parent = nullptr);
|
||||||
~PlaylistManager();
|
~PlaylistManager();
|
||||||
|
|
||||||
PlaylistModel * model();
|
PlaylistModel * model();
|
||||||
|
|
||||||
void setPlaylist(const QList<QUrl> & url);
|
void setPlaylist(const QList<QUrl> & url);
|
||||||
Q_INVOKABLE QModelIndex loadPlaylist(const QList<QUrl> & urls);
|
Q_INVOKABLE QModelIndex loadPlaylist(const QList<QUrl> & urls);
|
||||||
Q_INVOKABLE QModelIndex loadPlaylist(const QUrl & url);
|
Q_INVOKABLE QModelIndex loadPlaylist(const QUrl & url);
|
||||||
|
|
||||||
int totalCount() const;
|
int totalCount() const;
|
||||||
QModelIndex previousIndex() const;
|
QModelIndex previousIndex() const;
|
||||||
QModelIndex nextIndex() const;
|
QModelIndex nextIndex() const;
|
||||||
QModelIndex curIndex() const;
|
QModelIndex curIndex() const;
|
||||||
void setCurrentIndex(const QModelIndex & index);
|
void setCurrentIndex(const QModelIndex & index);
|
||||||
QUrl urlByIndex(const QModelIndex & index);
|
QUrl urlByIndex(const QModelIndex & index);
|
||||||
QString localFileByIndex(const QModelIndex & index);
|
QString localFileByIndex(const QModelIndex & index);
|
||||||
bool removeAt(const QModelIndex & index);
|
bool removeAt(const QModelIndex & index);
|
||||||
|
|
||||||
void setAutoLoadFilterSuffixes(const QStringList &nameFilters);
|
void setAutoLoadFilterSuffixes(const QStringList &nameFilters);
|
||||||
|
|
||||||
static QList<QUrl> convertToUrlList(const QStringList & files);
|
static QList<QUrl> convertToUrlList(const QStringList & files);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void currentIndexChanged(int index);
|
void currentIndexChanged(int index);
|
||||||
void totalCountChanged(int count);
|
void totalCountChanged(int count);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_currentIndex = -1;
|
int m_currentIndex = -1;
|
||||||
PlaylistModel m_model;
|
PlaylistModel m_model;
|
||||||
};
|
};
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
// SPDX-FileCopyrightText: 2025 Gary Wang <git@blumia.net>
|
// SPDX-FileCopyrightText: 2024 Gary Wang <git@blumia.net>
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QSlider>
|
#include <QSlider>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
|
||||||
class SeekableSlider : public QSlider
|
class SeekableSlider : public QSlider
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit SeekableSlider(QWidget *parent = nullptr);
|
explicit SeekableSlider(QWidget *parent = nullptr);
|
||||||
~SeekableSlider() override = default;
|
~SeekableSlider() = default;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user