]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blob - music_sampler.py
Move files
[perso/Immae/Projets/Python/MusicSampler.git] / music_sampler.py
1 import sys
2
3 if getattr(sys, 'frozen', False):
4 os.chdir(sys._MEIPASS)
5
6 import pygame
7 import pydub
8 import helpers
9
10 pygame.mixer.pre_init(frequency = 44100)
11 pygame.init()
12
13 size = width, height = 1024, 600
14
15 screen = pygame.display.set_mode(size)
16 background = pygame.Surface(screen.get_size())
17 background = background.convert()
18 background.fill((250, 250, 250))
19
20 action_surface = pygame.Surface((600, 250)).convert()
21 action_surface.fill((0,0,0))
22 helpers.parse_config()
23
24 for key_name in helpers.Mapping.KEYS:
25 key = helpers.Mapping.KEYS[key_name]
26 key.draw(background)
27
28 screen.blit(background, (0, 0))
29 screen.blit(action_surface, (10, 330))
30
31 pygame.display.flip()
32
33 contexts = [
34 'normal'
35 ]
36
37 context = 'normal'
38
39 while 1:
40 event = pygame.event.wait()
41 if event.type == pygame.QUIT or (
42 event.type == pygame.KEYDOWN and
43 event.mod == 4160 and
44 event.key == pygame.K_c):
45 pygame.quit()
46 sys.exit()
47
48 if context == 'normal':
49 if event.type == pygame.KEYDOWN:
50 key = helpers.Key.find_by_key_num(event.key)
51 if key is not None:
52 key.do_actions()
53 elif event.type == pygame.MOUSEBUTTONUP:
54 key = helpers.Key.find_by_collidepoint(pygame.mouse.get_pos())
55 if key is not None:
56 key.list_actions(action_surface)
57
58 pygame.display.flip()
59