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