Extract queue manage function
This commit is contained in:
parent
eaccc76c29
commit
172f31223c
42
campatmo.py
42
campatmo.py
|
@ -42,32 +42,36 @@ def load_sounds(mixer):
|
||||||
return types, sounds
|
return types, sounds
|
||||||
|
|
||||||
|
|
||||||
|
def manage_type_queue(name, type_channels, sounds):
|
||||||
|
try:
|
||||||
|
next_sound_index = max(
|
||||||
|
[
|
||||||
|
sounds[name].index(tt.get_queue() or tt.get_sound())
|
||||||
|
for tt in type_channels
|
||||||
|
]
|
||||||
|
)
|
||||||
|
except ValueError:
|
||||||
|
next_sound_index = 0
|
||||||
|
if next_sound_index >= len(sounds[name]):
|
||||||
|
random.shuffle(sounds[name])
|
||||||
|
next_sound_index = 0
|
||||||
|
for c in type_channels:
|
||||||
|
if c.get_queue() is not None and len(sounds[name]) > 1:
|
||||||
|
continue
|
||||||
|
c.queue(sounds[name][next_sound_index])
|
||||||
|
if c.get_queue() is None and len(sounds[name]) > 1:
|
||||||
|
c.queue(sounds[name][next_sound_index + 1])
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
mixer.init(frequency=22050 * 2)
|
mixer.init(frequency=22050 * 2)
|
||||||
types, sounds = load_sounds(mixer)
|
types, sounds = load_sounds(mixer)
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
for name, type_ in types.items():
|
for name, type_channels in types.items():
|
||||||
if len(sounds[name]) == 0:
|
if len(sounds[name]) == 0:
|
||||||
continue
|
continue
|
||||||
try:
|
manage_type_queue(name, type_channels, sounds)
|
||||||
next_sound_index = max(
|
|
||||||
[
|
|
||||||
sounds[name].index(tt.get_queue() or tt.get_sound())
|
|
||||||
for tt in type_
|
|
||||||
]
|
|
||||||
)
|
|
||||||
except ValueError:
|
|
||||||
next_sound_index = 0
|
|
||||||
if next_sound_index >= len(sounds[name]):
|
|
||||||
random.shuffle(sounds[name])
|
|
||||||
next_sound_index = 0
|
|
||||||
for c in type_:
|
|
||||||
if c.get_queue() is not None and len(sounds[name]) > 1:
|
|
||||||
continue
|
|
||||||
c.queue(sounds[name][next_sound_index])
|
|
||||||
if c.get_queue() is None and len(sounds[name]) > 1:
|
|
||||||
c.queue(sounds[name][next_sound_index + 1])
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
types, sounds = load_sounds(mixer)
|
types, sounds = load_sounds(mixer)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
|
Loading…
Reference in New Issue