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