Fixed advent mode and persistence stuff.

This commit is contained in:
Fabian Schlenz 2019-11-29 21:20:19 +01:00
parent 4eef69516e
commit 51bef05465
3 changed files with 48 additions and 35 deletions

View File

@ -142,7 +142,8 @@ void Controller::_check_rfid() {
if (time.tm_mon == 11) { // tm_mon is "months since january", so 11 means december. if (time.tm_mon == 11) { // tm_mon is "months since january", so 11 means december.
pl->advent_shuffle(time.tm_mday); pl->advent_shuffle(time.tm_mday);
} else { } else {
// TODO DEBUG("Album is in advent mode, but it isn't december (yet). Not playing.\n");
return;
} }
} else if (data.indexOf("[random]") != -1 && pl->is_fresh()) { } else if (data.indexOf("[random]") != -1 && pl->is_fresh()) {
pl->shuffle(); pl->shuffle();

View File

@ -317,12 +317,19 @@ void Playlist::shuffle(uint8_t random_offset) {
} }
void Playlist::advent_shuffle(uint8_t day) { void Playlist::advent_shuffle(uint8_t day) {
if (day > 24) day = 24; TRACE("advent_shuffle running...\n");
// Not enough songs till the current day? Play all songs in the default order.
if (day > _files.size()) {
return;
}
// We are in the "different playlist every day" mode. So we don't persist it in order to not miss changes.
persistence = PERSIST_NONE;
if (day > _files.size()) return;
_files.insert(_files.begin(), _files[day - 1]); _files.insert(_files.begin(), _files[day - 1]);
_files.erase(_files.begin() + day - 1, _files.end()); _files.erase(_files.begin() + day, _files.end());
} }
void Playlist::reset() { void Playlist::reset() {

View File

@ -109,7 +109,6 @@ Playlist* PlaylistManager::get_playlist_for_folder(String folder) {
p = new Playlist(folder); p = new Playlist(folder);
_playlists[folder] = p; _playlists[folder] = p;
if (p->persistence == PERSIST_PERMANENTLY) { if (p->persistence == PERSIST_PERMANENTLY) {
// TODO Load persistence from file
String search = folder; String search = folder;
search += "="; search += "=";
SPIMaster::select_sd(); SPIMaster::select_sd();
@ -197,7 +196,10 @@ String PlaylistManager::create_mapping_txt() {
} }
void PlaylistManager::persist(Playlist* p) { void PlaylistManager::persist(Playlist* p) {
if (p->persistence != PERSIST_PERMANENTLY) return; if (p->persistence == PERSIST_NONE) {
_playlists.erase(p->path());
return;
} else if (p->persistence == PERSIST_PERMANENTLY) {
String search = p->path(); String search = p->path();
search += '='; search += '=';
@ -231,4 +233,7 @@ void PlaylistManager::persist(Playlist* p) {
dst.println(p->get_position()); dst.println(p->get_position());
dst.close(); dst.close();
SPIMaster::select_sd(false); SPIMaster::select_sd(false);
_playlists.erase(p->path());
}
} }