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 from .beatplayer import BeatPlayer 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', 'L-Loop', 'R-Loop', 'Jack', '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 self.fx_mode_buttons = [[],[]] self.fx_mode = [0, 0] for i in range(len(self.fx_mode_labels[0])): 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[0].append( LozengeButton(self, self.fx_mode_labels[0][i], (x,y), r_x, r_y, 0) ) for i in range(len(self.fx_mode_labels[1])): x = self.screenW - 30 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.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.knobs_display_side = 0 self.mute_button = BinaryButton( self.screen, (20, self.fx_mode_buttons[0][0].y-20), (40, 40), 'M', False) self.beat_button = BeatButton(self, (40, self.fx_mode_buttons[0][1].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[0][3].y), 20) self.rec_button = BinaryButton( self.screen, (self.screenW-70, 15), (60, 30), "REC", False ) 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 fnames = [ "01_7Qp3xL8gK2tA5mR9eZ1vC4bN6sH0jF", "02_yP5cT8kL3wR0vX6mN9bQ2fZ4hJ7dS1", "03_3aB7eF2gH9jK5lM1nP6qR0sT8uV4B7eF2gH9jK5lM1nP6qR0sT8uV4wX", "04_6mV0cX8zL5jH7gF2dS9aP1oI3uY4tR", "05_2pQ8oR3iK6jL1fH7gK9wL0q3xZ4jL1fH7gK9wL0q3xZ4rE5", "06_9eZ1vC4bN6sH0jF7Qp3xL8gK2tA5mR", "07_0vX6mN9bQ2fZ4hJ7dS1yP5cT8kL3wR", "08_1nP6qR0sT8uV4wX3aB7eF2gH9jK5lM", "09_5jH7gF2dS9aP1oI3uY4tR6mV0cX8zL", "10_6jL1fH7gK9wL0q3xZ4rE5pQ8oR3iK2", "11_0jF7Qp3xL8gK2tA5mR9eZ1vC4bN6sH", "12_4hJ7dS1yP5cT8kL3wR0vX6mN9bQ2fZ", "13_9jK5lM1nP6qR0sT8uV4wX3aB7eF2gH" ] #self.beatplayer.set_clip_names(fnames[0:5]) #self.beatplayer.set_track_names(fnames[0:9]) #self.set_athmo_filenames(fnames) self.selected_athmo_srf = None self.clock = pygame.time.Clock() self.running = True def set_knob_value(self, side, index, value): self.knobs_display_side = side self.knobs[side][self.fx_mode[side]].set_value(index, value) def set_fx_mode(self, side, i): self.set_fx_mode_by_name(side, self.fx_mode_labels[side][i]) def set_fx_mode_by_name(self, side, mode): self.knobs_display_side = side self.knobs[side][self.fx_mode[side]].opacity = 0 #checke self.fx_mode[side] = self.fx_mode_labels[side].index(mode) self.knobs[side][self.fx_mode[side]].set_focused(None) self.knobs[side][self.fx_mode[side]].fade_in = True for b in self.fx_mode_buttons[side]: b.focused = (b.name == mode) 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 def set_beat_clip_index(self, index): self.beatplayer.clip_selection.index = index def set_beat_track_index(self, index): self.beatplayer.track_selection.index = index def set_selected_athmo(self): """ name = self.athmos.get_name_by_index(self.athmos.index) if len(name) > 20: name = name[0:22] + '...' self.selected_athmo_srf = font_helvetica16.render(name, False, color_primary) """ self.selected_athmo_srf = self.athmos.selected_item_srf def set_athmo_filenames(self, filenames): self.athmos.set_filenames(filenames) def set_beat_track_names(self, names): self.beatplayer.set_track_names(names) def set_beat_clip_names(self, names): self.beatplayer.set_clip_names(names) 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.beatplayer.update() self.athmos.update() self.knobs[self.knobs_display_side][self.fx_mode[self.knobs_display_side]].display() for i in range(2): for button in self.fx_mode_buttons[i]: button.display() self.mute_button.display() for i in range(1,4): pygame.draw.line(self.screen, color_primary_dark, (self.fx_mode_buttons[0][i].radius_x*0.5 + 60, self.fx_mode_buttons[0][i].y), (self.fx_mode_buttons[0][i].x - self.fx_mode_buttons[0][i].radius_x * 1.5, self.fx_mode_buttons[0][i].y)) self.beat_button.display() self.lloop_button.display() self.rloop_button.display() self.rec_button.display() if self.selected_athmo_srf is not None: self.screen.blit(self.selected_athmo_srf, (self.screenW*3 / 18, self.screenH - self.selected_athmo_srf.get_height()-10)) if self.loop_input_mode is not None: self.screen.blit(self.loop_input_mode, ((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)) 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 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() else: self.show_athmos(False) if event.key == pygame.K_UP: 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: 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()