-
Notifications
You must be signed in to change notification settings - Fork 5
/
play.js
141 lines (124 loc) · 4.83 KB
/
play.js
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
toast("start");
setScreenMetrics(1080,2160);
const keyMap = {
"A1":[700,200],
"A2":[900,200],
"A3":[1100,200],
"A4":[1300,200],
"A5":[1500,200],
"A6":[700,400],
"A7":[900,400],
"B1":[1100,400],
"B2":[1300,400],
"B3":[1500,400],
"B4":[700,600],
"B5":[900,600],
"B6":[1100,600],
"B7":[1300,600],
"C1":[1500,600],
"0":[0,0]
}; // 琴键位置映射坐标
function pressKeys(keys, duration){ // 按压琴键
console.log("play", keys);
if(keys.length===1){
var site =keyMap[keys[0]];
press(site[0],site[1],duration);
}
else if(keys.length===2){
gestures(
[0,duration,keyMap[keys[0]],keyMap[keys[0]]],
[0,duration,keyMap[keys[1]],keyMap[keys[1]]]
);
}
else{
gestures(
[0,duration,keyMap[keys[0]],keyMap[keys[0]]],
[0,duration,keyMap[keys[1]],keyMap[keys[1]]],
[0,duration,keyMap[keys[2]],keyMap[keys[2]]]
);
}
}
function play(sheets){
var beats = sheets.split(",");
for(var i=0;i<beats.length;i++){
var beat = beats[i];
var keys = beat.split(" ");
console.log(beat);
var duration = keys[0].search('-') == -1 ? 500 : parseFloat(keys[0].split('-')[1]) * 1000;
keys = keys.map(k => k.split('-')[0]);
pressKeys(keys,duration);
}
}
var xihuani = "A3,A4,A1 A5,0,\
A5 B1,A7,A3,A1 A5,A7,A3 B1,A6,0,\
A2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B2,B1";
toast("弹奏大鱼");
play(dayu);
sleep(3000);
toast("弹奏烟花易冷");
play(yanhuayileng);
sleep(3000);
toast("弹奏小情歌");
play(xiaoqingge);
sleep(3000);
toast("弹奏喜欢你");
play(xihuani);
toast("stop");