forked from romgere/romgerebox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbox-track.js
138 lines (100 loc) · 2.84 KB
/
box-track.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
import Component from '@ember/component';
import { alias, notEmpty } from '@ember/object/computed';
import { isEmpty } from '@ember/utils';
import { inject as service } from '@ember/service';
import Constants from 'romgerebox/constants';
export default Component.extend({
audioService : service('audio'),
classNames: ['boxTrack', 'layout-col', 'flex-nogrow'],
classNameBindings: ['sampleColor', 'dragPending','hasSample'],
sampleColor: alias('sample.color'),
sampleIcon: alias('sample.icon'),
hasSample: notEmpty('sample'),
//Sample to play
sample: null,
dragPending: false,
mute: alias('sample.mute'),
solo: false,
volume : alias('sample.volume'),
maxVolume: Constants.MAX_TRACK_VOLUME,
//Register to parent
didReceiveAttrs() {
this.get('boxMain').registerBoxTrack( this);
},
clearCurrentSample: function(){
let sample = this.get('sample')
this.set('sample', null);
this.get('boxMain').sampleChangedForTrack( this, null);
sample.set('isUsed', false);
sample.stop();
this.get('boxMain').endSoloForTrack();
this.set('solo', false);
this.setMuteState( false);
},
setMuteState: function( mute ){
if( isEmpty(this.get('sample'))){
return;
}
this.get('sample').set('mute', mute);
this.set('solo', false);
},
setSample: function( sample){
if( this.get('sample') ){
this.clearCurrentSample();
}
this.set('sample', sample);
this.get('boxMain').sampleChangedForTrack( this, sample);
sample.set('isUsed', true);
},
actions:{
play: function( params ){
if( isEmpty(this.get('sample'))){
return;
}
if( params.isLoopSideA || ! this.get('sample.doubleSample')){
this.get('sample').play( params.startTime);
}
//deal with loopB on double sample
else{
this.get('sample').play( params.startTime + params.loopTime);
}
},
stop: function(){
if( isEmpty(this.get('sample'))){
return;
}
this.get('sample').stop();
},
onDragSample: function( sample ){
this.setSample( sample);
},
onOverAction: function(){
this.set('dragPending', true);
},
onDragOutAction: function(){
this.set('dragPending', false);
},
muteToggle: function(){
this.setMuteState( ! this.get('mute'));
},
soloAction: function(){
if( this.get('solo') ){
this.get('boxMain').endSoloForTrack();
this.set('solo', false);
this.setMuteState( false);
}
else{
this.setMuteState( false);
this.get('boxMain').askForSoloForTrack( this.get('sample'));
this.set('solo', true);
}
},
//Mute from parent (for other track solo)
mute: function( mute){
this.setMuteState( mute);
},
removeAction: function(){
this.clearCurrentSample();
},
}
});