diff options
Diffstat (limited to 'src/displayapp/screens/Music.cpp')
| -rw-r--r-- | src/displayapp/screens/Music.cpp | 58 |
1 files changed, 20 insertions, 38 deletions
diff --git a/src/displayapp/screens/Music.cpp b/src/displayapp/screens/Music.cpp index d14ae3a..1abb16a 100644 --- a/src/displayapp/screens/Music.cpp +++ b/src/displayapp/screens/Music.cpp @@ -20,9 +20,9 @@ #include <cstdint> #include "displayapp/DisplayApp.h" #include "components/ble/MusicService.h" -#include "displayapp/icons/music/disc.cpp" -#include "displayapp/icons/music/disc_f_1.cpp" -#include "displayapp/icons/music/disc_f_2.cpp" +#include "displayapp/icons/music/disc.c" +#include "displayapp/icons/music/disc_f_1.c" +#include "displayapp/icons/music/disc_f_2.c" using namespace Pinetime::Applications::Screens; @@ -53,7 +53,7 @@ Music::Music(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Mus lv_style_init(&btn_style); lv_style_set_radius(&btn_style, LV_STATE_DEFAULT, 20); lv_style_set_bg_color(&btn_style, LV_STATE_DEFAULT, LV_COLOR_AQUA); - lv_style_set_bg_opa(&btn_style, LV_STATE_DEFAULT, LV_OPA_20); + lv_style_set_bg_opa(&btn_style, LV_STATE_DEFAULT, LV_OPA_50); btnVolDown = lv_btn_create(lv_scr_act(), nullptr); btnVolDown->user_data = this; @@ -152,32 +152,24 @@ Music::~Music() { void Music::Refresh() { if (artist != musicService.getArtist()) { artist = musicService.getArtist(); - currentLength = 0; lv_label_set_text(txtArtist, artist.data()); } if (track != musicService.getTrack()) { track = musicService.getTrack(); - currentLength = 0; lv_label_set_text(txtTrack, track.data()); } if (album != musicService.getAlbum()) { album = musicService.getAlbum(); - currentLength = 0; } if (playing != musicService.isPlaying()) { playing = musicService.isPlaying(); } - // Because we increment this ourselves, - // we can't compare with the old data directly - // have to update it when there's actually new data - // just to avoid unnecessary draws that make UI choppy - if (lastLength != musicService.getProgress()) { - currentLength = musicService.getProgress(); - lastLength = currentLength; + if (currentPosition != musicService.getProgress()) { + currentPosition = musicService.getProgress(); UpdateLength(); } @@ -186,7 +178,7 @@ void Music::Refresh() { UpdateLength(); } - if (playing == Pinetime::Controllers::MusicService::MusicStatus::Playing) { + if (playing) { lv_label_set_text_static(txtPlayPause, Symbols::pause); if (xTaskGetTickCount() - 1024 >= lastIncrement) { @@ -197,18 +189,12 @@ void Music::Refresh() { } frameB = !frameB; - if (currentLength < totalLength) { - currentLength += - static_cast<int>((static_cast<float>(xTaskGetTickCount() - lastIncrement) / 1024.0f) * musicService.getPlaybackSpeed()); - } else { + if (currentPosition >= totalLength) { // Let's assume the getTrack finished, paused when the timer ends // and there's no new getTrack being sent to us - // TODO: ideally this would be configurable playing = false; } lastIncrement = xTaskGetTickCount(); - - UpdateLength(); } } else { lv_label_set_text_static(txtPlayPause, Symbols::play); @@ -219,23 +205,19 @@ void Music::UpdateLength() { if (totalLength > (99 * 60 * 60)) { lv_label_set_text_static(txtTrackDuration, "Inf/Inf"); } else if (totalLength > (99 * 60)) { - char timer[12]; - sprintf(timer, - "%02d:%02d/%02d:%02d", - (currentLength / (60 * 60)) % 100, - ((currentLength % (60 * 60)) / 60) % 100, - (totalLength / (60 * 60)) % 100, - ((totalLength % (60 * 60)) / 60) % 100); - lv_label_set_text(txtTrackDuration, timer); + lv_label_set_text_fmt(txtTrackDuration, + "%02d:%02d/%02d:%02d", + (currentPosition / (60 * 60)) % 100, + ((currentPosition % (60 * 60)) / 60) % 100, + (totalLength / (60 * 60)) % 100, + ((totalLength % (60 * 60)) / 60) % 100); } else { - char timer[12]; - sprintf(timer, - "%02d:%02d/%02d:%02d", - (currentLength / 60) % 100, - (currentLength % 60) % 100, - (totalLength / 60) % 100, - (totalLength % 60) % 100); - lv_label_set_text(txtTrackDuration, timer); + lv_label_set_text_fmt(txtTrackDuration, + "%02d:%02d/%02d:%02d", + (currentPosition / 60) % 100, + (currentPosition % 60) % 100, + (totalLength / 60) % 100, + (totalLength % 60) % 100); } } |
