X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FProjets%2FPython%2FMusicSampler.git;a=blobdiff_plain;f=music_sampler.py;h=c10b6349701210a2ce583bb88543559a6fb0dd4f;hp=6cc49dff4884a7f0391f796ddd097321afe146b0;hb=201d8411d7e1f70f13ced3fc797a696e6593f3a0;hpb=e7f8dab4980d8a477f305e3565ca3c80abd7d790 diff --git a/music_sampler.py b/music_sampler.py index 6cc49df..c10b634 100644 --- a/music_sampler.py +++ b/music_sampler.py @@ -1,55 +1,89 @@ -import sys -import pygame import helpers -import threading -pygame.mixer.pre_init(frequency = 44100) -pygame.init() +helpers.parse_args() -size = width, height = 1024, 600 +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 -helpers.draw_lock.acquire() -screen = pygame.display.set_mode(size) -mapping = helpers.Mapping(screen) +class KeyList(RelativeLayout): + keylist = ListProperty([]) + first_key = StringProperty("") + second_key = StringProperty("") + third_key = StringProperty("") -action_surface = pygame.Surface((600, 250)).convert() -action_surface.fill((0,0,0)) -helpers.parse_config(mapping) -helpers.draw_lock.release() + def append(self, value): + self.keylist.insert(0, value) -mapping.draw() + def on_keylist(self, instance, new_key_list): + if len(self.keylist) > 0: + self.first_key = self.keylist[0] + if len(self.keylist) > 1: + self.second_key = self.keylist[1] + if len(self.keylist) > 2: + self.third_key = self.keylist[2] -helpers.draw_lock.acquire() -screen.blit(action_surface, (10, 330)) +class PlayList(RelativeLayout): + playlist = ListProperty([]) -pygame.display.flip() -helpers.draw_lock.release() + def __init__(self, **kwargs): + super(PlayList, self).__init__(**kwargs) + Clock.schedule_interval(self.update_playlist, 0.5) -contexts = [ - 'normal' -] + def update_playlist(self, dt): + if self.parent is None or 'Mapping' not in self.parent.ids: + return True -context = 'normal' + open_files = self.parent.ids['Mapping'].open_files + self.playlist = [] + for music_file in open_files.values(): + if not music_file.is_in_use(): + continue -while 1: - event = pygame.event.wait() + text = "{}/{}".format( + helpers.duration_to_min_sec(music_file.sound_position), + helpers.duration_to_min_sec(music_file.sound_duration)) - if event.type == pygame.QUIT or ( - event.type == pygame.KEYDOWN and - event.mod == 4160 and - event.key == pygame.K_c): - pygame.quit() - sys.exit() + if music_file.is_loaded_paused(): + self.playlist.append(["⏸", music_file.name, text, False]) + else: + self.playlist.append(["⏵", music_file.name, text, True]) - 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) - pygame.display.flip() +class ActionList(RelativeLayout): + action_title = StringProperty("") + action_list = ListProperty([]) + def update_list(self, key, action_descriptions): + self.action_title = "actions linked to key {}:".format(key.key_sym) + self.action_list = [] + + for [action, status] in action_descriptions: + if status == "done": + icon = "✓" + elif status == "current": + icon = "✅" + else: + icon = " " + self.action_list.append([icon, action]) + +class Screen(FloatLayout): + pass + +class MusicSamplerApp(App): + def build(self): + Window.size = (913, 563) + + return Screen() + +if __name__ == '__main__': + Builder.load_file(helpers.path() + "/music_sampler.kv") + MusicSamplerApp().run()