-
Notifications
You must be signed in to change notification settings - Fork 4
/
actionbinder.js
39 lines (30 loc) · 1.26 KB
/
actionbinder.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
//动作助手
class ActionBinder{
constructor(mb,setting){
this.tapeListener = this._init_tape_drag_listener(mb,setting);
this._init_tape_click_listener(mb,setting,this.tapeListener);
mb._jGE.add(this.tapeListener);
}
_init_tape_drag_listener(mb,setting){
let [w,h]=MLC.get_tape_drag_area(setting);
let pu = new $tk_path({styleType:'stroke',style:"red 1" ,points:[[0,0],[w,0],[w,h],[0,h],-1],pos:MLC.get_tape_drag_pos(setting)});
let k = new Key({code:"tapeAction",upObjs:[pu]});
DragHelper.InitDrag(k,{
startCallback:mb.tape.DragStart.bind(mb.tape)
,moveCallback:mb.tape.DragHandler.bind(mb.tape)
,scrollCallback:mb.tape.ScrollHandler.bind(mb.tape)
})
let kb = new Keyboard(mb._jGE);
kb.SetPos({x:setting.tape.pos.x,y:0});
kb.add(k);
return kb;
}
_init_tape_click_listener(mb,setting,tapeListener){
tapeListener.get("tapeAction").addEventListener("keyup",(x)=>{
let p = MLC.get_tape_point_from_pos(x.x,x.y,setting,mb.tape);
if(p == null) return;
if(p.time<0 || p.syllable<0 || p.syllable >=30) return;
mb._jGE.broadcast("MusicBox.Add.Music",p);
});
}
}