-
Notifications
You must be signed in to change notification settings - Fork 1
/
runner.py
151 lines (119 loc) · 8.55 KB
/
runner.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
from flask import Flask
from flask import request
from flask import render_template
import alankar
import player
app = Flask(__name__)
@app.route('/')
def my_form():
return render_template("index.html") # this should be the name of your html file
@app.route('/', methods=['POST'])
def my_form_post():
text1 = request.form['text1']
text2 = request.form['text2']
text3 = request.form['text3']
text4 = request.form['text4']
text5 = request.form.getlist('notation')
output = "".join(["<!DOCTYPE html> <html lang='en'> <head> <meta charset='UTF-8'> <meta name='viewport' content='width=device-width, initial-scale=1'>",
'<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">',
'<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato">',
'<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Montserrat">',
'<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">',
'<style> body,h1,h2,h3,h4,h5,h6 {font-family: "Lato", sans-serif} .w3-bar,h1,button {font-family: "Montserrat", sans-serif}',
'.fa-anchor,.fa-coffee {font-size:200px}</style></head><body bgcolor = "FFBFAA">',
'<style> #alankar {color: blue} #alankar:hover {color: red} </style>',
'<center> <p></p><div style = "width: 95%; border: 1px solid #996955" id = "form" ><h1> Raag Alankar Generator',
'</h1><form action="/" method="POST">',
'<table> <tr>',
'<td> <label> <strong> Raag: </strong> </label> </td> <td> <input id="auto" autocomplete = "off" type="text" name="text1" placeholder = "Raag" value = "' + text1 + '"> </td> </tr>',
'<tr> <td> <label> <strong> Number: </strong> </label> </td> <td> <input type="number" name="text2" placeholder = "#" min = "1" max = "15" value = "' + text2 + '"> </td></tr>',
'<tr> <td> <label> <strong> Key: </strong> </label> </td> <td> <select name="text3" placeholder = "Key">'])
for option in ["A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"]:
if text3 == option:
output += '<option value = "' + option + '" selected>' + option + '</option>'
else:
output += '<option value = "' + option + '">' + option + '</option>'
output += "".join([
'</select> </td></tr>',
'<tr> <td> <label> <strong> Speed: </strong> </label> </td><td> <input type="number" name="text4" placeholder = "B/M" min = "10" max = "500" value = "' + text4 + '"> </td> </tr>',
'<tr> <td> <input type="radio" id="indian" name="notation" value="indian"> <label for="indian">Indian Notation </label> </td>',
'<td> <input type="radio" id="solfege" name="notation" value="solfege"> <label for="solfege">Solfege Notation</label> </td> </tr> </table><br/>',
'<input type="submit" name="my-form" value="Get Alankars"> <input type="reset" value = "Last Query"> <p></p></form></div></center>',
'<script src="../static/auto.js"></script>',
'<script src="../static/simpletones.js"></script>',
'<script> autocomplete(document.getElementById("auto"), raags); </script>',
'<center><div style = "width:95%; border: 1px solid #996955" id = "form" ><p></p>'])
try:
asc, desc, comp = alankar.alankar(text1, int(text2))
ps = player.playstring("".join(asc[0]), text3, int(text4), asc = True)
except Exception as e:
print(e)
output += "Invalid Input. <p></p></div></center>"
output += '<center><div style = "width: 75%;" id = "notes"><p style = "font-size:8px;"> <em>The majority of Raags are vakra - that is, they do not have a very direct Aaroha and Avroha. These Raags are marked in <span style = "color:#AA0000"> red </span>, and the algorithm will for some lengths of alankar return "Memory Overload" reflecting too many different permutations to compute. Raags marked in <span style = "color:#996600"> yellow </span> will always return, but 50 or more potential alankars might be returned. Raags in black are known to have a maximum of 10 different options for each length. Don\'t consider the returned alankars in the vakra Raags as gospel - they are, at best, the beginnings of the development of a palta. </em></p>'
output += '</div></center></body></html>'
return output
if comp == -1:
output += str("Raag <strong>" + text1 + "</strong> not found" + "<p></p></div></center></body></html>")
return output
elif comp == 0:
output += str("Raag <strong>" + text1 + "</strong> has an invalid aaroha/avroha in our database, given by <br/>" + str(asc) + "; <br/>" +
str(desc) + "<p></p></div></center>")
output += '<center><div style = "width: 75%;" id = "notes"><p style = "font-size:8px;"> <em>The majority of Raags are vakra - that is, they do not have a very direct Aaroha and Avroha. These Raags are marked in <span style = "color:#AA0000"> red </span>, and the algorithm will for some lengths of alankar return "Memory Overload" reflecting too many different permutations to compute. Raags marked in <span style = "color:#996600"> yellow </span> will always return, but 50 or more potential alankars might be returned. Raags in black are known to have a maximum of 10 different options for each length. Don\'t consider the returned alankars in the vakra Raags as gospel - they are, at best, the beginnings of the development of a palta. </em></p>'
output += '</div></center></body></html>'
return output
else:
if len(asc) > 1:
output += "Multiple options for Raag <strong>" + text1 + "</strong>, ascending Alankar " + text2 + ". Options Below: <br/>"
else:
output += "Raag <strong>" + text1 + "</strong> ascending Alankar " + text2 + ": <br/>"
for i in range(len(asc)):
#print(asc[i])
playable = "".join(asc[i])
ps = player.playstring(playable, text3, int(text4), asc = True)
if ps is not None:
output += "\n<p onclick = " + ps + " style='display:inline' id= 'alankar'>"
else:
output += "<p id= 'alankar' style='display:inline'>"
output += transform(asc[i], text5)
output += "</p><br/>"
output += "<br/>"
if len(desc) > 1:
output += "Multiple options for Raag <strong>" + text1 + "</strong>, descending Alankar " + text2 + ". Options Below: <br/>"
else:
output += "Raag <strong>" + text1 + "</strong> descending Alankar " + text2 + ": <br/>"
for i in range(len(desc)):
playable = "".join(desc[i])
ps = player.playstring(playable, text3, int(text4), asc = False)
if ps is not None:
output += "<p onclick = " + ps + " style='display:inline' id= 'alankar'>"
else:
output += "<p style='display:inline' id= 'alankar'>"
output += transform(desc[i], text5)
output += "</p><br/>"
output += "<br/>" + "<p style = 'color:black'><em>Click any of the provided alankars to listen to them.</em></p><p></p></div></center>"
output += '<center><div style = "width: 75%;" id = "notes"><p style = "font-size:8px;"> <em>The majority of Raags are vakra - that is, they do not have a very direct Aaroha and Avroha. These Raags are marked in <span style = "color:#AA0000"> red </span>, and the algorithm will for some lengths of alankar return "Memory Overload" reflecting too many different permutations to compute. Raags marked in <span style = "color:#996600"> yellow </span> will always return, but 50 or more potential alankars might be returned. Raags in black are known to have a maximum of 10 different options for each length. Don\'t consider the returned alankars in the vakra Raags as gospel - they are, at best, the beginnings of the development of a palta. </em></p>'
output += '</div></center></body></html>'
#print(output)
return output
def transform(q, text):
if len(text) == 0 or text[0] == "indian":
return " ".join(q)
trans = {"S": "Do", "R": "Re", "r": "re", "G": "Mi", "g": "mi", "M": "Fa", "m": "fa", "P": "So", "D": "La", "d": "la", "N": "Ti", "n": "ti"}
ss = []
for j in q:
s = ""
idx = 0
for i in j:
if i in trans:
s += trans[i]
else:
s += i
if idx == len(j) - 1:
pass
else:
s += "-"
idx += 1
ss.append(s)
return ", ".join(ss)
if __name__ == '__main__':
app.run()