]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blame_incremental - music_sampler.py
Fix channels and description with blank lines
[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)
16channel_number = helpers.parse_config(mapping)
17pygame.mixer.set_num_channels(channel_number)
18
19mapping.draw()
20
21draw_lock.acquire()
22pygame.display.flip()
23draw_lock.release()
24
25contexts = [
26 'normal'
27]
28
29context = 'normal'
30
31#### Normal workflow ####
32while 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()