aboutsummaryrefslogtreecommitdiff
path: root/music_sampler.py
blob: 9797c918073f4baa8033f85634b9c5163efc34e9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import sys

if getattr(sys, 'frozen', False):
    os.chdir(sys._MEIPASS)

import pygame
import pydub
import helpers

pygame.mixer.pre_init(frequency = 44100)
pygame.init()

size = width, height = 1024, 600

screen = pygame.display.set_mode(size)
background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill((250, 250, 250))

action_surface = pygame.Surface((600, 250)).convert()
action_surface.fill((0,0,0))
helpers.parse_config()

for key_name in helpers.Mapping.KEYS:
    key = helpers.Mapping.KEYS[key_name]
    key.draw(background)

screen.blit(background, (0, 0))
screen.blit(action_surface, (10, 330))

pygame.display.flip()

contexts = [
    'normal'
]

context = 'normal'

while 1:
    event = pygame.event.wait()
    if event.type == pygame.QUIT or (
            event.type == pygame.KEYDOWN and 
            event.mod  == 4160 and
            event.key  == pygame.K_c):
        pygame.quit()
        sys.exit()

    if context == 'normal':
        if event.type == pygame.KEYDOWN:
            key = helpers.Key.find_by_key_num(event.key)
            if key is not None:
                key.do_actions()
        elif event.type == pygame.MOUSEBUTTONUP:
            key = helpers.Key.find_by_collidepoint(pygame.mouse.get_pos())
            if key is not None:
                key.list_actions(action_surface)

    pygame.display.flip()