From 988d4194bedf34ade9911c04679af88317c39ebb Mon Sep 17 00:00:00 2001 From: Patrick Moessler Date: Mon, 22 May 2023 02:32:16 +0200 Subject: [PATCH] add random selection from starts play mode --- src/sleepywaves.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/sleepywaves.py b/src/sleepywaves.py index 89a2b7e..4c3a320 100644 --- a/src/sleepywaves.py +++ b/src/sleepywaves.py @@ -13,7 +13,7 @@ import time from dataclasses import dataclass from mfrc522.SimpleMFRC522 import SimpleMFRC522 from pydantic import BaseModel -from random import randrange +from random import choice, randrange from mpd import MPDClient import RPi.GPIO as GPIO @@ -27,7 +27,7 @@ log_levels = ( "DEBUG", ) -PlayMode = Literal["random", "sequence", "random_sequence"] +PlayMode = Literal["random", "sequence", "random_sequence", "random_start_sequence"] CONFIG_FILE_NAME = "config.json" NEW_CONFIG_FILE_PREFIX = "changeme_" @@ -169,6 +169,17 @@ class Player: track_id = randrange(0, len(self.current_title.config.tracks), 1) else: track_id = (track_id + 1) % len(self.current_title.config.tracks) + elif self.current_title.config.mode == "random_start_sequence": + if first: + if not self.current_title.config.start_times: + track_id = 0 + else: + start_name = choice( + list(self.current_title.config.start_times.keys()) + ) + track_id = self.current_title.config.tracks.index(start_name) + else: + track_id = (track_id + 1) % len(self.current_title.config.tracks) self.current_title.status.last_track = self.current_title.config.tracks[ track_id ]