X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=music_sampler.py;h=a7faea24921b337e50e688164601276eb8ff36c5;hb=f029e879b326c3b3dce3428561a280fa52b9f04c;hp=6cc49dff4884a7f0391f796ddd097321afe146b0;hpb=e7f8dab4980d8a477f305e3565ca3c80abd7d790;p=perso%2FImmae%2FProjets%2FPython%2FMusicSampler.git diff --git a/music_sampler.py b/music_sampler.py index 6cc49df..a7faea2 100644 --- a/music_sampler.py +++ b/music_sampler.py @@ -1,55 +1,70 @@ +import kivy +kivy.require("1.9.1") +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 kivy.lang import Builder +from helpers.key import Key +from helpers.mapping import Mapping + import sys -import pygame -import helpers -import threading -pygame.mixer.pre_init(frequency = 44100) -pygame.init() +if getattr(sys, 'frozen', False): + Builder.load_file(sys._MEIPASS + '/musicsampler.kv') + +class PlayList(RelativeLayout): + playlist = ListProperty([]) -size = width, height = 1024, 600 + def __init__(self, **kwargs): + super(PlayList, self).__init__(**kwargs) + Clock.schedule_interval(self.update_playlist, 0.5) -helpers.draw_lock.acquire() -screen = pygame.display.set_mode(size) -mapping = helpers.Mapping(screen) + def update_playlist(self, dt): + if self.parent is None or 'Mapping' not in self.parent.ids: + return True -action_surface = pygame.Surface((600, 250)).convert() -action_surface.fill((0,0,0)) -helpers.parse_config(mapping) -helpers.draw_lock.release() + 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]) -mapping.draw() -helpers.draw_lock.acquire() -screen.blit(action_surface, (10, 330)) +class ActionList(RelativeLayout): + action_title = StringProperty("") + action_list = ListProperty([]) -pygame.display.flip() -helpers.draw_lock.release() + def update_list(self, key, action_number = 0): + self.action_title = "actions linked to key {}:".format(key.key_sym) + self.action_list = [] -contexts = [ - 'normal' -] + action_descriptions = [action.description() for action in key.actions] -context = 'normal' + for index, description in enumerate(action_descriptions): + if index < int(action_number): + icon = "✓" + elif index + 0.5 == action_number: + icon = "✅" + else: + icon = " " -while 1: - event = pygame.event.wait() + self.action_list.append([icon, description]) - if event.type == pygame.QUIT or ( - event.type == pygame.KEYDOWN and - event.mod == 4160 and - event.key == pygame.K_c): - pygame.quit() - sys.exit() +class Screen(FloatLayout): + pass - if context == 'normal': - if event.type == pygame.KEYDOWN: - key = mapping.find_by_key_num(event.key) - if key is not None: - threading.Thread(target=key.do_actions).start() - elif event.type == pygame.MOUSEBUTTONUP: - key = mapping.find_by_collidepoint(pygame.mouse.get_pos()) - if key is not None: - key.list_actions(action_surface) +class MusicSamplerApp(App): + def build(self): + Window.size = (913, 563) - pygame.display.flip() + return Screen() +if __name__ == '__main__': + MusicSamplerApp().run()