Working song cover loading on music select screen ?
This commit is contained in:
parent
0065bd276e
commit
df3dda88f3
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
3
utils/requirements.txt
Normal file
3
utils/requirements.txt
Normal file
@ -0,0 +1,3 @@
|
||||
Faker==4.0.0
|
||||
path==13.1.0
|
||||
Pillow==7.0.0
|
69
utils/test_songs_generator.py
Normal file
69
utils/test_songs_generator.py
Normal file
@ -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")
|
Loading…
Reference in New Issue
Block a user