-
Notifications
You must be signed in to change notification settings - Fork 4
/
clip_manager.js
192 lines (158 loc) · 3.31 KB
/
clip_manager.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
outlets = 2;
var _track;
var _colors = { "off":0, "orange":96, "green":75, };
var _clipSlots = new Array(8);
var _nbClips = 0;
var _hasClipCallBackArray = [ hasClip_1_CallBack, hasClip_2_CallBack, hasClip_3_CallBack, hasClip_4_CallBack, hasClip_5_CallBack, hasClip_6_CallBack, hasClip_7_CallBack, hasClip_8_CallBack ];
var _selectedClip = 0;
var _observedTrack = 0;
function init()
{
post("init with observedTrack :", _observedTrack, "\n");
_track = new LiveAPI(clipSlotCallback, "live_set tracks " + _observedTrack.toString());
if(!_track){
post("no api object tracks\n");
return;
}
_track.property = "clip_slots";
}
function focus()
{
for(i=0; i < _nbClips; i++){
if(_clipSlots[i].get("has_clip") == 1)
setColor(i+100, "orange");
}
if(_selectedClip != 0)
setColor(_selectedClip + 99,"green");
}
function delete_clip(clip)
{
if( _clipSlots[clip] == null)
return;
_clipSlots[clip].call("delete_clip");
}
function set_track(arg)
{
post("Clip Manager set track with ", arg, "\n");
setSelectedClip(0);
_observedTrack = arg;
init();
}
function list()
{
var a = arrayfromargs(arguments);
if(a[1] == 0)
{
post(a[0]);
if( _clipSlots[a[0]-1] == null)
return;
//Set old clip to orange
if(_selectedClip != 0)
setColor(_selectedClip + 99, "orange");
setSelectedClip(a[0]);
if(_clipSlots[a[0]-1].get("has_clip") == 0){
_clipSlots[a[0]-1].call("create_clip",8);
}
setColor(_selectedClip + 99, "green");
}
}
function setSelectedClip(value)
{
_selectedClip = value;
outlet(1,"clip_change",value - 1);
}
function processHasClip(clip, state)
{
if(_selectedClip == clip){
outlet(1,"refresh_seq");
if(state == 0)
{
setColor(_selectedClip + 99,"off");
setSelectedClip(0);
}
return;
}
switch(state){
case 0:
setColor(clip+99, "off");
break;
case 1:
setColor(clip+99, "orange");
break;
}
}
function clipSlotCallback(args)
{
if(args[0] != "clip_slots")
return;
//Args form is : clip_slots id 1 id 2 id 3 ...
_nbClips = (args.length -1)/2;
if(_nbClips > 8)
_nbClips = 8;
_clipSlots.length = 0;
_clipSlots.length = 8;
for(i = 0; i< 8; i++){
if(i <= _nbClips){
_clipSlots[i] = new LiveAPI(_hasClipCallBackArray[i],"live_set tracks "+ _observedTrack.toString() + " clip_slots " + i.toString());
_clipSlots[i].property = "has_clip";
}
else
{
_clipSlots[i] = null;
}
}
}
function hasClip_1_CallBack(args)
{
if(args[0] != "has_clip")
return;
processHasClip(1, args[1]);
}
function hasClip_2_CallBack(args)
{
if(args[0] != "has_clip")
return;
processHasClip(2, args[1]);
}
function hasClip_3_CallBack(args)
{
if(args[0] != "has_clip")
return;
processHasClip(3, args[1]);
}
function hasClip_4_CallBack(args)
{
if(args[0] != "has_clip")
return;
processHasClip(4, args[1]);
}
function hasClip_5_CallBack(args)
{
if(args[0] != "has_clip")
return;
processHasClip(5, args[1]);
}
function hasClip_6_CallBack(args)
{
if(args[0] != "has_clip")
return;
processHasClip(6, args[1]);
}
function hasClip_7_CallBack(args)
{
if(args[0] != "has_clip")
return;
processHasClip(7, args[1]);
}
function hasClip_8_CallBack(args)
{
if(args[0] != "has_clip")
return;
processHasClip(8, args[1]);
}
function setColor(note, color)
{
outlet(0, note, _colors["off"]);
if(color != "off")
outlet(0, note, _colors[color]);
}