mirror of
https://github.com/correl/turntable.git
synced 2024-11-23 19:19:55 +00:00
Render metadata in GUI
This commit is contained in:
parent
329270bd7d
commit
777ba43d93
2 changed files with 23 additions and 5 deletions
|
@ -13,4 +13,6 @@ def main() -> None:
|
||||||
while event := events.get():
|
while event := events.get():
|
||||||
logging.info("Event: %s", event)
|
logging.info("Event: %s", event)
|
||||||
except:
|
except:
|
||||||
|
logging.exception("Shutting down")
|
||||||
|
finally:
|
||||||
app.shutdown()
|
app.shutdown()
|
||||||
|
|
|
@ -43,7 +43,7 @@ class Plot:
|
||||||
return
|
return
|
||||||
fft = abs(np.fft.fft(data).real)
|
fft = abs(np.fft.fft(data).real)
|
||||||
fft = fft[: len(fft) // 2]
|
fft = fft[: len(fft) // 2]
|
||||||
heights = scipy.signal.resample(fft, self.bars) * self.height / 2 ** 16
|
heights = abs(scipy.signal.resample(fft, self.bars) * self.height / 2 ** 16)
|
||||||
for i, height in enumerate(heights):
|
for i, height in enumerate(heights):
|
||||||
pygame.draw.rect(
|
pygame.draw.rect(
|
||||||
self.screen,
|
self.screen,
|
||||||
|
@ -59,9 +59,9 @@ class Plot:
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
events: "Queue[events.Event]" = Queue()
|
event_queue: "Queue[events.Event]" = Queue()
|
||||||
pcm_in: "Queue[models.PCM]" = Queue()
|
pcm_in: "Queue[models.PCM]" = Queue()
|
||||||
app = application.Application(events, pcm_in)
|
app = application.Application(event_queue, pcm_in)
|
||||||
config = app.config.get("gui", dict())
|
config = app.config.get("gui", dict())
|
||||||
disp_no = os.getenv("DISPLAY")
|
disp_no = os.getenv("DISPLAY")
|
||||||
if disp_no:
|
if disp_no:
|
||||||
|
@ -97,6 +97,7 @@ def main():
|
||||||
screen.fill((0, 0, 0))
|
screen.fill((0, 0, 0))
|
||||||
# Initialise font support
|
# Initialise font support
|
||||||
pygame.font.init()
|
pygame.font.init()
|
||||||
|
font = pygame.font.Font(pygame.font.get_default_font(), 15)
|
||||||
# Render the screen
|
# Render the screen
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
|
|
||||||
|
@ -105,7 +106,7 @@ def main():
|
||||||
x=0,
|
x=0,
|
||||||
y=0,
|
y=0,
|
||||||
width=screen.get_width(),
|
width=screen.get_width(),
|
||||||
height=screen.get_height(),
|
height=screen.get_height() - 50,
|
||||||
bars=40,
|
bars=40,
|
||||||
bar_width=screen.get_width() // 45,
|
bar_width=screen.get_width() // 45,
|
||||||
color=(139, 0, 139),
|
color=(139, 0, 139),
|
||||||
|
@ -114,6 +115,7 @@ def main():
|
||||||
try:
|
try:
|
||||||
app.run()
|
app.run()
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
|
title = "<Idle>"
|
||||||
while True:
|
while True:
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == QUIT or (
|
if event.type == QUIT or (
|
||||||
|
@ -123,8 +125,15 @@ def main():
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
while event := events.get(False):
|
while event := event_queue.get(False):
|
||||||
...
|
...
|
||||||
|
if isinstance(event, events.StartedPlaying):
|
||||||
|
title = "<Starting...>"
|
||||||
|
elif isinstance(event, events.StoppedPlaying):
|
||||||
|
title = "<Idle>"
|
||||||
|
elif isinstance(event, events.NewMetadata):
|
||||||
|
title = event.title
|
||||||
|
|
||||||
except queue.Empty:
|
except queue.Empty:
|
||||||
...
|
...
|
||||||
try:
|
try:
|
||||||
|
@ -134,7 +143,14 @@ def main():
|
||||||
...
|
...
|
||||||
screen.fill((0, 0, 0))
|
screen.fill((0, 0, 0))
|
||||||
plot.draw()
|
plot.draw()
|
||||||
|
title_text = font.render(title, True, (255, 255, 255))
|
||||||
|
title_rect = title_text.get_rect()
|
||||||
|
title_rect.left = 25
|
||||||
|
title_rect.centery = screen.get_height() - 25
|
||||||
|
screen.blit(title_text, title_rect)
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
clock.tick(FPS)
|
clock.tick(FPS)
|
||||||
except:
|
except:
|
||||||
|
logger.exception("Shutting down")
|
||||||
|
finally:
|
||||||
app.shutdown()
|
app.shutdown()
|
||||||
|
|
Loading…
Reference in a new issue