From 5234599c90ca6f349dd7d3939d73a5215bc911ed Mon Sep 17 00:00:00 2001 From: hawkeyexp Date: Mon, 24 Sep 2018 12:14:27 +0200 Subject: [PATCH] Implement taglib and use in filescan / player | Extend supported media --- CMakeLists.txt | 3 + cmake_modules/Findtaglib.cmake | 70 +++++++++++++++++++ .../f1x/openauto/autoapp/UI/MainWindow.hpp | 5 ++ src/autoapp/UI/MainWindow.cpp | 69 ++++++++++++------ src/autoapp/UI/mainwindow.ui | 10 +-- 5 files changed, 132 insertions(+), 25 deletions(-) create mode 100644 cmake_modules/Findtaglib.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index fc87b2e..84039e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,7 @@ find_package(Qt5 COMPONENTS Multimedia MultimediaWidgets Bluetooth) find_package(Protobuf REQUIRED) find_package(OpenSSL REQUIRED) find_package(rtaudio REQUIRED) +find_package(taglib REQUIRED) if(WIN32) set(WINSOCK2_LIBRARIES "ws2_32") @@ -56,6 +57,7 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR} ${PROTOBUF_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR} ${RTAUDIO_INCLUDE_DIRS} + ${TAGLIB_INCLUDE_DIRS} ${AASDK_PROTO_INCLUDE_DIRS} ${AASDK_INCLUDE_DIRS} ${BCM_HOST_INCLUDE_DIRS} @@ -83,6 +85,7 @@ target_link_libraries(autoapp ${ILCLIENT_LIBRARIES} ${WINSOCK2_LIBRARIES} ${RTAUDIO_LIBRARIES} + ${TAGLIB_LIBRARIES} ${AASDK_PROTO_LIBRARIES} ${AASDK_LIBRARIES}) diff --git a/cmake_modules/Findtaglib.cmake b/cmake_modules/Findtaglib.cmake new file mode 100644 index 0000000..b74d324 --- /dev/null +++ b/cmake_modules/Findtaglib.cmake @@ -0,0 +1,70 @@ +# +# This file is part of openauto project. +# Copyright (C) 2018 f1x.studio (Michal Szwaj) +# +# openauto is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. + +# openauto is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with openauto. If not, see . +# + +if (TAGLIB_LIBRARIES AND TAGLIB_INCLUDE_DIRS) + # in cache already + set(TAGLIB_FOUND TRUE) +else (TAGLIB_LIBRARIES AND TAGLIB_INCLUDE_DIRS) + find_path(TAGLIB_INCLUDE_DIR + NAMES + taglib.h + PATHS + /usr/include + /usr/local/include + /opt/local/include + /sw/include + PATH_SUFFIXES + taglib + ) + + find_library(TAGLIB_LIBRARY + NAMES + tag taglib libtag + PATHS + /usr/lib + /usr/local/lib + /opt/local/lib + /sw/lib + ) + + set(TAGLIB_INCLUDE_DIRS + ${TAGLIB_INCLUDE_DIR} + ) + set(TAGLIB_LIBRARIES + ${TAGLIB_LIBRARY} -ltag +) + + if (TAGLIB_INCLUDE_DIRS AND TAGLIB_LIBRARIES) + set(TAGLIB_FOUND TRUE) + endif (TAGLIB_INCLUDE_DIRS AND TAGLIB_LIBRARIES) + + if (TAGLIB_FOUND) + if (NOT taglib_FIND_QUIETLY) + message(STATUS "Found taglib:") + message(STATUS " - Includes: ${TAGLIB_INCLUDE_DIRS}") + message(STATUS " - Libraries: ${TAGLIB_LIBRARIES}") + endif (NOT taglib_FIND_QUIETLY) + else (TAGLIB_FOUND) + if (taglib_FIND_REQUIRED) + message(FATAL_ERROR "Could not find taglib") + endif (taglib_FIND_REQUIRED) + endif (TAGLIB_FOUND) + + mark_as_advanced(TAGLIB_INCLUDE_DIRS TAGLIB_LIBRARIES) + +endif (TAGLIB_LIBRARIES AND TAGLIB_INCLUDE_DIRS) diff --git a/include/f1x/openauto/autoapp/UI/MainWindow.hpp b/include/f1x/openauto/autoapp/UI/MainWindow.hpp index 8595138..a37baeb 100644 --- a/include/f1x/openauto/autoapp/UI/MainWindow.hpp +++ b/include/f1x/openauto/autoapp/UI/MainWindow.hpp @@ -37,6 +37,11 @@ #include +#include +#include +#include + + namespace Ui { class MainWindow; diff --git a/src/autoapp/UI/MainWindow.cpp b/src/autoapp/UI/MainWindow.cpp index 334f724..d7c62b2 100644 --- a/src/autoapp/UI/MainWindow.cpp +++ b/src/autoapp/UI/MainWindow.cpp @@ -29,8 +29,6 @@ #include #include #include -#include -#include namespace f1x { @@ -1305,24 +1303,37 @@ void f1x::openauto::autoapp::ui::MainWindow::metaDataChanged() } else { ui_->pushButtonBack->setIcon(QPixmap("://coverlogo.png")); } - QString Title = player->metaData(QMediaMetaData::Title).toString(); - QString AlbumInterpret = player->metaData(QMediaMetaData::AlbumArtist).toString(); - if (AlbumInterpret == "" && ui_->comboBoxAlbum->currentText() != ".") { - AlbumInterpret = ui_->comboBoxAlbum->currentText(); - } - QString currentPlaying = ""; - if (AlbumInterpret != "") { - currentPlaying.append(AlbumInterpret); - } - if (Title != "" && AlbumInterpret != "") { - currentPlaying.append(" - "); - } - if (Title != "") { - currentPlaying.append(Title); - } - ui_->labelCurrentPlaying->setText(currentPlaying); + QString fullpathplaying = player->currentMedia().canonicalUrl().toString(); QString filename = QFileInfo(fullpathplaying).fileName(); + + try { + // use metadata from mp3list widget (prescanned id3 by taglib) + if (playlist->currentIndex() != -1 && fullpathplaying != "") { + QString currentsong = ui_->mp3List->item(playlist->currentIndex())->text(); + ui_->labelCurrentPlaying->setText(currentsong); + } + } catch (...) { + // use metadata from player + QString AlbumInterpret = player->metaData(QMediaMetaData::AlbumArtist).toString(); + QString Title = player->metaData(QMediaMetaData::Title).toString(); + + if (AlbumInterpret == "" && ui_->comboBoxAlbum->currentText() != ".") { + AlbumInterpret = ui_->comboBoxAlbum->currentText(); + } + QString currentPlaying; + + if (AlbumInterpret != "") { + currentPlaying.append(AlbumInterpret); + } + if (Title != "" && AlbumInterpret != "") { + currentPlaying.append(" - "); + } + if (Title != "") { + currentPlaying.append(Title); + } + ui_->labelCurrentPlaying->setText(currentPlaying); + } ui_->labelTrack->setText(QString::number(playlist->currentIndex()+1)); ui_->labelTrackCount->setText(QString::number(playlist->mediaCount())); } @@ -1379,12 +1390,30 @@ void f1x::openauto::autoapp::ui::MainWindow::scanFiles() QList content; QDir directory(this->musicfolder + "/" + this->albumfolder); - QStringList mp3s = directory.entryList(QStringList() << "*.mp3" << "*.flac" << "*.aac" << "*.ogg",QDir::Files, QDir::Name); + QStringList mp3s = directory.entryList(QStringList() << "*.mp3" << "*.flac" << "*.aac" << "*.ogg" << "*.mp4",QDir::Files, QDir::Name); foreach (QString filename, mp3s) { // add to mediacontent content.push_back(QMediaContent(QUrl::fromLocalFile(this->musicfolder + "/" + this->albumfolder + "/" + filename))); // add items to gui - ui_->mp3List->addItem(filename); + // read metadata using taglib + try { + TagLib::FileRef file((this->musicfolder + "/" + this->albumfolder + "/" + filename).toUtf8(),true); + TagLib::String artist_string = file.tag()->artist(); + TagLib::String title_string = file.tag()->title(); + TagLib::uint track_string = file.tag()->track(); + QString artistid3 = QString::fromStdWString(artist_string.toCWString()); + QString titleid3 = QString::fromStdWString(title_string.toCWString()); + QString trackid3 = QString::number(track_string); + int tracklength = trackid3.length(); + if (tracklength < 2) { + trackid3 = "0" + trackid3; + } + QString ID3Entry = trackid3 + ": " + artistid3 + " - " + titleid3; + ui_->mp3List->addItem(ID3Entry); + } catch (...) { + // old way only adding filename to list + ui_->mp3List->addItem(filename); + } } // set playlist this->playlist->addMedia(content); diff --git a/src/autoapp/UI/mainwindow.ui b/src/autoapp/UI/mainwindow.ui index 6dd1062..ad3c08c 100644 --- a/src/autoapp/UI/mainwindow.ui +++ b/src/autoapp/UI/mainwindow.ui @@ -7,7 +7,7 @@ 0 0 907 - 1291 + 1295 @@ -3006,13 +3006,13 @@ outline: none; 150 - 16 + 20 150 - 16 + 20 @@ -3035,13 +3035,13 @@ background-color: rgba(0, 0, 0, 0); 0 - 16 + 20 16777215 - 16 + 20