Compare commits

..

5 Commits

6 changed files with 121 additions and 72 deletions

View File

@ -10,6 +10,8 @@ class Athmos(ItemSelection):
self.show_list = True self.show_list = True
self.max_name_width = 350 self.max_name_width = 350
super().__init__(self.max_name_width) super().__init__(self.max_name_width)
self.current_duration = 0
self.time_started = 0
def set_filenames(self,filenames): def set_filenames(self,filenames):
super().set_items(filenames) super().set_items(filenames)

View File

@ -1,6 +1,7 @@
from .item_selection import ItemSelection from .item_selection import ItemSelection
import pygame import pygame
from .colors import * from .colors import *
from .fonts import *
class BeatPlayer: class BeatPlayer:
@ -26,14 +27,14 @@ class BeatPlayer:
self.screen.blit(self.clip_selection.surface, ((self.screen.get_width()/4 + self.max_name_width) + 100, self.screen.blit(self.clip_selection.surface, ((self.screen.get_width()/4 + self.max_name_width) + 100,
(self.screen.get_height() - self.clip_selection.surface.get_height())/2)) (self.screen.get_height() - self.clip_selection.surface.get_height())/2))
else: else:
if self.track_selection.selected_item_srf is not None: selected_track = self.track_selection.get_selected_item()
self.screen.blit(self.track_selection.selected_item_srf, selected_clip = self.clip_selection.get_selected_item()
((self.screen.get_width()/4+10), self.screen.get_height() - 45)) if len(selected_track) > 15: selected_track = selected_track[0:13] + '...'
pygame.draw.rect(self.screen, color_primary_light, if len(selected_clip) > 30: selected_clip = selected_clip[0:28] + '...'
(self.screen.get_width()/4, self.screen.get_height() - 50, self.max_name_width+20, 40), 2) track_surface = font_helvetica16.render(f"{selected_track}",
if self.clip_selection.selected_item_srf is not None: False, color_primary_dark)
self.screen.blit(self.clip_selection.selected_item_srf, clip_surface = font_helvetica16.render(f"/ {selected_clip}",
((self.screen.get_width()/4 + self.max_name_width) + 110, self.screen.get_height() - 45)) False, color_primary_dark)
pygame.draw.rect(self.screen, color_primary_light, self.screen.blit(clip_surface, (self.screen.get_width()/2, 15))
((self.screen.get_width()/4 + self.max_name_width) + 100, self.screen.get_height() - 50, self.screen.blit(track_surface, (self.screen.get_width()/2-track_surface.get_width()-10, 15))
self.max_name_width+20, 40), 2)

View File

@ -24,6 +24,9 @@ class ItemSelection:
def get_count(self): def get_count(self):
return len(self.items) return len(self.items)
def get_selected_item(self):
return self.items[self.index]
def update(self): def update(self):
self.surface.fill("black") self.surface.fill("black")
for i in range(self.get_display_count()): for i in range(self.get_display_count()):

View File

@ -6,7 +6,7 @@ import random
class Knobs: class Knobs:
def __init__(self, gui, is_left_side=True): def __init__(self, gui, knob_names, is_left_side=True):
self.gui = gui self.gui = gui
self.knobs_surface = pygame.Surface((gui.screenW, gui.screenH), pygame.SRCALPHA) self.knobs_surface = pygame.Surface((gui.screenW, gui.screenH), pygame.SRCALPHA)
@ -15,20 +15,10 @@ class Knobs:
self.fade_speed = 5 self.fade_speed = 5
self.fade_in = False self.fade_in = False
self.fade_out = False self.fade_out = False
self.knob_names = knob_names
self.is_left_side = is_left_side self.is_left_side = is_left_side
knob_names = [
'Delay Time',
'Delay Vol',
'Reverb Wet',
'Reverb Size',
'Filter Freq',
'Distortion',
'Detune',
'Gain'
]
# Create and position the knobs # Create and position the knobs
self.knobs_radius = self.gui.screenW / 25 self.knobs_radius = self.gui.screenW / 25
knobs_spacing = self.knobs_radius * 2 knobs_spacing = self.knobs_radius * 2

View File

