X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=music_sampler.py;h=0d9a7a98263e358c99ab578a028da41be0028475;hb=4b2d79ca27dcbb85465829595ad81cec5fc63983;hp=42c01e3adfa629c789cfd6f2ff570cb6106e8613;hpb=8612c5f8bb0fc9529bc489a6719654d4474db6d5;p=perso%2FImmae%2FProjets%2FPython%2FMusicSampler.git diff --git a/music_sampler.py b/music_sampler.py index 42c01e3..0d9a7a9 100644 --- a/music_sampler.py +++ b/music_sampler.py @@ -1,80 +1,63 @@ -import sys -import pygame -import helpers -import threading - -pygame.mixer.pre_init(frequency = 44100) -pygame.init() - -size = width, height = 913, 563 -screen = pygame.display.set_mode(size) -screen.fill((229, 228, 226)) - -draw_lock = helpers.Lock("draw") - -mapping = helpers.Mapping(screen, draw_lock) -channel_number, open_files = helpers.parse_config(mapping) -pygame.mixer.set_num_channels(channel_number) - -mapping.draw() +from kivy.app import App +from kivy.uix.floatlayout import FloatLayout +from kivy.uix.relativelayout import RelativeLayout +from kivy.properties import ListProperty, StringProperty +from kivy.clock import Clock +from kivy.core.window import Window + +from helpers.key import Key +from helpers.mapping import Mapping + +class PlayList(RelativeLayout): + playlist = ListProperty([]) + + def __init__(self, **kwargs): + super(PlayList, self).__init__(**kwargs) + Clock.schedule_interval(self.update_playlist, 0.5) + + def update_playlist(self, dt): + if self.parent is None or 'Mapping' not in self.parent.ids: + return True + + open_files = self.parent.ids['Mapping'].open_files + self.playlist = [] + for music_file in open_files.values(): + if not music_file.is_playing(): + continue + if music_file.is_paused(): + self.playlist.append(["⏸", music_file.name, False]) + else: + self.playlist.append(["⏵", music_file.name, True]) -draw_lock.acquire() -pygame.display.flip() -draw_lock.release() -contexts = [ - 'normal' -] +class ActionList(RelativeLayout): + action_title = StringProperty("") + action_list = ListProperty([]) -context = 'normal' + def update_list(self, key, action_number = 0): + self.action_title = "actions linked to key {}:".format(key.key_sym) + self.action_list = [] -#### Normal workflow #### -while 1: - event = pygame.event.wait() + action_descriptions = [action.description() for action in key.actions] - if event.type == pygame.QUIT or ( - event.type == pygame.KEYDOWN and - event.mod == 4160 and - event.key == pygame.K_c): - for thread in threading.enumerate(): - if thread.getName()[0:2] != "MS": - continue - thread.join() + for index, description in enumerate(action_descriptions): + if index < int(action_number): + icon = "✓" + elif index + 0.5 == action_number: + icon = "✅" + else: + icon = " " - pygame.quit() - sys.exit() + self.action_list.append([icon, description]) - if context == 'normal': - if event.type == pygame.KEYDOWN: - key = mapping.find_by_key_num(event.key) - if key is not None and not key.disabled: - threading.Thread(name = "MSKeyAction", target=key.do_actions, args = [screen]).start() - threading.Thread(name = "MSClic", target=key.list_actions, args = [screen]).start() - elif event.type == pygame.MOUSEBUTTONUP: - key = mapping.find_by_collidepoint(pygame.mouse.get_pos()) - if key is not None: - threading.Thread(name = "MSClic", target=key.list_actions, args = [screen]).start() +class Screen(FloatLayout): + pass - draw_lock.acquire() - police = helpers.font(14) - icon_police = helpers.font(14, font = "Symbola") +class MusicSamplerApp(App): + def build(self): + Window.size = (913, 563) - surface = pygame.Surface((208, 250)).convert() - surface.fill((250, 250, 250)) - offset = 0 - for music_file in open_files.values(): - police.set_bold(False) - if music_file.is_playing(): - if music_file.is_paused(): - icon = icon_police.render("⏸", True, (0,0,0)) - else: - icon = icon_police.render("⏵", True, (0,0,0)) - police.set_bold(True) - text = police.render(music_file.name, True, (0,0,0)) - surface.blit(icon, (0, offset)) - surface.blit(text, (20, offset)) - offset += police.get_linesize() - screen.blit(surface, (700, 308)) + return Screen() - pygame.display.flip() - draw_lock.release() +if __name__ == '__main__': + MusicSamplerApp().run()