]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blob - music_sampler.py
Fix channels and description with blank lines
[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 screen = pygame.display.set_mode(size)
11 screen.fill((250, 250, 250))
12
13 draw_lock = helpers.Lock("draw")
14
15 mapping = helpers.Mapping(screen, draw_lock)
16 channel_number = helpers.parse_config(mapping)
17 pygame.mixer.set_num_channels(channel_number)
18
19 mapping.draw()
20
21 draw_lock.acquire()
22 pygame.display.flip()
23 draw_lock.release()
24
25 contexts = [
26 'normal'
27 ]
28
29 context = 'normal'
30
31 #### Normal workflow ####
32 while 1:
33 event = pygame.event.wait()
34
35 if event.type == pygame.QUIT or (
36 event.type == pygame.KEYDOWN and
37 event.mod == 4160 and
38 event.key == pygame.K_c):
39 for thread in threading.enumerate():
40 if thread.getName()[0:2] != "MS":
41 continue
42 thread.join()
43
44 pygame.quit()
45 sys.exit()
46
47 if context == 'normal':
48 if event.type == pygame.KEYDOWN:
49 key = mapping.find_by_key_num(event.key)
50 if key is not None:
51 threading.Thread(name = "MSKeyAction", target=key.do_actions).start()
52 elif event.type == pygame.MOUSEBUTTONUP:
53 key = mapping.find_by_collidepoint(pygame.mouse.get_pos())
54 if key is not None:
55 threading.Thread(name = "MSClic", target=key.list_actions, args = [screen]).start()
56
57 draw_lock.acquire()
58 pygame.display.flip()
59 draw_lock.release()
60
61 #### In Ipython ####
62 # for thread in threading.enumerate():
63 # if thread.getName()[0:2] != "MS":
64 # continue
65 # thread.join()