2025-02-23 15:26:53 +01:00
|
|
|
import pygame
|
2025-03-13 19:42:58 +01:00
|
|
|
from .colors import *
|
|
|
|
|
from .fonts import *
|
|
|
|
|
from .knobs import Knobs
|
|
|
|
|
from .lozenge_button import LozengeButton
|
|
|
|
|
from .binary_button import BinaryButton
|
|
|
|
|
from .circle_button import *
|
2025-04-02 21:27:14 +02:00
|
|
|
from .athmos import Athmos
|
2025-02-24 23:23:05 +01:00
|
|
|
|
|
|
|
|
class GuiMain:
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
# pygame setup
|
|
|
|
|
pygame.init()
|
2025-02-28 16:51:32 +01:00
|
|
|
pygame.display.set_caption("SantoscopeUI")
|
2025-02-28 13:16:39 +01:00
|
|
|
self.screen = pygame.display.set_mode((800, 480))
|
|
|
|
|
#self.screen = pygame.display.set_mode((0,0), pygame.FULLSCREEN)
|
2025-02-25 21:26:16 +01:00
|
|
|
self.screenH = self.screen.get_height()
|
|
|
|
|
self.screenW = self.screen.get_width()
|
2025-02-24 23:23:05 +01:00
|
|
|
|
2025-03-02 20:16:40 +01:00
|
|
|
self.label_surface = pygame.Surface((self.screenW, self.screenH), pygame.SRCALPHA)
|
|
|
|
|
|
2025-02-28 14:04:53 +01:00
|
|
|
self.fx_mode_labels = [
|
2025-02-24 23:23:05 +01:00
|
|
|
'Strings',
|
|
|
|
|
'Beat',
|
|
|
|
|
'L-Loop',
|
|
|
|
|
'R-Loop',
|
|
|
|
|
'Jack',
|
|
|
|
|
'Athmo'
|
|
|
|
|
]
|
|
|
|
|
|
2025-02-25 19:59:56 +01:00
|
|
|
# Create and position the fx_mode buttons
|
|
|
|
|
self.fx_mode_buttons = []
|
2025-02-28 14:04:53 +01:00
|
|
|
|
|
|
|
|
self.fx_mode = 0
|
2025-02-25 19:59:56 +01:00
|
|
|
|
2025-02-28 14:04:53 +01:00
|
|
|
for i in range(len(self.fx_mode_labels)):
|
2025-02-25 19:59:56 +01:00
|
|
|
x = self.screenW * 2.5 / 19
|
2025-02-25 22:10:16 +01:00
|
|
|
y = i * self.screenH / 7.5 + 45
|
2025-02-25 19:59:56 +01:00
|
|
|
r_x = self.screenW * 0.35 / 19
|
|
|
|
|
r_y = (self.screenH-20) / 16
|
2025-02-28 20:04:50 +01:00
|
|
|
self.fx_mode_buttons.append(
|
|
|
|
|
LozengeButton(self, self.fx_mode_labels[i], (x,y), r_x, r_y)
|
|
|
|
|
)
|
2025-02-28 14:04:53 +01:00
|
|
|
|
|
|
|
|
self.knobs = []
|
|
|
|
|
for i in range(len(self.fx_mode_labels)):
|
|
|
|
|
self.knobs.append(Knobs(self))
|
2025-02-24 23:23:05 +01:00
|
|
|
|
2025-04-02 22:59:01 +02:00
|
|
|
#self.set_fx_mode(self.fx_mode)
|
2025-02-28 16:51:32 +01:00
|
|
|
|
2025-02-28 19:53:20 +01:00
|
|
|
self.mute_button = BinaryButton(
|
|
|
|
|
self.screen,
|
|
|
|
|
(20, self.fx_mode_buttons[0].y-20),
|
|
|
|
|
(40, 40), 'M',
|
|
|
|
|
False)
|
2025-03-02 22:40:13 +01:00
|
|
|
self.beat_button = BeatButton(self, (40, self.fx_mode_buttons[1].y), 20)
|
|
|
|
|
self.rloop_button = LoopButton(self, (40, self.fx_mode_buttons[2].y), 20)
|
|
|
|
|
self.lloop_button = LoopButton(self, (40, self.fx_mode_buttons[3].y), 20)
|
2025-02-28 19:53:20 +01:00
|
|
|
|
2025-02-28 20:04:50 +01:00
|
|
|
self.rec_button = BinaryButton(
|
|
|
|
|
self.screen,
|
|
|
|
|
(self.screenW-70, self.screenH-40),
|
|
|
|
|
(60, 30),
|
|
|
|
|
"REC",
|
|
|
|
|
False
|
|
|
|
|
)
|
|
|
|
|
|
2025-04-02 22:59:01 +02:00
|
|
|
self.athmos = Athmos(self.screen)
|
2025-04-02 21:27:14 +02:00
|
|
|
|
2025-02-24 23:23:05 +01:00
|
|
|
self.clock = pygame.time.Clock()
|
|
|
|
|
self.running = True
|
|
|
|
|
|
2025-03-13 21:48:01 +01:00
|
|
|
def set_knob_value(self, index, value):
|
|
|
|
|
self.knobs[self.fx_mode].set_value(index, value)
|
|
|
|
|
|
2025-03-30 12:10:59 +02:00
|
|
|
def set_fx_mode(self, i):
|
|
|
|
|
self.set_fx_mode_by_name(self.fx_mode_labels[i])
|
|
|
|
|
|
|
|
|
|
def set_fx_mode_by_name(self, mode):
|
2025-03-02 20:16:40 +01:00
|
|
|
self.knobs[self.fx_mode].opacity = 0
|
2025-02-28 14:04:53 +01:00
|
|
|
self.fx_mode = self.fx_mode_labels.index(mode)
|
2025-02-28 14:21:06 +01:00
|
|
|
self.knobs[self.fx_mode].set_focused(None)
|
2025-03-02 20:16:40 +01:00
|
|
|
self.knobs[self.fx_mode].fade_in = True
|
2025-02-25 19:59:56 +01:00
|
|
|
for b in self.fx_mode_buttons:
|
2025-02-28 14:04:53 +01:00
|
|
|
b.focused = (b.name == mode)
|
2025-02-25 19:59:56 +01:00
|
|
|
|
2025-04-02 22:59:01 +02:00
|
|
|
def set_athmo_index(self, index):
|
|
|
|
|
self.athmos.index = index
|
|
|
|
|
|
|
|
|
|
def set_athmo_filenames(self, filenames):
|
2025-04-02 23:42:32 +02:00
|
|
|
self.athmos.set_filenames(filenames)
|
2025-04-02 22:59:01 +02:00
|
|
|
|
2025-03-13 19:42:58 +01:00
|
|
|
def update(self):
|
|
|
|
|
if self.running:
|
2025-02-24 23:23:05 +01:00
|
|
|
# fill the screen with a color to wipe away anything from last frame
|
|
|
|
|
self.screen.fill("black")
|
|
|
|
|
|
2025-03-02 20:16:40 +01:00
|
|
|
self.screen.blit(self.label_surface, (0,0))
|
|
|
|
|
self.label_surface = pygame.Surface((self.screenW, self.screenH), pygame.SRCALPHA)
|
|
|
|
|
|
2025-04-02 22:59:01 +02:00
|
|
|
self.athmos.update()
|
|
|
|
|
|
2025-02-28 14:04:53 +01:00
|
|
|
self.knobs[self.fx_mode].display()
|
2025-02-24 23:23:05 +01:00
|
|
|
|
2025-02-25 19:59:56 +01:00
|
|
|
for button in self.fx_mode_buttons:
|
|
|
|
|
button.display()
|
2025-02-25 22:10:16 +01:00
|
|
|
|
2025-02-28 16:51:32 +01:00
|
|
|
self.mute_button.display()
|
|
|
|
|
|
2025-02-25 22:10:16 +01:00
|
|
|
for i in range(1,4):
|
|
|
|
|
pygame.draw.line(self.screen, color_primary_dark,
|
|
|
|
|
(self.fx_mode_buttons[i].radius_x*0.5 + 60, self.fx_mode_buttons[i].y),
|
|
|
|
|
(self.fx_mode_buttons[i].x - self.fx_mode_buttons[i].radius_x * 1.5,
|
|
|
|
|
self.fx_mode_buttons[i].y))
|
2025-02-28 19:53:20 +01:00
|
|
|
self.beat_button.display()
|
|
|
|
|
self.lloop_button.display()
|
|
|
|
|
self.rloop_button.display()
|
2025-02-28 20:04:50 +01:00
|
|
|
self.rec_button.display()
|
2025-02-25 22:10:16 +01:00
|
|
|
|
|
|
|
|
pygame.draw.polygon(self.screen, "white", [(0, self.screenH/2), (self.screenW*3 / 19, self.screenH), (0, self.screenH)])
|
2025-02-24 23:23:05 +01:00
|
|
|
# flip() the display to put your work on screen
|
|
|
|
|
pygame.display.flip()
|
|
|
|
|
|
2025-03-13 19:42:58 +01:00
|
|
|
self.clock.tick(30) # limits FPS to 60
|
2025-02-25 20:36:47 +01:00
|
|
|
|
|
|
|
|
for event in pygame.event.get():
|
2025-03-13 19:42:58 +01:00
|
|
|
# exit when esc is pressed
|
2025-02-28 16:51:32 +01:00
|
|
|
if event.type == pygame.KEYDOWN:
|
|
|
|
|
if event.key == pygame.K_ESCAPE:
|
2025-03-13 19:42:58 +01:00
|
|
|
self.running = False
|
|
|
|
|
elif event.type == pygame.QUIT:
|
|
|
|
|
self.running = False
|
|
|
|
|
elif event.type == pygame.MOUSEBUTTONDOWN:
|
2025-02-28 16:51:32 +01:00
|
|
|
if event.button == 1:
|
|
|
|
|
self.mute_button.check_click(pygame.mouse.get_pos())
|
2025-02-28 20:04:50 +01:00
|
|
|
self.rec_button.check_click(pygame.mouse.get_pos())
|
2025-03-02 22:40:13 +01:00
|
|
|
self.beat_button.check_click(pygame.mouse.get_pos())
|
|
|
|
|
self.lloop_button.check_click(pygame.mouse.get_pos())
|
|
|
|
|
self.rloop_button.check_click(pygame.mouse.get_pos())
|
2025-03-13 19:42:58 +01:00
|
|
|
else:
|
|
|
|
|
pygame.quit()
|