forked from Brinckstah/VirtualVirtuoso
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chord_strum.py
174 lines (133 loc) · 4.91 KB
/
chord_strum.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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import gestures
import single_string_chords
import sound
import gesture_recognition
import pygame
import config
pygame.mixer.init()
def hello_from_the_other_side(result, landmark):
y_coordinate = gesture_recognition.find_y_coordinate(result, landmark)
if landmark == "Thumb":
if config.last_played_y_coordinate >= 0.6:
if y_coordinate <= 0.5:
return True
else:
return False
elif config.last_played_y_coordinate <= 0.5:
if y_coordinate >= 0.6:
return True
else:
return False
elif landmark == "Index":
if config.last_played_y_coordinate > 0.5:
if y_coordinate <= 0.5:
return True
else:
return False
elif config.last_played_y_coordinate < 0.5:
if y_coordinate >= 0.5:
return True
else:
return False
def up_or_down(y_coordinate):
if y_coordinate < 0.5:
return 0
else:
return 1
# Find response based on recognized result
def gesture_response(right_hand_gesture, left_hand_gesture, result):
if right_hand_gesture == 'Thumb_Up':
if not hello_from_the_other_side(result, "Thumb"):
return
y_coordinate = gesture_recognition.find_y_coordinate(result, "Thumb")
direction = up_or_down(y_coordinate)
if left_hand_gesture == 'Victory':
if direction == 0:
sound.channel1.play(sound.Cmaj_Chord)
elif direction == 1:
sound.channel1.play(sound.C_R)
sound.channel2.stop()
sound.channel3.stop()
sound.channel4.stop()
sound.channel5.stop()
sound.channel6.stop()
elif left_hand_gesture == 'ILoveYou':
if direction == 0:
sound.channel1.play(sound.Dmin_Chord)
elif direction == 1:
sound.channel1.play(sound.D_R)
sound.channel2.stop()
sound.channel3.stop()
sound.channel4.stop()
sound.channel5.stop()
sound.channel6.stop()
elif gestures.is_pinky_up(result):
if direction == 0:
sound.channel1.play(sound.Emin_Chord)
elif direction == 1:
sound.channel1.play(sound.E_R)
sound.channel2.stop()
sound.channel3.stop()
sound.channel4.stop()
sound.channel5.stop()
sound.channel6.stop()
elif left_hand_gesture == 'Closed_Fist':
if direction == 0:
sound.channel1.play(sound.Fmaj_Chord)
elif direction == 1:
sound.channel1.play(sound.F_R)
sound.channel2.stop()
sound.channel3.stop()
sound.channel4.stop()
sound.channel5.stop()
sound.channel6.stop()
elif left_hand_gesture == 'Pointing_Up':
if direction == 0:
sound.channel1.play(sound.Gmaj_Chord)
elif direction == 1:
sound.channel1.play(sound.G_R)
sound.channel2.stop()
sound.channel3.stop()
sound.channel4.stop()
sound.channel5.stop()
sound.channel6.stop()
elif left_hand_gesture == 'Open_Palm':
if direction == 0:
sound.channel1.play(sound.Amin_Chord)
elif direction == 1:
sound.channel1.play(sound.A_R)
sound.channel2.stop()
sound.channel3.stop()
sound.channel4.stop()
sound.channel5.stop()
sound.channel6.stop()
elif gestures.is_gesture_L(result):
if direction == 0:
sound.channel1.play(sound.Bdim_Chord)
elif direction == 1:
sound.channel1.play(sound.B_R)
sound.channel2.stop()
sound.channel3.stop()
sound.channel4.stop()
sound.channel5.stop()
sound.channel6.stop()
else:
return
config.last_played_y_coordinate = y_coordinate
elif gestures.is_picking(result):
if left_hand_gesture == 'Victory':
single_string_chords.tone_selector(result, "C")
elif left_hand_gesture == 'ILoveYou':
single_string_chords.tone_selector(result, "D")
elif gestures.is_pinky_up(result):
single_string_chords.tone_selector(result, "E")
elif left_hand_gesture == 'Closed_Fist':
single_string_chords.tone_selector(result, "F")
elif left_hand_gesture == 'Pointing_Up':
single_string_chords.tone_selector(result, "G")
elif left_hand_gesture == 'Open_Palm':
single_string_chords.tone_selector(result, "A")
elif gestures.is_gesture_L(result):
single_string_chords.tone_selector(result, "B")
else:
return