-
Notifications
You must be signed in to change notification settings - Fork 0
/
jouerPianoExtension.js
120 lines (108 loc) · 2.99 KB
/
jouerPianoExtension.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
// create by scratch3-extension generator
const ArgumentType = Scratch.ArgumentType;
const BlockType = Scratch.BlockType;
const formatMessage = Scratch.formatMessage;
const log = Scratch.log;
const menuIconURI = null;
const blockIconURI = null;
class jouerPianoExt{
constructor() {
}
// constructor (runtime){
// this.runtime = runtime;
// // communication related
// this.comm = runtime.ioDevices.comm;
// this.session = null;
// this.runtime.registerPeripheralExtension("jouerPianoExt", this);
// // session callbacks
// this.reporter = null;
// this.onmessage = this.onmessage.bind(this);
// this.onclose = this.onclose.bind(this);
// this.write = this.write.bind(this);
// // string op
// this.decoder = new TextDecoder();
// this.lineBuffer = "";
// }
// onclose (){
// this.session = null;
// }
// write (data, parser = null){
// if (this.session){
// return new Promise(resolve => {
// if (parser){
// this.reporter = {
// parser,
// resolve
// }
// }
// this.session.write(data);
// })
// }
// }
// onmessage (data){
// const dataStr = this.decoder.decode(data);
// this.lineBuffer += dataStr;
// if (this.lineBuffer.indexOf("\n") !== -1){
// const lines = this.lineBuffer.split("\n");
// this.lineBuffer = lines.pop();
// for (const l of lines){
// if (this.reporter){
// const {parser, resolve} = this.reporter;
// resolve(parser(l));
// };
// }
// }
// }
// scan (){
// this.comm.getDeviceList().then(result => {
// this.runtime.emit(this.runtime.constructor.PERIPHERAL_LIST_UPDATE, result);
// });
// }
getInfo (){
return {
id: "jouerPianoExt",
name: "Piano",
color1: "#b8e986",
color2: "#b8e986",
menuIconURI: menuIconURI,
blockIconURI: blockIconURI,
blocks: [
{
opcode: "jouerPiano",
blockType: BlockType.COMMAND,
text: "jouer piano"
}
]
}
}
jouerPiano (args, util){
while (true) {
if (this.mouse.down) {
if (this.mouse.x > -250 && this.mouse.x < -180) {
yield* this.startSound("C Piano");
}
if (this.mouse.x > -180 && this.mouse.x < -110) {
yield* this.startSound("D Piano");
}
if (this.mouse.x > -110 && this.mouse.x < -40) {
yield* this.startSound("E Piano");
}
if (this.mouse.x > -40 && this.mouse.x < 30) {
yield* this.startSound("F Piano");
}
if (this.mouse.x > 30 && this.mouse.x < 100) {
yield* this.startSound("G Piano");
}
if (this.mouse.x > 100 && this.mouse.x < 170) {
yield* this.startSound("A Piano");
}
if (this.mouse.x > 170 && this.mouse.x < 240) {
yield* this.startSound("B Piano");
}
}
yield;
}
}
}
// module.exports = jouerPianoExt;
Scratch.extensions.register(new jouerPianoExt())