aboutsummaryrefslogtreecommitdiff
path: root/music_sampler.py
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2016-06-18 00:29:15 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2016-06-18 00:29:15 +0200
commite7f8dab4980d8a477f305e3565ca3c80abd7d790 (patch)
tree494ecdd65d720825234e220bc9aa798f5fe94859 /music_sampler.py
parent1b79473633242db1c180e07d7165a5bd837eb62e (diff)
downloadMusicSampler-e7f8dab4980d8a477f305e3565ca3c80abd7d790.tar.gz
MusicSampler-e7f8dab4980d8a477f305e3565ca3c80abd7d790.tar.zst
MusicSampler-e7f8dab4980d8a477f305e3565ca3c80abd7d790.zip
Modifications to mapping/keys
Diffstat (limited to 'music_sampler.py')
-rw-r--r--music_sampler.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/music_sampler.py b/music_sampler.py
index 7933d50..6cc49df 100644
--- a/music_sampler.py
+++ b/music_sampler.py
@@ -1,30 +1,29 @@
1import sys 1import sys
2import pygame 2import pygame
3import pydub
4import helpers 3import helpers
4import threading
5 5
6pygame.mixer.pre_init(frequency = 44100) 6pygame.mixer.pre_init(frequency = 44100)
7pygame.init() 7pygame.init()
8 8
9size = width, height = 1024, 600 9size = width, height = 1024, 600
10 10
11helpers.draw_lock.acquire()
11screen = pygame.display.set_mode(size) 12screen = pygame.display.set_mode(size)
12background = pygame.Surface(screen.get_size()) 13mapping = helpers.Mapping(screen)
13background = background.convert()
14background.fill((250, 250, 250))
15 14
16action_surface = pygame.Surface((600, 250)).convert() 15action_surface = pygame.Surface((600, 250)).convert()
17action_surface.fill((0,0,0)) 16action_surface.fill((0,0,0))
18helpers.parse_config() 17helpers.parse_config(mapping)
18helpers.draw_lock.release()
19 19
20for key_name in helpers.Mapping.KEYS: 20mapping.draw()
21 key = helpers.Mapping.KEYS[key_name]
22 key.draw(background)
23 21
24screen.blit(background, (0, 0)) 22helpers.draw_lock.acquire()
25screen.blit(action_surface, (10, 330)) 23screen.blit(action_surface, (10, 330))
26 24
27pygame.display.flip() 25pygame.display.flip()
26helpers.draw_lock.release()
28 27
29contexts = [ 28contexts = [
30 'normal' 29 'normal'
@@ -34,6 +33,7 @@ context = 'normal'
34 33
35while 1: 34while 1:
36 event = pygame.event.wait() 35 event = pygame.event.wait()
36
37 if event.type == pygame.QUIT or ( 37 if event.type == pygame.QUIT or (
38 event.type == pygame.KEYDOWN and 38 event.type == pygame.KEYDOWN and
39 event.mod == 4160 and 39 event.mod == 4160 and
@@ -43,11 +43,11 @@ while 1:
43 43
44 if context == 'normal': 44 if context == 'normal':
45 if event.type == pygame.KEYDOWN: 45 if event.type == pygame.KEYDOWN:
46 key = helpers.Key.find_by_key_num(event.key) 46 key = mapping.find_by_key_num(event.key)
47 if key is not None: 47 if key is not None:
48 key.do_actions() 48 threading.Thread(target=key.do_actions).start()
49 elif event.type == pygame.MOUSEBUTTONUP: 49 elif event.type == pygame.MOUSEBUTTONUP:
50 key = helpers.Key.find_by_collidepoint(pygame.mouse.get_pos()) 50 key = mapping.find_by_collidepoint(pygame.mouse.get_pos())
51 if key is not None: 51 if key is not None:
52 key.list_actions(action_surface) 52 key.list_actions(action_surface)
53 53