the end-point for setting the knob values has been created

This commit is contained in:
SallarShayegan
2025-03-13 21:48:01 +01:00
parent 24a60d7745
commit 6269e6f9f6
3 changed files with 16 additions and 10 deletions

11
knob.py
View File

@ -2,6 +2,8 @@ import pygame
import math
from .colors import *
FADE_COUNT_DOWN = 150
class Knob:
def __init__(self, group, name, radius, position, value = 0):
@ -12,12 +14,13 @@ class Knob:
self.position = position
self.value = value
self.focused = False
self.fade_count_down = 150
self.count_down = FADE_COUNT_DOWN
self.vanish_label_path = False
self.label_path = []
def set_value(self, value):
self.value = value
self.count_down = FADE_COUNT_DOWN
def set_color(self, color):
self.color = color
@ -29,7 +32,7 @@ class Knob:
else:
self.focused = False
self.color = color_primary
self.fade_count_down = 150
self.count_down = FADE_COUNT_DOWN
if not self.vanish_label_path: self.label_path = []
def get_position(self):
@ -51,9 +54,9 @@ class Knob:
pos = pygame.mouse.get_pos()
if math.sqrt(math.pow(pos[0]-self.position[0],2) + math.pow(pos[1]-self.position[1],2)) < self.radius:
self.group.set_focused(self)
if self.focused: self.fade_count_down -= 1
if self.focused: self.count_down -= 1
if self.fade_count_down == 0:
if self.count_down == 0:
self.vanish_label_path = True
self.set_focused(False)
pygame.draw.circle(surface, self.color + (self.group.opacity,), self.position, self.radius)

View File

@ -27,10 +27,6 @@ class Knobs:
'Gain'
]
self.values = []
for i in range(len(knob_names)):
self.values.append(random.random())
# Create and position the knobs
self.knobs_radius = self.gui.screenW / 25
knobs_spacing = self.knobs_radius * 2
@ -39,8 +35,8 @@ class Knobs:
knobs_y = (self.gui.screenH - (self.knobs_radius + knobs_spacing) * 3) / 2
y = knobs_y
self.knobs = []
for i in range(8):
self.knobs.append(Knob(self, knob_names[i], self.knobs_radius, (x, y), self.values[i]))
for i in range(len(knob_names)):
self.knobs.append(Knob(self, knob_names[i], self.knobs_radius, (x, y), 0))
y += self.knobs_radius + knobs_spacing
if i == 3 or i == 6:
x += self.knobs_radius + knobs_spacing
@ -141,6 +137,10 @@ class Knobs:
if knob is None:
k.vanish_label_path = False
def set_value(self, index, value):
self.set_focused(self.knobs[index])
self.knobs[index].set_value(value)
def display(self):
if self.fade_in and self.opacity < 255: self.opacity += self.fade_speed
if self.fade_out and self.opacity > 0: self.opacity -= self.fade_speed

View File

@ -68,6 +68,9 @@ class GuiMain:
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, mode):
self.knobs[self.fx_mode].opacity = 0
self.fx_mode = self.fx_mode_labels.index(mode)