songs are now required to have an artist. this breaks existing dbfiles!

This commit is contained in:
Mark 2023-09-11 14:23:30 +02:00
parent 6131bc50a4
commit c93b933037
6 changed files with 12 additions and 16 deletions

View File

@ -122,9 +122,7 @@ impl GuiElemTrait for CurrentSong {
let (name, subtext) = if let Some(song) = new_song { let (name, subtext) = if let Some(song) = new_song {
if let Some(song) = info.database.get_song(&song) { if let Some(song) = info.database.get_song(&song) {
let sub = match ( let sub = match (
song.artist info.database.artists().get(&song.artist),
.as_ref()
.and_then(|id| info.database.artists().get(id)),
song.album song.album
.as_ref() .as_ref()
.and_then(|id| info.database.albums().get(id)), .and_then(|id| info.database.albums().get(id)),

View File

@ -398,7 +398,7 @@ impl QueueSong {
GuiElem::new(Label::new( GuiElem::new(Label::new(
GuiElemCfg::at(Rectangle::from_tuples((sub_offset, 0.57), (1.0, 1.0))), GuiElemCfg::at(Rectangle::from_tuples((sub_offset, 0.57), (1.0, 1.0))),
match ( match (
song.artist.as_ref().and_then(|id| db.artists().get(id)), db.artists().get(&song.artist),
song.album.as_ref().and_then(|id| db.albums().get(id)), song.album.as_ref().and_then(|id| db.albums().get(id)),
) { ) {
(None, None) => String::new(), (None, None) => String::new(),

View File

@ -192,7 +192,7 @@ impl<'a> Looper<'a> {
location: self.read_line("The songs file is located, relative to the library root, at...").into(), location: self.read_line("The songs file is located, relative to the library root, at...").into(),
title: self.read_line("The songs title is..."), title: self.read_line("The songs title is..."),
album: self.read_line_ido("The song is part of the album with the id... (empty for None)"), album: self.read_line_ido("The song is part of the album with the id... (empty for None)"),
artist: self.read_line_ido("The song is made by the artist with the id... (empty for None)"), artist: self.read_line_id("The song is made by the artist with the id..."),
more_artists: accumulate(|| self.read_line_ido("The song is made with support by other artist, one of which has the id... (will ask repeatedly; leave empty once done)")), more_artists: accumulate(|| self.read_line_ido("The song is made with support by other artist, one of which has the id... (will ask repeatedly; leave empty once done)")),
cover: self.read_line_ido("The song should use the cover with the id... (empty for None - will default to album or artist cover, if available)"), cover: self.read_line_ido("The song should use the cover with the id... (empty for None - will default to album or artist cover, if available)"),
general: GeneralData::default(), general: GeneralData::default(),
@ -223,8 +223,8 @@ impl<'a> Looper<'a> {
song.album = self.read_line_ido(""); song.album = self.read_line_ido("");
} }
"artist" => { "artist" => {
println!("prev: '{}'", song.artist.map_or(String::new(), |v| v.to_string())); println!("prev: '{}'", song.artist);
song.artist = self.read_line_ido(""); song.artist = self.read_line_id("");
} }
"location" => { "location" => {
println!("prev: '{:?}'", song.location); println!("prev: '{:?}'", song.location);

View File

@ -80,7 +80,7 @@ impl Database {
if let Some(Some(album)) = album.map(|v| self.albums.get_mut(&v)) { if let Some(Some(album)) = album.map(|v| self.albums.get_mut(&v)) {
album.songs.push(id); album.songs.push(id);
} else { } else {
if let Some(Some(artist)) = artist.map(|v| self.artists.get_mut(&v)) { if let Some(artist) = self.artists.get_mut(&artist) {
artist.singles.push(id); artist.singles.push(id);
} }
} }

View File

@ -19,7 +19,7 @@ pub struct Song {
pub location: DatabaseLocation, pub location: DatabaseLocation,
pub title: String, pub title: String,
pub album: Option<AlbumId>, pub album: Option<AlbumId>,
pub artist: Option<ArtistId>, pub artist: ArtistId,
pub more_artists: Vec<ArtistId>, pub more_artists: Vec<ArtistId>,
pub cover: Option<CoverId>, pub cover: Option<CoverId>,
pub general: GeneralData, pub general: GeneralData,
@ -33,7 +33,7 @@ impl Song {
location: DatabaseLocation, location: DatabaseLocation,
title: String, title: String,
album: Option<AlbumId>, album: Option<AlbumId>,
artist: Option<ArtistId>, artist: ArtistId,
more_artists: Vec<ArtistId>, more_artists: Vec<ArtistId>,
cover: Option<CoverId>, cover: Option<CoverId>,
) -> Self { ) -> Self {
@ -165,11 +165,9 @@ impl Song {
impl Display for Song { impl Display for Song {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.title)?; write!(f, "{}", self.title)?;
match (self.artist, self.album) { match self.album {
(Some(artist), Some(album)) => write!(f, " (by {artist} on {album})")?, Some(album) => write!(f, " (by {} on {album})", self.artist)?,
(None, Some(album)) => write!(f, " (on {album})")?, None => write!(f, " (by {})", self.artist)?,
(Some(artist), None) => write!(f, " (by {artist})")?,
(None, None) => {}
} }
Ok(()) Ok(())
} }

View File

@ -7,7 +7,7 @@ use std::{
thread, thread,
}; };
use musicdb_lib::server::{run_server, Command}; use musicdb_lib::server::run_server;
use musicdb_lib::data::database::Database; use musicdb_lib::data::database::Database;