X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=music_sampler.py;h=c17f7bff98d1764704ee542ef9a1004aa1151f8b;hb=425dd061bf64a8304ec96aec870b0e2e24fa44f4;hp=9f14d561fe127c419f4b0955f5f05ad78ee1b1ca;hpb=be27763f8be0f647cbe17ecee8c782901ce2cede;p=perso%2FImmae%2FProjets%2FPython%2FMusicSampler.git diff --git a/music_sampler.py b/music_sampler.py index 9f14d56..c17f7bf 100644 --- a/music_sampler.py +++ b/music_sampler.py @@ -6,24 +6,21 @@ import threading pygame.mixer.pre_init(frequency = 44100) pygame.init() -size = width, height = 1024, 600 - -helpers.draw_lock.acquire() +size = width, height = 913, 563 screen = pygame.display.set_mode(size) -mapping = helpers.Mapping(screen, helpers.draw_lock) +screen.fill((229, 228, 226)) -action_surface = pygame.Surface((600, 250)).convert() -action_surface.fill((0,0,0)) -helpers.parse_config(mapping) -helpers.draw_lock.release() +draw_lock = helpers.Lock("draw") -mapping.draw() +mapping = helpers.Mapping(screen, draw_lock) +channel_number, open_files = helpers.parse_config(mapping) +pygame.mixer.set_num_channels(channel_number) -helpers.draw_lock.acquire() -screen.blit(action_surface, (10, 330)) +mapping.draw() +draw_lock.acquire() pygame.display.flip() -helpers.draw_lock.release() +draw_lock.release() contexts = [ 'normal' @@ -31,6 +28,7 @@ contexts = [ context = 'normal' +#### Normal workflow #### while 1: event = pygame.event.wait() @@ -39,7 +37,7 @@ while 1: event.mod == 4160 and event.key == pygame.K_c): for thread in threading.enumerate(): - if thread is threading.current_thread(): + if thread.getName()[0:2] != "MS": continue thread.join() @@ -49,12 +47,40 @@ while 1: 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() + if key is not None and not key.disabled: + threading.Thread(name = "MSKeyAction", target=key.do_actions).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: - key.list_actions(action_surface) + threading.Thread(name = "MSClic", target=key.list_actions, args = [screen]).start() + + draw_lock.acquire() + police = helpers.font(14) + icon_police = helpers.font(14, font = "Symbola") + + 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)) pygame.display.flip() + draw_lock.release() +#### In Ipython #### +# for thread in threading.enumerate(): +# if thread.getName()[0:2] != "MS": +# continue +# thread.join()