add F7 to pause beat detection

This commit is contained in:
Patrick Moessler 2023-02-24 17:19:33 +01:00
parent fdedffdafa
commit 851cba85cb

View file

@ -157,6 +157,7 @@ class Beamshow:
strobe = False
fps_slidewindow = []
frames_per_beat = 0
pause_beat = False
while True:
with self.audio.lock:
is_beat = self.audio.is_beat
@ -174,7 +175,7 @@ class Beamshow:
sum(fps_slidewindow) / len(fps_slidewindow) if fps_slidewindow else 0
)
common_events = loop.send((is_beat, frames_per_beat))
common_events = loop.send((is_beat and not pause_beat, frames_per_beat))
reinitialize = False
for event in common_events:
if event.type == pg.QUIT or (
@ -191,6 +192,9 @@ class Beamshow:
print("Reload")
self.effects.clear()
reinitialize = True
elif event.key == pg.K_F7:
pause_beat = not pause_beat
print(f"Pause beat: {pause_beat}")
elif event.key == pg.K_F8:
self.randomize = not self.randomize
state_str = (
@ -241,7 +245,7 @@ class Beamshow:
if strobe:
self.window.fill(
Colors.White if (framecounter % 4 == 0) else Colors.Black
Colors.White if (framecounter % 4 <= 1) else Colors.Black
)
if blackout:
@ -250,9 +254,25 @@ class Beamshow:
if is_beat:
pg.draw.rect(self.window, Colors.White, (0, 0, 20, 20))
pg.display.flip()
self.clock.tick(60)
framecounter += 1
current_fps = self.clock.get_fps()
fps_slidewindow.append(current_fps)
while len(fps_slidewindow) > 120:
fps_slidewindow.pop(0)
if self.print_fps and (framecounter & 0x3F == 0):
print(f"FPS: {current_fps:5.2f}, avg {fps_mean:5.2f}")
if fps_mean < 50:
pg.draw.rect(
self.window,
Colors.Yellow,
(self.window.get_width() - 20, 0, 20, 20),
)
elif fps_mean < 40:
pg.draw.rect(
self.window,
Colors.Red,
(self.window.get_width() - 20, 0, 20, 20),
)
if (
self.randomize and (framecounter % (self.randomize_interval * 60)) == 0
@ -267,12 +287,9 @@ class Beamshow:
self.effects.clear()
self.effects.extend(self.presets[self.last_preset])
current_fps = self.clock.get_fps()
fps_slidewindow.append(current_fps)
while len(fps_slidewindow) > 120:
fps_slidewindow.pop(0)
if self.print_fps:
print(f"FPS: {current_fps:5.2f}, avg {fps_mean:5.2f}")
pg.display.flip()
self.clock.tick(60)
framecounter += 1
def app_main() -> None: