Impl album display
This commit is contained in:
parent
dda5b15aa4
commit
95e4a75eed
3 changed files with 86 additions and 7 deletions
|
@ -22,6 +22,7 @@ const TEXT_X_OFFSET: f32 = 0.3;
|
||||||
const TEXT_OFFSET_Y_SPACING: f32 = 0.4;
|
const TEXT_OFFSET_Y_SPACING: f32 = 0.4;
|
||||||
const TEXT_HEIGHT_SCALE: f32 = 0.1;
|
const TEXT_HEIGHT_SCALE: f32 = 0.1;
|
||||||
const ARTIST_HEIGHT_SCALE: f32 = 0.08;
|
const ARTIST_HEIGHT_SCALE: f32 = 0.08;
|
||||||
|
const ALBUM_HEIGHT_SCALE: f32 = 0.08;
|
||||||
const TIMER_HEIGHT_SCALE: f32 = 0.07;
|
const TIMER_HEIGHT_SCALE: f32 = 0.07;
|
||||||
const MIN_WIDTH_RATIO: f32 = 4.0 / 5.0;
|
const MIN_WIDTH_RATIO: f32 = 4.0 / 5.0;
|
||||||
const INCREASE_AMT: f32 = 6.0 / 5.0;
|
const INCREASE_AMT: f32 = 6.0 / 5.0;
|
||||||
|
@ -198,6 +199,9 @@ pub struct MPDDisplay {
|
||||||
title_text: Text,
|
title_text: Text,
|
||||||
title_string_cache: String,
|
title_string_cache: String,
|
||||||
title_transform: Transform,
|
title_transform: Transform,
|
||||||
|
album_text: Text,
|
||||||
|
album_string_cache: String,
|
||||||
|
album_transform: Transform,
|
||||||
timer_text: Text,
|
timer_text: Text,
|
||||||
timer_transform: Transform,
|
timer_transform: Transform,
|
||||||
timer_x: f32,
|
timer_x: f32,
|
||||||
|
@ -219,18 +223,18 @@ impl MPDDisplay {
|
||||||
is_valid: true,
|
is_valid: true,
|
||||||
is_initialized: false,
|
is_initialized: false,
|
||||||
is_authenticated: false,
|
is_authenticated: false,
|
||||||
notice_text: Text::new(""),
|
notice_text: Text::default(),
|
||||||
poll_instant: Instant::now() - POLL_TIME,
|
poll_instant: Instant::now() - POLL_TIME,
|
||||||
shared: None,
|
shared: None,
|
||||||
password_entered: false,
|
password_entered: false,
|
||||||
dirty_flag: None,
|
dirty_flag: None,
|
||||||
album_art: None,
|
album_art: None,
|
||||||
album_art_draw_transform: None,
|
album_art_draw_transform: None,
|
||||||
filename_text: Text::new(""),
|
filename_text: Text::default(),
|
||||||
filename_transform: Transform::default(),
|
filename_transform: Transform::default(),
|
||||||
artist_text: Text::new(""),
|
artist_text: Text::default(),
|
||||||
artist_transform: Transform::default(),
|
artist_transform: Transform::default(),
|
||||||
title_text: Text::new(""),
|
title_text: Text::default(),
|
||||||
title_transform: Transform::default(),
|
title_transform: Transform::default(),
|
||||||
timer_text: Text::new("0"),
|
timer_text: Text::new("0"),
|
||||||
timer_transform: Transform::default(),
|
timer_transform: Transform::default(),
|
||||||
|
@ -246,6 +250,9 @@ impl MPDDisplay {
|
||||||
filename_string_cache: String::new(),
|
filename_string_cache: String::new(),
|
||||||
artist_string_cache: String::new(),
|
artist_string_cache: String::new(),
|
||||||
title_string_cache: String::new(),
|
title_string_cache: String::new(),
|
||||||
|
album_text: Text::default(),
|
||||||
|
album_string_cache: String::new(),
|
||||||
|
album_transform: Transform::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,12 +427,14 @@ impl MPDDisplay {
|
||||||
let screen_coords: Rect = graphics::screen_coordinates(ctx);
|
let screen_coords: Rect = graphics::screen_coordinates(ctx);
|
||||||
|
|
||||||
let text_height_limit = TEXT_HEIGHT_SCALE * screen_coords.h.abs();
|
let text_height_limit = TEXT_HEIGHT_SCALE * screen_coords.h.abs();
|
||||||
|
let album_height_limit = ALBUM_HEIGHT_SCALE * screen_coords.h.abs();
|
||||||
let artist_height_limit = ARTIST_HEIGHT_SCALE * screen_coords.h.abs();
|
let artist_height_limit = ARTIST_HEIGHT_SCALE * screen_coords.h.abs();
|
||||||
let timer_height = TIMER_HEIGHT_SCALE * screen_coords.h.abs();
|
let timer_height = TIMER_HEIGHT_SCALE * screen_coords.h.abs();
|
||||||
|
|
||||||
let mut offset_y: f32 = screen_coords.h;
|
let mut offset_y: f32 = screen_coords.h;
|
||||||
|
|
||||||
let mut filename_y: f32 = 0.0;
|
let mut filename_y: f32 = 0.0;
|
||||||
|
let mut album_y: f32 = 0.0;
|
||||||
let mut artist_y: f32 = 0.0;
|
let mut artist_y: f32 = 0.0;
|
||||||
let mut title_y: f32 = 0.0;
|
let mut title_y: f32 = 0.0;
|
||||||
let mut timer_y: f32 = 0.0;
|
let mut timer_y: f32 = 0.0;
|
||||||
|
@ -436,6 +445,7 @@ impl MPDDisplay {
|
||||||
y: &mut f32,
|
y: &mut f32,
|
||||||
is_string: bool,
|
is_string: bool,
|
||||||
is_artist: bool,
|
is_artist: bool,
|
||||||
|
is_album: bool,
|
||||||
timer_x: &mut f32,
|
timer_x: &mut f32,
|
||||||
timer_y: &mut f32| {
|
timer_y: &mut f32| {
|
||||||
let mut current_x = INIT_FONT_SIZE_X;
|
let mut current_x = INIT_FONT_SIZE_X;
|
||||||
|
@ -463,6 +473,8 @@ impl MPDDisplay {
|
||||||
|| height
|
|| height
|
||||||
>= (if is_artist {
|
>= (if is_artist {
|
||||||
artist_height_limit
|
artist_height_limit
|
||||||
|
} else if is_album {
|
||||||
|
album_height_limit
|
||||||
} else {
|
} else {
|
||||||
text_height_limit
|
text_height_limit
|
||||||
})
|
})
|
||||||
|
@ -513,6 +525,7 @@ impl MPDDisplay {
|
||||||
&mut filename_y,
|
&mut filename_y,
|
||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
|
false,
|
||||||
&mut self.timer_x,
|
&mut self.timer_x,
|
||||||
&mut self.timer_y,
|
&mut self.timer_y,
|
||||||
);
|
);
|
||||||
|
@ -524,6 +537,20 @@ impl MPDDisplay {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !self.album_text.contents().is_empty() && !self.opts.disable_show_album {
|
||||||
|
set_transform(
|
||||||
|
&mut self.album_text,
|
||||||
|
&mut self.album_transform,
|
||||||
|
&mut offset_y,
|
||||||
|
&mut album_y,
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
&mut self.timer_x,
|
||||||
|
&mut self.timer_y,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if !self.artist_text.contents().is_empty() && !self.opts.disable_show_artist {
|
if !self.artist_text.contents().is_empty() && !self.opts.disable_show_artist {
|
||||||
set_transform(
|
set_transform(
|
||||||
&mut self.artist_text,
|
&mut self.artist_text,
|
||||||
|
@ -532,6 +559,7 @@ impl MPDDisplay {
|
||||||
&mut artist_y,
|
&mut artist_y,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
|
false,
|
||||||
&mut self.timer_x,
|
&mut self.timer_x,
|
||||||
&mut self.timer_y,
|
&mut self.timer_y,
|
||||||
);
|
);
|
||||||
|
@ -551,6 +579,7 @@ impl MPDDisplay {
|
||||||
&mut title_y,
|
&mut title_y,
|
||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
|
false,
|
||||||
&mut self.timer_x,
|
&mut self.timer_x,
|
||||||
&mut self.timer_y,
|
&mut self.timer_y,
|
||||||
);
|
);
|
||||||
|
@ -569,11 +598,13 @@ impl MPDDisplay {
|
||||||
&mut timer_y,
|
&mut timer_y,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
false,
|
||||||
&mut self.timer_x,
|
&mut self.timer_x,
|
||||||
&mut self.timer_y,
|
&mut self.timer_y,
|
||||||
);
|
);
|
||||||
|
|
||||||
let filename_dimensions = self.filename_text.dimensions(ctx);
|
let filename_dimensions = self.filename_text.dimensions(ctx);
|
||||||
|
let album_dimensions = self.album_text.dimensions(ctx);
|
||||||
let artist_dimensions = self.artist_text.dimensions(ctx);
|
let artist_dimensions = self.artist_text.dimensions(ctx);
|
||||||
let title_dimensions = self.title_text.dimensions(ctx);
|
let title_dimensions = self.title_text.dimensions(ctx);
|
||||||
let timer_dimensions = self.timer_text.dimensions(ctx);
|
let timer_dimensions = self.timer_text.dimensions(ctx);
|
||||||
|
@ -591,6 +622,18 @@ impl MPDDisplay {
|
||||||
Color::from_rgba(0, 0, 0, 160),
|
Color::from_rgba(0, 0, 0, 160),
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
if !self.opts.disable_show_album {
|
||||||
|
mesh_builder.rectangle(
|
||||||
|
DrawMode::fill(),
|
||||||
|
Rect {
|
||||||
|
x: TEXT_X_OFFSET,
|
||||||
|
y: album_y,
|
||||||
|
w: album_dimensions.w,
|
||||||
|
h: album_dimensions.h,
|
||||||
|
},
|
||||||
|
Color::from_rgba(0, 0, 0, 160),
|
||||||
|
)?;
|
||||||
|
}
|
||||||
if !self.opts.disable_show_artist {
|
if !self.opts.disable_show_artist {
|
||||||
mesh_builder.rectangle(
|
mesh_builder.rectangle(
|
||||||
DrawMode::fill(),
|
DrawMode::fill(),
|
||||||
|
@ -722,9 +765,10 @@ impl EventHandler for MPDDisplay {
|
||||||
}
|
}
|
||||||
if shared.mpd_play_state != MPDPlayState::Playing {
|
if shared.mpd_play_state != MPDPlayState::Playing {
|
||||||
if shared.mpd_play_state == MPDPlayState::Stopped {
|
if shared.mpd_play_state == MPDPlayState::Stopped {
|
||||||
self.title_text = Text::new("");
|
self.title_text = Text::default();
|
||||||
self.artist_text = Text::new("");
|
self.artist_text = Text::default();
|
||||||
self.filename_text = Text::new("");
|
self.album_text = Text::default();
|
||||||
|
self.filename_text = Text::default();
|
||||||
self.timer = 0.0;
|
self.timer = 0.0;
|
||||||
self.length = 0.0;
|
self.length = 0.0;
|
||||||
self.album_art = None;
|
self.album_art = None;
|
||||||
|
@ -767,6 +811,21 @@ impl EventHandler for MPDDisplay {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.store(true, Ordering::Relaxed);
|
.store(true, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
|
if !shared.album.is_empty() {
|
||||||
|
if shared.album != self.album_string_cache {
|
||||||
|
self.album_string_cache = shared.album.clone();
|
||||||
|
self.album_text = string_to_text(
|
||||||
|
shared.album.clone(),
|
||||||
|
&mut self.loaded_fonts,
|
||||||
|
ctx,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.dirty_flag
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.store(true, Ordering::Relaxed);
|
||||||
|
}
|
||||||
if !shared.filename.is_empty() {
|
if !shared.filename.is_empty() {
|
||||||
if shared.filename != self.filename_string_cache {
|
if shared.filename != self.filename_string_cache {
|
||||||
self.filename_string_cache = shared.filename.clone();
|
self.filename_string_cache = shared.filename.clone();
|
||||||
|
@ -860,6 +919,16 @@ impl EventHandler for MPDDisplay {
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !self.opts.disable_show_album {
|
||||||
|
self.album_text.draw(
|
||||||
|
ctx,
|
||||||
|
DrawParam {
|
||||||
|
trans: self.album_transform,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
|
||||||
if !self.opts.disable_show_artist {
|
if !self.opts.disable_show_artist {
|
||||||
self.artist_text.draw(
|
self.artist_text.draw(
|
||||||
ctx,
|
ctx,
|
||||||
|
|
|
@ -30,6 +30,8 @@ pub struct Opt {
|
||||||
disable_show_title: bool,
|
disable_show_title: bool,
|
||||||
#[structopt(long = "disable-show-artist", help = "disable artist display")]
|
#[structopt(long = "disable-show-artist", help = "disable artist display")]
|
||||||
disable_show_artist: bool,
|
disable_show_artist: bool,
|
||||||
|
#[structopt(long = "disable-show-album", help = "disable album display")]
|
||||||
|
disable_show_album: bool,
|
||||||
#[structopt(long = "disable-show-filename", help = "disable filename display")]
|
#[structopt(long = "disable-show-filename", help = "disable filename display")]
|
||||||
disable_show_filename: bool,
|
disable_show_filename: bool,
|
||||||
#[structopt(long = "pprompt", help = "input password via prompt")]
|
#[structopt(long = "pprompt", help = "input password via prompt")]
|
||||||
|
|
|
@ -34,6 +34,7 @@ pub struct InfoFromShared {
|
||||||
pub filename: String,
|
pub filename: String,
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub artist: String,
|
pub artist: String,
|
||||||
|
pub album: String,
|
||||||
pub length: f64,
|
pub length: f64,
|
||||||
pub pos: f64,
|
pub pos: f64,
|
||||||
pub error_text: String,
|
pub error_text: String,
|
||||||
|
@ -54,6 +55,7 @@ pub struct MPDHandlerState {
|
||||||
current_song_filename: String,
|
current_song_filename: String,
|
||||||
current_song_title: String,
|
current_song_title: String,
|
||||||
current_song_artist: String,
|
current_song_artist: String,
|
||||||
|
current_song_album: String,
|
||||||
current_song_length: f64,
|
current_song_length: f64,
|
||||||
current_song_position: f64,
|
current_song_position: f64,
|
||||||
current_binary_size: usize,
|
current_binary_size: usize,
|
||||||
|
@ -280,6 +282,7 @@ impl MPDHandler {
|
||||||
stop_flag: Arc::new(AtomicBool::new(false)),
|
stop_flag: Arc::new(AtomicBool::new(false)),
|
||||||
log_level,
|
log_level,
|
||||||
mpd_play_state: MPDPlayState::Stopped,
|
mpd_play_state: MPDPlayState::Stopped,
|
||||||
|
current_song_album: String::new(),
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -304,6 +307,7 @@ impl MPDHandler {
|
||||||
filename: read_lock.current_song_filename.clone(),
|
filename: read_lock.current_song_filename.clone(),
|
||||||
title: read_lock.current_song_title.clone(),
|
title: read_lock.current_song_title.clone(),
|
||||||
artist: read_lock.current_song_artist.clone(),
|
artist: read_lock.current_song_artist.clone(),
|
||||||
|
album: read_lock.current_song_album.clone(),
|
||||||
length: read_lock.current_song_length,
|
length: read_lock.current_song_length,
|
||||||
pos: read_lock.current_song_position
|
pos: read_lock.current_song_position
|
||||||
+ read_lock.song_pos_get_time.elapsed().as_secs_f64(),
|
+ read_lock.song_pos_get_time.elapsed().as_secs_f64(),
|
||||||
|
@ -632,6 +636,7 @@ impl MPDHandler {
|
||||||
write_handle.can_get_album_art_in_dir = true;
|
write_handle.can_get_album_art_in_dir = true;
|
||||||
write_handle.current_song_title.clear();
|
write_handle.current_song_title.clear();
|
||||||
write_handle.current_song_artist.clear();
|
write_handle.current_song_artist.clear();
|
||||||
|
write_handle.current_song_album.clear();
|
||||||
write_handle.current_song_length = 0.0;
|
write_handle.current_song_length = 0.0;
|
||||||
write_handle.current_song_position = 0.0;
|
write_handle.current_song_position = 0.0;
|
||||||
write_handle.did_check_overtime = false;
|
write_handle.did_check_overtime = false;
|
||||||
|
@ -663,6 +668,7 @@ impl MPDHandler {
|
||||||
write_handle.can_get_album_art_in_dir = true;
|
write_handle.can_get_album_art_in_dir = true;
|
||||||
write_handle.current_song_title.clear();
|
write_handle.current_song_title.clear();
|
||||||
write_handle.current_song_artist.clear();
|
write_handle.current_song_artist.clear();
|
||||||
|
write_handle.current_song_album.clear();
|
||||||
write_handle.current_song_length = 0.0;
|
write_handle.current_song_length = 0.0;
|
||||||
write_handle.current_song_position = 0.0;
|
write_handle.current_song_position = 0.0;
|
||||||
write_handle.did_check_overtime = false;
|
write_handle.did_check_overtime = false;
|
||||||
|
@ -724,6 +730,8 @@ impl MPDHandler {
|
||||||
write_handle.current_song_title = line.split_off(7);
|
write_handle.current_song_title = line.split_off(7);
|
||||||
} else if line.starts_with("Artist: ") {
|
} else if line.starts_with("Artist: ") {
|
||||||
write_handle.current_song_artist = line.split_off(8);
|
write_handle.current_song_artist = line.split_off(8);
|
||||||
|
} else if line.starts_with("Album: ") {
|
||||||
|
write_handle.current_song_album = line.split_off(7);
|
||||||
} else if line.starts_with("type: ") {
|
} else if line.starts_with("type: ") {
|
||||||
write_handle.art_data_type = line.split_off(6);
|
write_handle.art_data_type = line.split_off(6);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue