add random selection from starts play mode

This commit is contained in:
Patrick Moessler 2023-05-22 02:32:16 +02:00
parent 1c5113b74a
commit 988d4194be

View file

@ -13,7 +13,7 @@ import time
from dataclasses import dataclass from dataclasses import dataclass
from mfrc522.SimpleMFRC522 import SimpleMFRC522 from mfrc522.SimpleMFRC522 import SimpleMFRC522
from pydantic import BaseModel from pydantic import BaseModel
from random import randrange from random import choice, randrange
from mpd import MPDClient from mpd import MPDClient
import RPi.GPIO as GPIO import RPi.GPIO as GPIO
@ -27,7 +27,7 @@ log_levels = (
"DEBUG", "DEBUG",
) )
PlayMode = Literal["random", "sequence", "random_sequence"] PlayMode = Literal["random", "sequence", "random_sequence", "random_start_sequence"]
CONFIG_FILE_NAME = "config.json" CONFIG_FILE_NAME = "config.json"
NEW_CONFIG_FILE_PREFIX = "changeme_" NEW_CONFIG_FILE_PREFIX = "changeme_"
@ -169,6 +169,17 @@ class Player:
track_id = randrange(0, len(self.current_title.config.tracks), 1) track_id = randrange(0, len(self.current_title.config.tracks), 1)
else: else:
track_id = (track_id + 1) % len(self.current_title.config.tracks) 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[ self.current_title.status.last_track = self.current_title.config.tracks[
track_id track_id
] ]