]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blob - music_sampler.py
Move classes to separate file
[perso/Immae/Projets/Python/MusicSampler.git] / music_sampler.py
1 import sys
2 import pygame
3 import helpers
4 import threading
5
6 pygame.mixer.pre_init(frequency = 44100)
7 pygame.init()
8
9 size = width, height = 1024, 600
10
11 helpers.draw_lock.acquire()
12 screen = pygame.display.set_mode(size)
13 mapping = helpers.Mapping(screen, helpers.draw_lock)
14
15 action_surface = pygame.Surface((600, 250)).convert()
16 action_surface.fill((0,0,0))
17 helpers.parse_config(mapping)
18 helpers.draw_lock.release()
19
20 mapping.draw()
21
22 helpers.draw_lock.acquire()
23 screen.blit(action_surface, (10, 330))
24
25 pygame.display.flip()
26 helpers.draw_lock.release()
27
28 contexts = [
29 'normal'
30 ]
31
32 context = 'normal'
33
34 while 1:
35 event = pygame.event.wait()
36
37 if event.type == pygame.QUIT or (
38 event.type == pygame.KEYDOWN and
39 event.mod == 4160 and
40 event.key == pygame.K_c):
41 for thread in threading.enumerate():
42 if thread is threading.current_thread():
43 continue
44 thread.join()
45
46 pygame.quit()
47 sys.exit()
48
49 if context == 'normal':
50 if event.type == pygame.KEYDOWN:
51 key = mapping.find_by_key_num(event.key)
52 if key is not None:
53 threading.Thread(target=key.do_actions).start()
54 elif event.type == pygame.MOUSEBUTTONUP:
55 key = mapping.find_by_collidepoint(pygame.mouse.get_pos())
56 if key is not None:
57 key.list_actions(action_surface)
58
59 pygame.display.flip()
60