diff --git a/src/Data/SongList.cpp b/src/Data/SongList.cpp index eb609ba..cb64350 100644 --- a/src/Data/SongList.cpp +++ b/src/Data/SongList.cpp @@ -69,7 +69,9 @@ namespace Data { } } - Song::Song(fs::path song_folder) { + Song::Song(fs::path song_folder) : + folder(song_folder) + { // .memon ? auto memon_files = getMemonFiles(song_folder); diff --git a/src/Data/SongList.hpp b/src/Data/SongList.hpp index e955fec..3e5c3d9 100644 --- a/src/Data/SongList.hpp +++ b/src/Data/SongList.hpp @@ -16,6 +16,7 @@ namespace Data { struct Song { Song() = default; explicit Song(fs::path song_folder); + fs::path folder; std::string title; std::string artist; // Path to the album cover diff --git a/src/Resources/Autoloader.cpp b/src/Resources/Autoloader.cpp index 8b0f212..1b36ad6 100644 --- a/src/Resources/Autoloader.cpp +++ b/src/Resources/Autoloader.cpp @@ -8,6 +8,7 @@ void Textures::Autoloader::load(const fs::path& t_path) { if (!texture->loadFromFile(t_path)) { throw std::invalid_argument("Unable to load cover image : "+t_path.string()); } + texture->setSmooth(true); m_mapping[t_path] = texture; } diff --git a/src/Screens/MusicSelect/MusicSelect.cpp b/src/Screens/MusicSelect/MusicSelect.cpp index 634a43e..fccd84a 100644 --- a/src/Screens/MusicSelect/MusicSelect.cpp +++ b/src/Screens/MusicSelect/MusicSelect.cpp @@ -26,7 +26,7 @@ MusicSelect::Screen::Screen(const Data::SongList& t_song_list) : } } */ - ribbon.test_song_cover_sort(); + ribbon.title_sort(song_list); std::cout << "loaded MusicSelect::Screen" << std::endl; } diff --git a/src/Screens/MusicSelect/Panel.cpp b/src/Screens/MusicSelect/Panel.cpp index 90fad9d..cc27b06 100644 --- a/src/Screens/MusicSelect/Panel.cpp +++ b/src/Screens/MusicSelect/Panel.cpp @@ -70,7 +70,7 @@ void MusicSelect::SongPanel::draw(Resources& resources, sf::RenderTarget& target sf::Sprite cover; sf::Texture& cover_texture = resources.fallback_cover; if (m_song.cover) { - cover_texture = *resources.covers.get(m_song.cover.value()); + cover_texture = *resources.covers.get(m_song.folder/m_song.cover.value()); } cover.setTexture(cover_texture); auto bounds = cover.getGlobalBounds(); diff --git a/utils/requirements.txt b/utils/requirements.txt new file mode 100644 index 0000000..f9d8644 --- /dev/null +++ b/utils/requirements.txt @@ -0,0 +1,3 @@ +Faker==4.0.0 +path==13.1.0 +Pillow==7.0.0 diff --git a/utils/test_songs_generator.py b/utils/test_songs_generator.py new file mode 100644 index 0000000..19a03ad --- /dev/null +++ b/utils/test_songs_generator.py @@ -0,0 +1,69 @@ +import argparse +from path import Path +from PIL import Image +import json +from faker import Faker +fake = Faker() + +parser = argparse.ArgumentParser() +parser.add_argument("input_folder", type=Path) +parser.add_argument("output_folder", type=Path) +parser.add_argument("--music-folder-mode", action="store_true", dest="music_folder_mode") +parser.add_argument("--clean", action="store_true") +parser.add_argument("--random-name", action="store_true", dest="random_name") + +args = parser.parse_args() + +def create_song_folder_from_image(image: Path): + song_name = fake.sentence().strip(".") if args.random_name else image.stem + song_folder = args.output_folder / song_name + song_folder.mkdir() + output_image = song_folder / f"{song_name}.jpg" + Image.open(str(image)).save(str(output_image)) + memon = { + "version": "0.1.0", + "metadata": { + "song title": song_name, + "artist": "", + "music path": "", + "album cover path": output_image.name, + "BPM": 120, + "offset": 0, + }, + "data": { + "BSC" : { + "level": 1, + "resolution": 4, + "notes": [] + } + } + } + json.dump( + memon, + open(song_folder/f"{song_name}.memon", "w"), + indent=4, + sort_keys=True, + ) + +if args.clean: + args.output_folder.rmtree_p() + args.output_folder.mkdir() + +def walk_music_folder(folder: Path): + for album in folder.dirs(): + yield from album.files() + +files = walk_music_folder(args.input_folder) if args.music_folder_mode else args.input_folder.files() + +for file in files: + try: + Image.open(str(file)) + except IOError as e: + print(f"{file} : {e}") + + try: + create_song_folder_from_image(file) + except Exception as e: + print(f"{file} : {e}") + + print(f"{file} : ok") \ No newline at end of file