@ -5,7 +5,7 @@ from .fonts import *
class LozengeButton: class LozengeButton:
def __init__(self, gui, name, position, radius_x, radius_y): def __init__(self, gui, name, position, radius_x, radius_y, side):
self.gui = gui self.gui = gui
self.screen = gui.screen self.screen = gui.screen
self.name = name self.name = name
@ -13,6 +13,7 @@ class LozengeButton:
self.y = position[1] self.y = position[1]
self.radius_x = radius_x self.radius_x = radius_x
self.radius_y = radius_y self.radius_y = radius_y
self.side = side
self.focused = False self.focused = False
def display(self): def display(self):
@ -21,12 +22,13 @@ class LozengeButton:
pos = pygame.mouse.get_pos() pos = pygame.mouse.get_pos()
if math.sqrt(math.pow(pos[0] - self.x, 2) + math.pow(pos[1] - self.y, 2)) < self.radius_y: if math.sqrt(math.pow(pos[0] - self.x, 2) + math.pow(pos[1] - self.y, 2)) < self.radius_y:
self.focused = True self.focused = True
self.gui.set_fx_mode_by_name(self.name) self.gui.set_fx_mode_by_name(self.side, self.name)
self.gui.set_controller_fx_mode(self.side, self.name)
if self.focused: if self.focused:
w = 0 w = 0
fx_mode_label = font_helvetica16.render(self.name, False, color_primary_light) fx_mode_label = font_helvetica16.render(self.name, False, color_primary_light)
self.screen.blit(fx_mode_label, (self.x + 20, self.y - 8)) self.screen.blit(fx_mode_label, (self.x + (20 if self.side == 0 else -20-fx_mode_label.get_width()), self.y - 8))
else: else:
w = 2 w = 2
fx_mode_label = font_helvetica16.render(str(self.name)[0:1], False, color_primary_light) fx_mode_label = font_helvetica16.render(str(self.name)[0:1], False, color_primary_light)

123
main.py
View File

