-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
55 lines (44 loc) · 1.19 KB
/
main.py
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
import pygame
import pygame.midi
from mopyx import action
from engine import engine
from launchpad import BUTTON_MIXER, Launchpad
from project import project
from ui import App
PROJECT_FILE = 'project.json'
pygame.init()
pygame.midi.init()
clock = pygame.time.Clock()
screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
pad = Launchpad(screen)
try:
project.load(PROJECT_FILE)
engine.initVolume()
clock.tick(1)
app = App(pad)
app.renderUi()
pressedForExit = None
@action
def process() -> bool:
global pressedForExit
for i, v in pad.poll():
if v:
app.buttonPressed(i)
if i == BUTTON_MIXER:
pressedForExit = pygame.time.get_ticks()
else:
app.buttonReleased(i)
if i == BUTTON_MIXER:
pressedForExit = None
engine.update()
if pressedForExit and pygame.time.get_ticks() - pressedForExit > 2000:
return False
return True
while process():
pad.refresh()
pygame.display.flip()
clock.tick(60)
finally:
pad.close()
project.dump(PROJECT_FILE)
pygame.quit()