adjusted item_selection and created a module 'beatplayer'
This commit is contained in:
@ -3,25 +3,19 @@ from .colors import *
|
||||
from .item_selection import ItemSelection
|
||||
import pygame
|
||||
|
||||
MAX_COUNT = 9
|
||||
|
||||
class Athmos(ItemSelection):
|
||||
|
||||
def __init__(self, screen):
|
||||
self.screen = screen
|
||||
self.show_list = True
|
||||
self.surface = pygame.Surface((0,0), pygame.SRCALPHA)
|
||||
self.max_name_width = 350
|
||||
super().__init__(self.surface, self.max_name_width, MAX_COUNT)
|
||||
super().__init__(self.max_name_width)
|
||||
|
||||
def set_filenames(self,filenames):
|
||||
super().set_items(filenames)
|
||||
|
||||
def get_name_by_index(self, index):
|
||||
return self.items[index]
|
||||
|
||||
def get_count(self):
|
||||
return len(self.items)
|
||||
|
||||
def update(self):
|
||||
if self.show_list:
|
||||
|
||||
25
beatplayer.py
Normal file
25
beatplayer.py
Normal file
@ -0,0 +1,25 @@
|
||||
from .item_selection import ItemSelection
|
||||
|
||||
class BeatPlayer:
|
||||
|
||||
def __init__(self, screen):
|
||||
self.screen = screen
|
||||
self.max_name_width = 200
|
||||
self.clip_selection = ItemSelection(self.max_name_width)
|
||||
self.track_selection = ItemSelection(self.max_name_width)
|
||||
self.show_selection = False
|
||||
|
||||
def set_clip_names(self, clips):
|
||||
self.clip_selection.set_items(clips)
|
||||
|
||||
def set_track_names(self, tracks):
|
||||
self.track_selection.set_items(tracks)
|
||||
|
||||
def update(self):
|
||||
if self.show_selection:
|
||||
self.track_selection.update()
|
||||
self.clip_selection.update()
|
||||
self.screen.blit(self.track_selection.surface, ((self.screen.get_width()/4),
|
||||
(self.screen.get_height() - self.track_selection.surface.get_height())/2))
|
||||
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))
|
||||
@ -5,21 +5,23 @@ import math
|
||||
|
||||
class ItemSelection:
|
||||
|
||||
def __init__(self, surface, max_item_width, max_count):
|
||||
def __init__(self, max_item_width, max_display_count = 9):
|
||||
self.index = 0
|
||||
self.items = []
|
||||
self.surface = surface
|
||||
self.surface = pygame.Surface((0,0), pygame.SRCALPHA)
|
||||
self.max_item_width = max_item_width
|
||||
self.max_count = max_count
|
||||
self.max_display_count = max_display_count
|
||||
|
||||
def set_items(self, items):
|
||||
self.items = items
|
||||
self.surface = pygame.Surface(
|
||||
(self.max_item_width+50, self.get_display_count()*40),
|
||||
pygame.SRCALPHA)
|
||||
(self.max_item_width+50, self.get_display_count()*40), pygame.SRCALPHA)
|
||||
|
||||
def get_display_count(self):
|
||||
return min(self.max_count, len(self.items))
|
||||
return min(self.max_display_count, len(self.items))
|
||||
|
||||
def get_count(self):
|
||||
return len(self.items)
|
||||
|
||||
def update(self):
|
||||
self.surface.fill("black")
|
||||
@ -34,11 +36,12 @@ class ItemSelection:
|
||||
text_surface = font_helvetica16.render(text, False, color_primary_light)
|
||||
else:
|
||||
text_surface = font_helvetica16.render(text, False, color_primary)
|
||||
opacity = -20 + math.floor((i+1) * 2 * 255 / self.max_count
|
||||
if i < self.max_count/2
|
||||
else (self.max_count-i) * 2 * 255 / self.max_count)
|
||||
opacity = -15 + math.floor((i+1) * 2 * 255 / self.max_display_count
|
||||
if i < self.max_display_count/2
|
||||
else (self.max_display_count-i) * 2 * 255 / self.max_display_count)
|
||||
text_surface.set_alpha(opacity)
|
||||
#if text_surface.get_width() > self.max_item_width: self.max_item_width = text_surface.get_width()
|
||||
self.surface.blit(text_surface, ((10, self.surface.get_height()/self.get_display_count()*i)))
|
||||
pygame.draw.rect(self.surface, color_primary_light, (0, self.surface.get_height()/2-25, self.max_item_width+20, 40), 2)
|
||||
pygame.draw.rect(self.surface, color_primary_light,
|
||||
(0, self.surface.get_height()/2-25, self.max_item_width+20, 40), 2)
|
||||
|
||||
38
main.py
38
main.py
@ -6,6 +6,7 @@ from .lozenge_button import LozengeButton
|
||||
from .binary_button import BinaryButton
|
||||
from .circle_button import *
|
||||
from .athmos import Athmos
|
||||
from .beatplayer import BeatPlayer
|
||||
|
||||
class GuiMain:
|
||||
|
||||
@ -70,9 +71,11 @@ class GuiMain:
|
||||
self.loop_input_mode = None
|
||||
self.set_loop_input_mode(0)
|
||||
|
||||
self.beatplayer = BeatPlayer(self.screen)
|
||||
|
||||
self.athmos = Athmos(self.screen)
|
||||
self.athmos.show_list = False
|
||||
self.set_athmo_filenames([
|
||||
fnames = [
|
||||
"01_7Qp3xL8gK2tA5mR9eZ1vC4bN6sH0jF",
|
||||
"02_yP5cT8kL3wR0vX6mN9bQ2fZ4hJ7dS1",
|
||||
"03_3aB7eF2gH9jK5lM1nP6qR0sT8uV4B7eF2gH9jK5lM1nP6qR0sT8uV4wX",
|
||||
@ -85,8 +88,11 @@ class GuiMain:
|
||||
"10_6jL1fH7gK9wL0q3xZ4rE5pQ8oR3iK2",
|
||||
"11_0jF7Qp3xL8gK2tA5mR9eZ1vC4bN6sH",
|
||||
"12_4hJ7dS1yP5cT8kL3wR0vX6mN9bQ2fZ",
|
||||
"13_9jK5lM1nP6qR0sT8uV4wX3aB7eF2gH",
|
||||
])
|
||||
"13_9jK5lM1nP6qR0sT8uV4wX3aB7eF2gH"
|
||||
]
|
||||
self.beatplayer.set_clip_names(fnames)
|
||||
self.beatplayer.set_track_names(fnames)
|
||||
self.set_athmo_filenames(fnames)
|
||||
self.selected_athmo_srf = None
|
||||
|
||||
self.clock = pygame.time.Clock()
|
||||
@ -109,9 +115,15 @@ class GuiMain:
|
||||
def show_athmos(self, show=True):
|
||||
self.athmos.show_list = show
|
||||
self.show_knobs = not show
|
||||
self.beatplayer.show_selection = False
|
||||
if show == False:
|
||||
self.set_selected_athmo()
|
||||
|
||||
def show_beatplayer(self, show=True):
|
||||
self.beatplayer.show_selection = show
|
||||
self.show_knobs = not show
|
||||
self.athmos.show_list = False
|
||||
|
||||
def set_athmo_index(self, index):
|
||||
self.athmos.index = index
|
||||
|
||||
@ -138,6 +150,7 @@ class GuiMain:
|
||||
self.screen.blit(self.label_surface, (0,0))
|
||||
self.label_surface = pygame.Surface((self.screenW, self.screenH), pygame.SRCALPHA)
|
||||
|
||||
self.beatplayer.update()
|
||||
self.athmos.update()
|
||||
|
||||
self.knobs[self.fx_mode].display()
|
||||
@ -178,6 +191,11 @@ class GuiMain:
|
||||
if event.type == pygame.KEYDOWN:
|
||||
if event.key == pygame.K_ESCAPE:
|
||||
self.running = False
|
||||
if event.key == pygame.K_RETURN:
|
||||
if not self.beatplayer.show_selection:
|
||||
self.show_beatplayer()
|
||||
else:
|
||||
self.show_beatplayer(False)
|
||||
if event.key == pygame.K_INSERT:
|
||||
if not self.athmos.show_list:
|
||||
self.show_athmos()
|
||||
@ -187,10 +205,24 @@ class GuiMain:
|
||||
if self.athmos.show_list:
|
||||
self.athmos.index -= 1
|
||||
self.athmos.index %= self.athmos.get_count()
|
||||
elif self.beatplayer.show_selection:
|
||||
self.beatplayer.clip_selection.index -= 1
|
||||
self.beatplayer.clip_selection.index %= self.beatplayer.clip_selection.get_count()
|
||||
if event.key == pygame.K_DOWN:
|
||||
if self.athmos.show_list:
|
||||
self.athmos.index += 1
|
||||
self.athmos.index %= self.athmos.get_count()
|
||||
elif self.beatplayer.show_selection:
|
||||
self.beatplayer.clip_selection.index += 1
|
||||
self.beatplayer.clip_selection.index %= self.beatplayer.clip_selection.get_count()
|
||||
if event.key == pygame.K_RIGHT:
|
||||
if self.beatplayer.show_selection:
|
||||
self.beatplayer.track_selection.index += 1
|
||||
self.beatplayer.track_selection.index %= self.beatplayer.track_selection.get_count()
|
||||
if event.key == pygame.K_LEFT:
|
||||
if self.beatplayer.show_selection:
|
||||
self.beatplayer.track_selection.index -= 1
|
||||
self.beatplayer.track_selection.index %= self.beatplayer.track_selection.get_count()
|
||||
elif event.type == pygame.QUIT:
|
||||
self.running = False
|
||||
elif event.type == pygame.MOUSEBUTTONDOWN:
|
||||
|
||||
Reference in New Issue
Block a user