165 lines
5.8 KiB
Python
Executable File
165 lines
5.8 KiB
Python
Executable File
import pygame
|
|
from .colors import *
|
|
from .fonts import *
|
|
from .knobs import Knobs
|
|
from .lozenge_button import LozengeButton
|
|
from .binary_button import BinaryButton
|
|
from .circle_button import *
|
|
from .athmos import Athmos
|
|
|
|
class GuiMain:
|
|
|
|
def __init__(self):
|
|
# pygame setup
|
|
pygame.init()
|
|
pygame.display.set_caption("SantoscopeUI")
|
|
self.screen = pygame.display.set_mode((800, 480))
|
|
#self.screen = pygame.display.set_mode((0,0), pygame.FULLSCREEN)
|
|
self.screenH = self.screen.get_height()
|
|
self.screenW = self.screen.get_width()
|
|
|
|
self.label_surface = pygame.Surface((self.screenW, self.screenH), pygame.SRCALPHA)
|
|
|
|
self.fx_mode_labels = [
|
|
'Strings',
|
|
'Beat',
|
|
'L-Loop',
|
|
'R-Loop',
|
|
'Jack',
|
|
'Athmo'
|
|
]
|
|
|
|
# Create and position the fx_mode buttons
|
|
self.fx_mode_buttons = []
|
|
|
|
self.fx_mode = 0
|
|
|
|
for i in range(len(self.fx_mode_labels)):
|
|
x = self.screenW * 2.5 / 19
|
|
y = i * self.screenH / 7.5 + 45
|
|
r_x = self.screenW * 0.35 / 19
|
|
r_y = (self.screenH-20) / 16
|
|
self.fx_mode_buttons.append(
|
|
LozengeButton(self, self.fx_mode_labels[i], (x,y), r_x, r_y)
|
|
)
|
|
|
|
self.knobs = []
|
|
for i in range(len(self.fx_mode_labels)):
|
|
self.knobs.append(Knobs(self))
|
|
|
|
self.set_fx_mode(self.fx_mode)
|
|
self.show_knobs = True
|
|
|
|
self.mute_button = BinaryButton(
|
|
self.screen,
|
|
(20, self.fx_mode_buttons[0].y-20),
|
|
(40, 40), 'M',
|
|
False)
|
|
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)
|
|
|
|
self.rec_button = BinaryButton(
|
|
self.screen,
|
|
(self.screenW-70, self.screenH-40),
|
|
(60, 30),
|
|
"REC",
|
|
False
|
|
)
|
|
|
|
self.loop_input_mode = None
|
|
self.set_loop_input_mode(0)
|
|
|
|
self.athmos = Athmos(self.screen)
|
|
self.athmos.show_list = False
|
|
|
|
self.clock = pygame.time.Clock()
|
|
self.running = True
|
|
|
|
def set_knob_value(self, index, value):
|
|
self.knobs[self.fx_mode].set_value(index, value)
|
|
|
|
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):
|
|
self.knobs[self.fx_mode].opacity = 0
|
|
self.fx_mode = self.fx_mode_labels.index(mode)
|
|
self.knobs[self.fx_mode].set_focused(None)
|
|
self.knobs[self.fx_mode].fade_in = True
|
|
for b in self.fx_mode_buttons:
|
|
b.focused = (b.name == mode)
|
|
|
|
def show_athmos(self, show=True):
|
|
self.athmos.show_list = show
|
|
self.show_knobs = not show
|
|
|
|
def set_athmo_index(self, index):
|
|
self.athmos.index = index
|
|
|
|
def set_athmo_filenames(self, filenames):
|
|
self.athmos.set_filenames(filenames)
|
|
|
|
def set_loop_input_mode(self, mode):
|
|
str_mode = 'SJ'
|
|
if mode == 0:
|
|
str_mode = 'S'
|
|
elif mode == 1:
|
|
str_mode = 'J'
|
|
self.loop_input_mode = font_helvetica16.render(str_mode, False, color_primary)
|
|
|
|
def update(self):
|
|
if self.running:
|
|
# fill the screen with a color to wipe away anything from last frame
|
|
self.screen.fill("black")
|
|
|
|
self.screen.blit(self.label_surface, (0,0))
|
|
self.label_surface = pygame.Surface((self.screenW, self.screenH), pygame.SRCALPHA)
|
|
|
|
self.athmos.update()
|
|
|
|
self.knobs[self.fx_mode].display()
|
|
|
|
for button in self.fx_mode_buttons:
|
|
button.display()
|
|
|
|
self.mute_button.display()
|
|
|
|
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))
|
|
self.beat_button.display()
|
|
self.lloop_button.display()
|
|
self.rloop_button.display()
|
|
self.rec_button.display()
|
|
|
|
if self.loop_input_mode is not None:
|
|
self.screen.blit(self.loop_input_mode,
|
|
(self.lloop_button.position[1]+self.rloop_button.position[1]/2),
|
|
(self.fx_mode_buttons[3].x + self.lloop_button.position[0]/2))
|
|
|
|
pygame.draw.polygon(self.screen, "white", [(0, self.screenH/2), (self.screenW*3 / 19, self.screenH), (0, self.screenH)])
|
|
# flip() the display to put your work on screen
|
|
pygame.display.flip()
|
|
|
|
self.clock.tick(30) # limits FPS to 60
|
|
|
|
for event in pygame.event.get():
|
|
# exit when esc is pressed
|
|
if event.type == pygame.KEYDOWN:
|
|
if event.key == pygame.K_ESCAPE:
|
|
self.running = False
|
|
elif event.type == pygame.QUIT:
|
|
self.running = False
|
|
elif event.type == pygame.MOUSEBUTTONDOWN:
|
|
if event.button == 1:
|
|
self.mute_button.check_click(pygame.mouse.get_pos())
|
|
self.rec_button.check_click(pygame.mouse.get_pos())
|
|
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())
|
|
else:
|
|
pygame.quit()
|