-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSimpleUI.py
More file actions
126 lines (97 loc) · 4.4 KB
/
SimpleUI.py
File metadata and controls
126 lines (97 loc) · 4.4 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
'''
A simple UI
'''
from SimpleListener import SimpleListener
from SuperConductorModel import SuperConductorModel
from AbstractView import AbstractView
import pygame, sys, Leap, Player
class SimpleUI():
def __init__(self, model):
model.register_track_listener(self.update_track)
model.register_current_note_listener(self.update_note)
model.register_volume_listener(self.update_volume)
model.register_pitch_listener(self.update_pitch)
model.register_speed_listener(self.update_speed)
model.register_instrument_listener(self.update_instrument)
model.register_control_listener(self.update_control)
self.windowWidth = 600
self.windowHeight = 300
#self.gesture = "None"
self.control = "None"
self.defaultColor = (255, 255, 255)
self.highlightColor = (125, 125, 125)
#self.gestureList = ("swipe", "key tap", "screen_tap", "Up", "Down", "circle clockwise", "circle counterclockwise")
self.controlVal = {'volume':0, 'pitch':0, 'track':0, 'speed':0, 'insutrment':0, 'note':0}
pygame.init()
self.window = pygame.display.set_mode((self.windowWidth, self.windowHeight))
pygame.display.set_caption("Simple UI")
#Surface
self.background = pygame.Surface(self.window.get_size())
self.background = self.background.convert()
self.background.fill ((50,0,80))
# Create a sample listener and controller
self.listener = SimpleListener()
self.listener.set_model(model)
self.controller = Leap.Controller()
# Have the sample listener receive events from the controller
self.controller.add_listener(self.listener)
def callbackfunc(self, control, val):
self.control = control
self.controlVal[control] = val
def update_volume(self, volume_level):
Player.velocity_offset(volume_level)
self.controlVal['volume'] = volume_level
def update_pitch(self, pitch_level):
Player.pitch_offset(pitch_level)
self.controlVal['pitch'] = pitch_level
def update_track(self, track_name):
self.controlVal['track'] = track_name
def update_speed(self, speed_level):
self.controlVal['speed'] = speed_level
def update_instrument(self, instrument_number):
self.controlVal['instrument'] = instrument_number
def update_note(self, note_number):
self.controlVal['note'] = note_number
def update_control(self, control_name):
self.control = control_name
#Application Loop
def main(self):
#clock = pygame.time.Clock()
self.window.blit(self.background, (0,0))
while True:
#clock.tick(60)
#Handle Input Events
for event in pygame.event.get():
if event.type == pygame.QUIT:
print "quit"
sys.exit()
# Remove the sample listener when done
self.controller.remove_listener(self.listener)
break
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
# user pressed ESC
sys.exit()
# Remove the sample listener when done
self.controller.remove_listener(self.listener)
break
self.window.blit(self.background, (0,0))
font = pygame.font.Font(None, 36)
intX = 0
intY = 0
for n in self.controlVal.keys():
if n == self.control:
text = font.render("%s" % n, 1, self.highlightColor, (255, 255, 255))
else:
text = font.render("%s" % n, 1, self.defaultColor)
self.window.blit(text, (intX,intY))
text = font.render("{0} ".format(self.controlVal[n]), 1, self.defaultColor)
self.window.blit(text, (150,intY))
intY += 50
pygame.display.flip()
pygame.quit()
if __name__ == "__main__":
m = SuperConductorModel()
ui = SimpleUI(m)
Player.midistart("songs\miley_cyrus-wrecking_ball.mid")
ui.main()