resolve pylint diagnostics
This commit is contained in:
parent
3c828cb669
commit
cd231d5aed
1 changed files with 30 additions and 37 deletions
|
|
@ -9,6 +9,7 @@ import random
|
||||||
import board
|
import board
|
||||||
import keypad
|
import keypad
|
||||||
import audiobusio
|
import audiobusio
|
||||||
|
import audiocore
|
||||||
import audiomp3
|
import audiomp3
|
||||||
import audiomixer
|
import audiomixer
|
||||||
|
|
||||||
|
|
@ -38,11 +39,6 @@ audiodev = audiobusio.I2SOut(
|
||||||
# without "opening" a "file"!
|
# without "opening" a "file"!
|
||||||
EMPTY_MP3_BYTES = b"\xff\xe3"
|
EMPTY_MP3_BYTES = b"\xff\xe3"
|
||||||
|
|
||||||
# THis is actually a valid but very short mp3 file, use it in case the core
|
|
||||||
# changes and becomes more picky
|
|
||||||
# EMPTY_MP3_BYTES = b'\xff\xe3\x18\xc4\x00\x00\x00\x03H\x00\x00\x00\x00CIRCUITPYUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU\xff\xe3\x18\xc4;\x00\x00\x03H\x00\x00\x00\x00UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU\xff\xe3\x18\xc4v\x00\x00\x03H\x00\x00\x00\x00UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU'
|
|
||||||
|
|
||||||
|
|
||||||
def exists(p):
|
def exists(p):
|
||||||
try:
|
try:
|
||||||
os.stat(p)
|
os.stat(p)
|
||||||
|
|
@ -60,10 +56,10 @@ def random_choice(seq):
|
||||||
# stop any audio (it's already stopped) but it DOES mark the voice & decoder as
|
# stop any audio (it's already stopped) but it DOES mark the voice & decoder as
|
||||||
# available. Otherwise, we might needlessly stop some other sample.
|
# available. Otherwise, we might needlessly stop some other sample.
|
||||||
def free_stopped_channels():
|
def free_stopped_channels():
|
||||||
for trigger in triggers:
|
for i in triggers:
|
||||||
if trigger._voice and not trigger.playing:
|
if i.voice and not i.playing:
|
||||||
print("fst")
|
print("fst")
|
||||||
trigger.force_off()
|
i.force_off()
|
||||||
|
|
||||||
|
|
||||||
# iterating on reversed triggers gives priority to **lower** numbered triggers
|
# iterating on reversed triggers gives priority to **lower** numbered triggers
|
||||||
|
|
@ -71,8 +67,8 @@ def ensure_available_decoder():
|
||||||
if available_decoders:
|
if available_decoders:
|
||||||
return available_decoders.popleft()
|
return available_decoders.popleft()
|
||||||
|
|
||||||
for trigger in reversed_triggers:
|
for i in reversed_triggers:
|
||||||
trigger.force_off()
|
i.force_off()
|
||||||
if available_decoders:
|
if available_decoders:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
@ -83,8 +79,8 @@ def ensure_available_voice():
|
||||||
if available_voices:
|
if available_voices:
|
||||||
return available_voices.popleft()
|
return available_voices.popleft()
|
||||||
|
|
||||||
for trigger in reversed_triggers:
|
for i in reversed_triggers:
|
||||||
trigger.force_off()
|
i.force_off()
|
||||||
if available_voices:
|
if available_voices:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
@ -94,8 +90,8 @@ def ensure_available_voice():
|
||||||
class TriggerBase:
|
class TriggerBase:
|
||||||
def __init__(self, prefix):
|
def __init__(self, prefix):
|
||||||
self._decoder = None
|
self._decoder = None
|
||||||
self._voice = None
|
self.voice = None
|
||||||
self._filenames = list(self._gather_filenames(prefix))
|
self.filenames = list(self._gather_filenames(prefix))
|
||||||
|
|
||||||
def _gather_filenames(self, prefix):
|
def _gather_filenames(self, prefix):
|
||||||
for stem in self.stems:
|
for stem in self.stems:
|
||||||
|
|
@ -108,7 +104,7 @@ class TriggerBase:
|
||||||
yield name_wav
|
yield name_wav
|
||||||
continue
|
continue
|
||||||
|
|
||||||
def _get_sample(self, path):
|
def get_sample(self, path):
|
||||||
if path.endswith(".mp3"):
|
if path.endswith(".mp3"):
|
||||||
self._decoder = ensure_available_decoder()
|
self._decoder = ensure_available_decoder()
|
||||||
self._decoder.open(path)
|
self._decoder.open(path)
|
||||||
|
|
@ -119,16 +115,16 @@ class TriggerBase:
|
||||||
def play(self, path, loop=False):
|
def play(self, path, loop=False):
|
||||||
self.force_off()
|
self.force_off()
|
||||||
free_stopped_channels()
|
free_stopped_channels()
|
||||||
sample = self._get_sample(path)
|
sample = self.get_sample(path)
|
||||||
self._voice = ensure_available_voice()
|
self.voice = ensure_available_voice()
|
||||||
self._voice.play(sample, loop=loop)
|
self.voice.play(sample, loop=loop)
|
||||||
|
|
||||||
def force_off(self):
|
def force_off(self):
|
||||||
print("force off", self)
|
print("force off", self)
|
||||||
voice = self._voice
|
voice = self.voice
|
||||||
if voice is not None:
|
if voice is not None:
|
||||||
print(f"return voice {id(voice)}")
|
print(f"return voice {id(voice)}")
|
||||||
self._voice = None
|
self.voice = None
|
||||||
voice.stop()
|
voice.stop()
|
||||||
available_voices.append(voice)
|
available_voices.append(voice)
|
||||||
decoder = self._decoder
|
decoder = self._decoder
|
||||||
|
|
@ -141,7 +137,7 @@ class TriggerBase:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def playing(self):
|
def playing(self):
|
||||||
return False if self._voice is None else self._voice.playing
|
return False if self.voice is None else self.voice.playing
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def matches(cls, prefix):
|
def matches(cls, prefix):
|
||||||
|
|
@ -151,7 +147,7 @@ class TriggerBase:
|
||||||
return exists(name_wav) or exists(name_mp3)
|
return exists(name_wav) or exists(name_mp3)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<{self.__class__.__name__} {self._filenames}{' playing' if self.playing else ''}>"
|
return f"<{self.__class__.__name__} {self.filenames}{' playing' if self.playing else ''}>"
|
||||||
|
|
||||||
|
|
||||||
class NopTrigger(TriggerBase):
|
class NopTrigger(TriggerBase):
|
||||||
|
|
@ -172,7 +168,7 @@ class BasicTrigger(TriggerBase):
|
||||||
stems = [""]
|
stems = [""]
|
||||||
|
|
||||||
def on_press(self):
|
def on_press(self):
|
||||||
self.play(self._filenames[0])
|
self.play(self.filenames[0])
|
||||||
|
|
||||||
def on_release(self):
|
def on_release(self):
|
||||||
pass
|
pass
|
||||||
|
|
@ -184,7 +180,7 @@ class HoldLoopingTrigger(TriggerBase):
|
||||||
stems = ["HOLDL"]
|
stems = ["HOLDL"]
|
||||||
|
|
||||||
def on_press(self):
|
def on_press(self):
|
||||||
self.play(self._filenames[0], loop=True)
|
self.play(self.filenames[0], loop=True)
|
||||||
|
|
||||||
def on_release(self):
|
def on_release(self):
|
||||||
self.force_off()
|
self.force_off()
|
||||||
|
|
@ -199,7 +195,7 @@ class LatchingLoopTrigger(TriggerBase):
|
||||||
if self.playing:
|
if self.playing:
|
||||||
self.force_off()
|
self.force_off()
|
||||||
else:
|
else:
|
||||||
self.play(self._filenames[0], loop=True)
|
self.play(self.filenames[0], loop=True)
|
||||||
|
|
||||||
def on_release(self):
|
def on_release(self):
|
||||||
pass
|
pass
|
||||||
|
|
@ -213,8 +209,8 @@ class PlayNextTrigger(TriggerBase):
|
||||||
self._phase = 0
|
self._phase = 0
|
||||||
|
|
||||||
def on_press(self):
|
def on_press(self):
|
||||||
self.play(self._filenames[self._phase])
|
self.play(self.filenames[self._phase])
|
||||||
self._phase = (self._phase + 1) % len(self._filenames)
|
self._phase = (self._phase + 1) % len(self.filenames)
|
||||||
|
|
||||||
def on_release(self):
|
def on_release(self):
|
||||||
pass
|
pass
|
||||||
|
|
@ -223,11 +219,8 @@ class PlayNextTrigger(TriggerBase):
|
||||||
class PlayRandomTrigger(TriggerBase):
|
class PlayRandomTrigger(TriggerBase):
|
||||||
stems = [f"RAND{i}" for i in range(10)]
|
stems = [f"RAND{i}" for i in range(10)]
|
||||||
|
|
||||||
def __init__(self, prefix):
|
|
||||||
super().__init__(prefix)
|
|
||||||
|
|
||||||
def on_press(self):
|
def on_press(self):
|
||||||
self.play(random_choice(self._filenames))
|
self.play(random_choice(self.filenames))
|
||||||
|
|
||||||
def on_release(self):
|
def on_release(self):
|
||||||
pass
|
pass
|
||||||
|
|
@ -275,16 +268,16 @@ def playback_specs(sample):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def check_match_make_mixer(audiodev):
|
def check_match_make_mixer(dev):
|
||||||
all_filenames = []
|
all_filenames = []
|
||||||
for trigger in triggers:
|
for i in triggers:
|
||||||
all_filenames.extend(trigger._filenames)
|
all_filenames.extend(i.filenames)
|
||||||
|
|
||||||
if not all_filenames:
|
if not all_filenames:
|
||||||
raise RuntimeError("*** NO AUDIO FILES FOUND ***")
|
raise RuntimeError("*** NO AUDIO FILES FOUND ***")
|
||||||
|
|
||||||
if max_simultaneous_voices == 1:
|
if max_simultaneous_voices == 1:
|
||||||
return [audiodev]
|
return [dev]
|
||||||
|
|
||||||
first_trigger = triggers[0]
|
first_trigger = triggers[0]
|
||||||
|
|
||||||
|
|
@ -292,7 +285,7 @@ def check_match_make_mixer(audiodev):
|
||||||
|
|
||||||
specs = None
|
specs = None
|
||||||
for filename in all_filenames:
|
for filename in all_filenames:
|
||||||
sample = first_trigger._get_sample(filename)
|
sample = first_trigger.get_sample(filename)
|
||||||
new_specs = playback_specs(sample)
|
new_specs = playback_specs(sample)
|
||||||
if specs is None:
|
if specs is None:
|
||||||
specs = new_specs
|
specs = new_specs
|
||||||
|
|
@ -312,7 +305,7 @@ def check_match_make_mixer(audiodev):
|
||||||
samples_signed=samples_signed,
|
samples_signed=samples_signed,
|
||||||
**specs,
|
**specs,
|
||||||
)
|
)
|
||||||
audiodev.play(mixer)
|
dev.play(mixer)
|
||||||
|
|
||||||
return list(mixer.voice)
|
return list(mixer.voice)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue