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