diff --git a/circle_button.py b/circle_button.py index b093031..a5b31e6 100644 --- a/circle_button.py +++ b/circle_button.py @@ -4,18 +4,62 @@ import math class CircleButton: - def __init__(self, gui, x, y, radius): - self.screen = gui.screen - self.x = x - self.y = y + def __init__(self, gui, position, radius): + self.surface = gui.screen + self.position = position self.radius = radius self.color = color_primary - def check_click(self, pos, action): - if math.sqrt(math.pow(pos[0] - self.x, 2) + - math.pow(pos[1] - self.y, 2)) < self.radius: - action() + def check_click(self, pos): + if math.sqrt(math.pow(pos[0] - self.position[0], 2) + + math.pow(pos[1] - self.position[1], 2)) < self.radius: + self.on_click() + + def on_click(self): + pass + + def draw(self): + pass def display(self): - pygame.draw.circle(self.screen, self.color, - (self.x, self.y), self.radius) \ No newline at end of file + pygame.draw.circle(self.surface, self.color, self.position, self.radius) + self.draw() + +class BeatButton(CircleButton): + + def __init__(self, gui, position, radius): + self.playing = False + super().__init__(gui, position, radius) + + def on_click(self): + self.playing = not self.playing + + def draw(self): + x, y = self.position + pygame.draw.polygon(self.surface, "black", [ + (x-self.radius/2.5, y-self.radius/1.5), + (x+self.radius/1.5, y), + (x-self.radius/2.5, y+self.radius/1.5) + ], 2 if self.playing else 0) + +class LoopButton(CircleButton): + def __init__(self, gui, position, radius): + self.state = False + self.counter = 0 + self.frame_threshold = 30 + self.recording = False + super().__init__(gui, position, radius) + + def on_click(self): + self.recording = not self.recording + self.state = not self.state + + def draw(self): + pygame.draw.circle(self.surface, "black", self.position, self.radius/1.5) + pygame.draw.circle(self.surface, self.color, self.position, self.radius/2, + 2 if not self.state else 0) + if self.recording: + if self.counter == self.frame_threshold: + self.state = not self.state + self.counter = 0 + self.counter += 1 \ No newline at end of file diff --git a/main.py b/main.py index 9605640..edcf00e 100644 --- a/main.py +++ b/main.py @@ -4,8 +4,7 @@ from fonts import * from knobs import Knobs from lozenge_button import LozengeButton from binary_button import BinaryButton -from circle_button import CircleButton -from functools import partial +from circle_button import * class GuiMain: @@ -54,9 +53,9 @@ class GuiMain: (20, self.fx_mode_buttons[0].y-20), (40, 40), 'M', False) - self.beat_button = CircleButton(self, 40, self.fx_mode_buttons[1].y, 20) - self.rloop_button = CircleButton(self, 40, self.fx_mode_buttons[2].y, 20) - self.lloop_button = CircleButton(self, 40, self.fx_mode_buttons[3].y, 20) + 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, @@ -70,11 +69,6 @@ class GuiMain: self.running = True self.run() - def change_color(self, component): - if component.color == color_primary: - component.color = color_primary_dark - else: component.color = color_primary - def set_fx_mode(self, mode): self.knobs[self.fx_mode].opacity = 0 self.fx_mode = self.fx_mode_labels.index(mode) @@ -132,9 +126,9 @@ class GuiMain: 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(), partial(self.change_color, self.beat_button)) - self.lloop_button.check_click(pygame.mouse.get_pos(), partial(self.change_color, self.lloop_button)) - self.rloop_button.check_click(pygame.mouse.get_pos(), partial(self.change_color, self.rloop_button)) + 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()) pygame.quit()