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