@ -10,7 +10,8 @@ from .beatplayer import BeatPlayer
class GuiMain: class GuiMain:
def __init__(self): def __init__(self, controller):
self.controller = controller
# pygame setup # pygame setup
pygame.init() pygame.init()
pygame.display.set_caption("SantoscopeUI") pygame.display.set_caption("SantoscopeUI")
@ -22,43 +23,83 @@ class GuiMain:
self.label_surface = pygame.Surface((self.screenW, self.screenH), pygame.SRCALPHA) self.label_surface = pygame.Surface((self.screenW, self.screenH), pygame.SRCALPHA)
self.fx_mode_labels = [ self.fx_mode_labels = [
[
'Strings', 'Strings',
'Beat',
'L-Loop', 'L-Loop',
'R-Loop', 'R-Loop',
'Jack', 'Jack',
'Athmo' 'Athmo'
],
[
'Mixer',
'Beat'
]
]
left_knob_names = [
'Delay Time',
'Delay Vol',
'Reverb Wet',
'Reverb Size',
'Filter Freq',
'Distortion',
'Detune',
'Gain'
]
mixer_knob_names = [
'Jack Vol',
'Athmo Vol',
'Beat speed',
'L-loop Vol',
'-unassigned-',
'Beat Vol',
'R-loop Vol',
'Master Vol'
] ]
# Create and position the fx_mode buttons # Create and position the fx_mode buttons
self.fx_mode_buttons = [] self.fx_mode_buttons = [[],[]]
self.fx_mode = 0 self.fx_mode = [0, 0]
for i in range(len(self.fx_mode_labels)): for i in range(len(self.fx_mode_labels[0])):
x = self.screenW * 2.5 / 19 x = self.screenW * 2.5 / 19
y = i * self.screenH / 7.5 + 45 y = i * self.screenH / 7.5 + 45
r_x = self.screenW * 0.35 / 19 r_x = self.screenW * 0.35 / 19
r_y = (self.screenH-20) / 16 r_y = (self.screenH-20) / 16
self.fx_mode_buttons.append( self.fx_mode_buttons[0].append(
LozengeButton(self, self.fx_mode_labels[i], (x,y), r_x, r_y) LozengeButton(self, self.fx_mode_labels[0][i], (x,y), r_x, r_y, 0)
) )
self.knobs = [] for i in range(len(self.fx_mode_labels[1])):
for i in range(len(self.fx_mode_labels)): x = self.screenW - 30
self.knobs.append(Knobs(self)) y = i * self.screenH / 7.5 + 90
r_x = self.screenW * 0.35 / 19
r_y = (self.screenH-20) / 16
self.fx_mode_buttons[1].append(
LozengeButton(self, self.fx_mode_labels[1][i], (x,y), r_x, r_y, 1)
)
self.set_fx_mode(self.fx_mode) self.knobs = [[], []]
for i in range(len(self.fx_mode_labels[0])):
self.knobs[0].append(Knobs(self, left_knob_names))
for i in range(len(self.fx_mode_labels[1])):
self.knobs[1].append(Knobs(self, left_knob_names if i==1 else mixer_knob_names, is_left_side=False))
self.set_fx_mode(0, self.fx_mode[0])
self.set_fx_mode(1, self.fx_mode[1])
self.show_knobs = True self.show_knobs = True
self.knobs_display_side = 0
self.mute_button = BinaryButton( self.mute_button = BinaryButton(
self.screen, self.screen,
(20, self.fx_mode_buttons[0].y-20), (20, self.fx_mode_buttons[0][0].y-20),
(40, 40), 'M', (40, 40), 'M',
False) False)
self.beat_button = BeatButton(self, (40, self.fx_mode_buttons[1].y), 20) self.beat_button = BeatButton(self, (40, self.fx_mode_buttons[0][1].y), 20)
self.rloop_button = LoopButton(self, (40, self.fx_mode_buttons[2].y), 20) self.rloop_button = LoopButton(self, (40, self.fx_mode_buttons[0][2].y), 20)
self.lloop_button = LoopButton(self, (40, self.fx_mode_buttons[3].y), 20) self.lloop_button = LoopButton(self, (40, self.fx_mode_buttons[0][3].y), 20)
self.rec_button = BinaryButton( self.rec_button = BinaryButton(
self.screen, self.screen,
@ -98,20 +139,26 @@ class GuiMain:
self.clock = pygame.time.Clock() self.clock = pygame.time.Clock()
self.running = True self.running = True
def set_knob_value(self, index, value): def set_knob_value(self, side, index, value):
self.knobs[self.fx_mode].set_value(index, value) self.knobs_display_side = side
self.knobs[side][self.fx_mode[side]].set_value(index, value)
def set_fx_mode(self, i): def set_fx_mode(self, side, i):
self.set_fx_mode_by_name(self.fx_mode_labels[i]) self.set_fx_mode_by_name(side, self.fx_mode_labels[side][i])
def set_fx_mode_by_name(self, mode): def set_fx_mode_by_name(self, side, mode):
self.knobs[self.fx_mode].opacity = 0 self.knobs_display_side = side
self.fx_mode = self.fx_mode_labels.index(mode) self.knobs[side][self.fx_mode[side]].opacity = 0 #checke
self.knobs[self.fx_mode].set_focused(None) self.fx_mode[side] = self.fx_mode_labels[side].index(mode)
self.knobs[self.fx_mode].fade_in = True self.knobs[side][self.fx_mode[side]].set_focused(None)
for b in self.fx_mode_buttons: self.knobs[side][self.fx_mode[side]].fade_in = True
for b in self.fx_mode_buttons[side]:
b.focused = (b.name == mode) b.focused = (b.name == mode)
def set_controller_fx_mode(self, side, mode):
i = self.fx_mode_labels[side].index(mode)
self.controller.set_fx_mode(side, i)
def show_athmos(self, show=True): def show_athmos(self, show=True):
self.athmos.show_list = show self.athmos.show_list = show
self.show_knobs = not show self.show_knobs = not show
@ -135,13 +182,15 @@ class GuiMain:
def set_beat_track_index(self, index): def set_beat_track_index(self, index):
self.beatplayer.track_selection.index = index self.beatplayer.track_selection.index = index
def set_selected_athmo(self): def set_selected_athmo(self, duration):
""" """
name = self.athmos.get_name_by_index(self.athmos.index) name = self.athmos.get_name_by_index(self.athmos.index)
if len(name) > 20: name = name[0:22] + '...' if len(name) > 20: name = name[0:22] + '...'
self.selected_athmo_srf = font_helvetica16.render(name, False, color_primary) self.selected_athmo_srf = font_helvetica16.render(name, False, color_primary)
""" """
self.selected_athmo_srf = self.athmos.selected_item_srf self.selected_athmo_srf = self.athmos.selected_item_srf
self.athmos.current_duration = duration * 1000 if duration is not None else 0
self.athmos.time_started = pygame.time.get_ticks()
def set_athmo_filenames(self, filenames): def set_athmo_filenames(self, filenames):
self.athmos.set_filenames(filenames) self.athmos.set_filenames(filenames)
@ -171,18 +220,19 @@ class GuiMain:
self.beatplayer.update() self.beatplayer.update()
self.athmos.update() self.athmos.update()
self.knobs[self.fx_mode].display() self.knobs[self.knobs_display_side][self.fx_mode[self.knobs_display_side]].display()
for button in self.fx_mode_buttons: for i in range(2):
for button in self.fx_mode_buttons[i]:
button.display() button.display()
self.mute_button.display() self.mute_button.display()
for i in range(1,4): for i in range(1,4):
pygame.draw.line(self.screen, color_primary_dark, 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[0][i].radius_x*0.5 + 60, self.fx_mode_buttons[0][i].y),
(self.fx_mode_buttons[i].x - self.fx_mode_buttons[i].radius_x * 1.5, (self.fx_mode_buttons[0][i].x - self.fx_mode_buttons[0][i].radius_x * 1.5,
self.fx_mode_buttons[i].y)) self.fx_mode_buttons[0][i].y))
self.beat_button.display() self.beat_button.display()
self.lloop_button.display() self.lloop_button.display()
self.rloop_button.display() self.rloop_button.display()
@ -193,9 +243,12 @@ class GuiMain:
(self.screenW*3 / 18, (self.screenW*3 / 18,
self.screenH - self.selected_athmo_srf.get_height()-10)) self.screenH - self.selected_athmo_srf.get_height()-10))
if pygame.time.get_ticks() - self.athmos.time_started >= self.athmos.current_duration:
self.selected_athmo_srf = None
if self.loop_input_mode is not None: if self.loop_input_mode is not None:
self.screen.blit(self.loop_input_mode, self.screen.blit(self.loop_input_mode,
((self.fx_mode_buttons[3].x+self.lloop_button.position[0])/2-self.loop_input_mode.get_width()/2, ((self.fx_mode_buttons[0][3].x+self.lloop_button.position[0])/2-self.loop_input_mode.get_width()/2,
(self.lloop_button.position[1]+self.rloop_button.position[1])/2-self.loop_input_mode.get_height()/2)) (self.lloop_button.position[1]+self.rloop_button.position[1])/2-self.loop_input_mode.get_height()/2))
pygame.draw.polygon(self.screen, "white", [(0, self.screenH/2), (self.screenW*3 / 19, self.screenH), (0, self.screenH)]) pygame.draw.polygon(self.screen, "white", [(0, self.screenH/2), (self.screenW*3 / 19, self.screenH), (0, self.screenH)])
@ -223,22 +276,20 @@ class GuiMain:
if self.athmos.show_list: if self.athmos.show_list:
self.athmos.index -= 1 self.athmos.index -= 1
self.athmos.index %= self.athmos.get_count() self.athmos.index %= self.athmos.get_count()
elif self.beatplayer.show_selection: else:
self.beatplayer.clip_selection.index -= 1 self.beatplayer.clip_selection.index -= 1
self.beatplayer.clip_selection.index %= self.beatplayer.clip_selection.get_count() self.beatplayer.clip_selection.index %= self.beatplayer.clip_selection.get_count()
if event.key == pygame.K_DOWN: if event.key == pygame.K_DOWN:
if self.athmos.show_list: if self.athmos.show_list:
self.athmos.index += 1 self.athmos.index += 1
self.athmos.index %= self.athmos.get_count() self.athmos.index %= self.athmos.get_count()
elif self.beatplayer.show_selection: else:
self.beatplayer.clip_selection.index += 1 self.beatplayer.clip_selection.index += 1
self.beatplayer.clip_selection.index %= self.beatplayer.clip_selection.get_count() self.beatplayer.clip_selection.index %= self.beatplayer.clip_selection.get_count()
if event.key == pygame.K_RIGHT: if event.key == pygame.K_RIGHT:
if self.beatplayer.show_selection:
self.beatplayer.track_selection.index += 1 self.beatplayer.track_selection.index += 1
self.beatplayer.track_selection.index %= self.beatplayer.track_selection.get_count() self.beatplayer.track_selection.index %= self.beatplayer.track_selection.get_count()
if event.key == pygame.K_LEFT: if event.key == pygame.K_LEFT:
if self.beatplayer.show_selection:
self.beatplayer.track_selection.index -= 1 self.beatplayer.track_selection.index -= 1
self.beatplayer.track_selection.index %= self.beatplayer.track_selection.get_count() self.beatplayer.track_selection.index %= self.beatplayer.track_selection.get_count()
elif event.type == pygame.QUIT: elif event.type == pygame.QUIT: