-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransfer.html
More file actions
57 lines (55 loc) · 2.29 KB
/
transfer.html
File metadata and controls
57 lines (55 loc) · 2.29 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ArduinoMusic 音乐转换工具</title>
<style>
div { margin: 10px 0; }
input { height: 20px; width: 1000px; }
textarea { width: 1000px; height: 100px; }
button { height: 20px; width: 60px; border: 1px solid #333; }
input, textarea, button { border: 1px solid #333; border-radius: 5px; }
img { position: fixed; right: 20px; top: 0; width: 400px; }
</style>
</head>
<body>
<div>音调: 低音5 输入 5., 中音5 输入 5,高音1 输入.1,分节符输入 /,音调间用逗号或空格分隔</div>
<div><input type="text" id="melody" name="melody"></div>
<div>节拍: 1拍音符 0,下加一线输入 1,下加两线输入 2,跟着延音点输入 .,跟着延音线就输入-,分节符输入 /</div>
<div><input type="text" id="pace" name="pace"></div>
<div><button onclick="transfer()">转换</button></div>
<div style="display:none;"><textarea name="debug" id="debug"></textarea></div>
<div><textarea name="result" id="result"></textarea></div>
<div><img src="ex.png" width=></div>
</body>
<script>
melodyMap={
".1":"a", ".2":"b", ".3":"c", ".4":"d", ".5":"e", ".6":"f", ".7":"g",
"1":"1", "2":"2", "3":"3", "4":"4", "5":"5", "6":"6", "7":"7",
"1.":"t", "2.":"u", "3.":"v", "4.":"w", "5.":"x", "6.":"y", "7.":"z",
" ":" ", "0":"0"
}
paceMap={
"0":"1", "0-":"z", "0--":"y", "0---":"x", "0.":"a", "1.":"b", "2.":"c", "1":"2", "2":"3", "3":"4", " ":" "
}
function preformat(s){
return s.replace(/[ ,]+/g,",")
.replace(/[\|\/|\\,]{2,}/g,"/")
.replace(/(\d)(?=\d)/g,"$1,")
.replace(/\//g,", ,")
.replace(/^[ ,]+|[ ,]+$/g,"")
.split(",");
}
function transfer(){
debug.value = [
JSON.stringify(preformat(melody.value)),
JSON.stringify(preformat(pace.value))
].join("\n");
result.value = [
"\"" + "120" + "\",",
"\"" + preformat(melody.value).map(i=>melodyMap[i]).join("") + "\",",
"\"" + preformat(pace.value.replace(/(\.|\-+)/g, "$1 ")).map(i=>paceMap[i]).join("") + "\","
].join("\n");
}
</script>
</html>