-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathAudioTrack.js
62 lines (51 loc) · 1.19 KB
/
AudioTrack.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
(function(Timeline){
"use strict";
var Proto;
if(!Timeline){
throw new Error("Timeline Uninitialized");
}
function AudioTrack(tl, wave, id){
var refs = 0;
this.tl = tl;
this.id = id;
this.wave = wave;
tl.tracks.forEach(function(track){
if(track.audioId === id) refs++;
});
this.references = refs;
wave.on('redraw',this.draw.bind(this));
}
Proto = AudioTrack.prototype;
Proto.render = function(){
var view;
if(this.references){
view = this.tl.view;
this.wave.moveToTime(view.startTime,view.endTime);
}
};
Proto.draw = function(){
var id = this.id,
tl = this.tl,
buffer = this.wave.buffer,
width = tl.width,
height = tl.trackHeight,
padding = tl.trackPadding,
top = tl.keyHeight + padding,
ctx = tl.octx;
if(!this.references){ return; }
ctx.save();
ctx.globalAlpha = .5;
tl.tracks.forEach(function(track){
if(track.audioId === id){
ctx.clearRect(0, top, width, height);
if(!track.locked){ ctx.drawImage(buffer, 0, top); }
}
top += height + padding;
});
ctx.restore();
};
Proto.redraw = function(){
if(this.references){ this.wave.redraw(); }
};
Timeline.AudioTrack = AudioTrack;
}(Timeline));