From 50f30d494f9f06ad344ac0a9d64bdb9e8a5bd3eb Mon Sep 17 00:00:00 2001 From: Kevin Whitaker Date: Mon, 30 Jan 2017 00:22:03 -0500 Subject: [PATCH] filesystem support works in c++11, but needs another lib linked. Add some namespacing to make easier to transition to official filesystem lib release. Move static var in wrong place. Add first method ot handle scanning. --- CMakeLists.txt | 3 +-- src/GroovePlayer.cpp | 27 +++++++++++++++++++++++++-- src/GroovePlayer.h | 7 +++++++ 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d24443b..38cd3ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 3.1) project(arbitrateor) set(CMAKE_CXX_STANDARD 11) #Change to 17 when possible for filesystem support set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++1z") #Until then, force c++17 where we can. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") @@ -10,6 +9,6 @@ find_package(Wt REQUIRED) find_package(Groove REQUIRED) add_executable(arbitrateor src/main.cpp src/WebInterface.cpp src/GroovePlayer.cpp src/ui/LoginInterface.cpp src/ui/PlayerInterface.cpp) -target_link_libraries(arbitrateor ${Wt_LIBRARIES} ${GROOVE_LIBRARY} pthread) #TODO get threading links based on platform. +target_link_libraries(arbitrateor ${Wt_LIBRARIES} ${GROOVE_LIBRARY} pthread stdc++fs) #TODO get threading links based on platform. Remove gcc experimental fs when official c++17 exists. install(TARGETS arbitrateor RUNTIME DESTINATION bin) diff --git a/src/GroovePlayer.cpp b/src/GroovePlayer.cpp index 544f863..5783cac 100644 --- a/src/GroovePlayer.cpp +++ b/src/GroovePlayer.cpp @@ -23,7 +23,10 @@ #include #include #include "WebInterface.h" -#include //TODO:Change to non-gcc way when officially using c++17 +#include +#include + +std::filesystem::path GroovePlayer::musicScanDir = ""; GroovePlayer::GroovePlayer(std::string dbFile) : sqliteConnection(dbFile) { @@ -53,9 +56,29 @@ void GroovePlayer::grooveEventLoop() //TODO } +bool GroovePlayer::addFileToTrackDBIfTagged(std::filesystem::path file) +{ + //Now check if tags exist and put into DB. +} + + void GroovePlayer::grooveAudioScannerLoop() { - //TODO + for(std::filesystem::directory_entry p: std::filesystem::directory_iterator(musicScanDir)) + { + std::string extensionLowered; + for(auto elem : p.path().extension().string()) + { + extensionLowered.push_back(std::tolower(elem)); + } + if(extensionLowered == "mp3") //TODO:think about supporting more than mp3s. + { + if(addFileToTrackDBIfTagged(p.path())) + { + Wt::log("info") << p.path().string() << " was added to DB"; + } + } + } } diff --git a/src/GroovePlayer.h b/src/GroovePlayer.h index 831a1c8..85493e5 100644 --- a/src/GroovePlayer.h +++ b/src/GroovePlayer.h @@ -26,12 +26,18 @@ #include #include "db/User.h" #include "db/AudioTrack.h" +#include //TODO:Change to non-gcc way when officially using c++17 +namespace std { + namespace filesystem = experimental::filesystem; +} class GroovePlayer { public: + static std::filesystem::path musicScanDir; static GroovePlayer* getInstance() { static GroovePlayer instance("music.db"); + musicScanDir = std::filesystem::current_path().string()+"/music"; return &instance; }; GroovePlayer(GroovePlayer const&) = delete; @@ -47,6 +53,7 @@ private: std::vector getNextVoteBatch(); std::thread* grooveAudioScanner; static void grooveAudioScannerLoop(); + static bool addFileToTrackDBIfTagged(std::filesystem::path file); }; -- GitLab