-
Notifications
You must be signed in to change notification settings - Fork 0
/
screenMoodSelect.py
85 lines (75 loc) · 3.71 KB
/
screenMoodSelect.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
#screen to select mood with buttons
import colors
from musicGen import *
from musicJud import *
##helper function
def getButCoords(cX, cY, w, h): #returns SX, SY, EX, EY respectively
butSX = cX - w
butSY = cY - h
butEX = cX + w
butEY = cY + h
return butSX, butSY, butEX, butEY
##data components
def dataScreenMoodSel(data):
#mood selection buttons, [happy, sad, powerful, peaceful]
data.moodButnX = [data.width//4, data.width*3//4, data.width//4, data.width*3//4]
data.moodButnY = [data.height-160, data.height-160, data.height-85, data.height-85]
data.moodButnW = data.width*2//5
data.moodButnH = data.height//8
data.moodButnColors = [colors.butnMoodHap, colors.butnMoodSad,
colors.butnMoodPow, colors.butnMoodPea]
data.moodButnText = ["happy", "sad", "powerful", "peaceful"]
#back button
data.moodSelBackButnX = data.width//11
data.moodSelBackButnY = data.height//12
data.moodSelBackButnW = data.width//7
data.moodSelBackButnH = data.height/11
##event-related components
def mouseScreenMoodSel(event, data):
#handle back button
butSX, butSY, butEX, butEY = getButCoords(data.moodSelBackButnX, data.moodSelBackButnY,
data.moodSelBackButnW//2, data.moodSelBackButnH//2)
if event.x > butSX and event.x < butEX and event.y > butSY and event.y < butEY:
data.state = 0
playRandomNote()
play_music('pitch.mid', 1)
#handle four mood buttons
for i in range(4):
butSX, butSY, butEX, butEY = getButCoords(data.moodButnX[i],
data.moodButnY[i], data.moodButnW//2, data.moodButnH//2)
if event.x > butSX and event.x < butEX and event.y > butSY and event.y < butEY:
data.state = 2
data.answered = 0
data.mood = i
# print(data.moodButnText[data.mood])
data.playing = 1
break
if data.state == 2:
data.startLet, data.majorBool, data.chordProg, data.melodyRhyth, \
data.melodyPitches = generateNewMusic(data.mood)
while judgeMusic(data.startLet, data.majorBool, data.chordProg, \
data.melodyRhyth, data.melodyPitches) != data.mood:
data.startLet, data.majorBool, data.chordProg, data.melodyRhyth, \
data.melodyPitches = generateNewMusic(data.mood)
play_music('output.mid', 100000)
data.playing = 1
##draw components
def drawScreenMoodSel(canvas, data):
#instructions
canvas.create_text(data.width//2, data.height//3, text = "Select your mood",
fill = colors.textGrey, font = "system 40")
#back button
butnSX, butnSY, butnEX, butnEY = getButCoords(data.moodSelBackButnX,
data.moodSelBackButnY, data.moodSelBackButnW//2, data.moodSelBackButnH//2)
canvas.create_rectangle(butnSX, butnSY, butnEX, butnEY,
fill = colors.buttonStartBlack, width = 0)
canvas.create_text(data.moodSelBackButnX, data.moodSelBackButnY,
text = "back", fill = colors.greys[2], font = "system 20")
for i in range(4): #four mood buttons
butSX, butSY, butEX, butEY = getButCoords(data.moodButnX[i],
data.moodButnY[i], data.moodButnW//2, data.moodButnH//2)
color = data.moodButnColors[i]
txt = data.moodButnText[i]
canvas.create_rectangle(butSX, butSY, butEX, butEY, fill = colors.buttonStartBlack)
canvas.create_text(data.moodButnX[i], data.moodButnY[i], text = txt,
fill = color, font = "system 20")