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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
#ifndef UDO_ELASTICLIPARRANGER
#define UDO_ELASTICLIPARRANGER ##
#include "scss/elasticlip.udo"
#include "scss/mixer/base.udo"
#include "array_3d.udo"
#include "sequencing_scheduled.udo"
#include "interop.udo"
giecpa_fn = -1
giecpa_scenenumber = -1
/*
Follow actions
0 repeat
1 next
2 previous
3 random in channel
4 stop
*/
instr ecpa_boot
ichannelnumber = (p4 == 0) ? 12 : p4
isendchannels = (p5 == 0) ? 2 : p5
imixermaxinserts = (p6 == 0) ? 6 : p6
giecpa_scenenumber = (p7 == 0) ? 16 : p7
schedule("mx_boot", 0, 1, ichannelnumber, isendchannels, imixermaxinserts)
giecpa_fn arr3d_init ichannelnumber, giecpa_scenenumber, 5
turnoff
endin
instr ecpa_addclip
icbid = p4
iclipid = p5
ichannel = p6
iscene = p7
index arr3d_index giecpa_fn, ichannel, iscene, 0
tabw_i iclipid, index, giecpa_fn
; set default follow actions
tabw_i 0, index + 1, giecpa_fn
tabw_i 0.5, index + 2, giecpa_fn
tabw_i 0, index + 3, giecpa_fn
tabw_i 16, index + 4, giecpa_fn
io_sendstring("callback", sprintf("{\"cbid\": %d}", icbid))
turnoff
endin
instr ecpa_moveclip
icbid = p4
ichannelfrom = p5
iscenefrom = p6
ichannelto = p7
isceneto = p8
index_from arr3d_index giecpa_fn, ichannelfrom, iscenefrom, 0
index_to arr3d_index giecpa_fn, ichannelto, isceneto, 0
index = 0
while (index < 5) do
tabw_i tab_i(index_from + index, giecpa_fn), index_to + index, giecpa_fn
index += 1
od
io_sendstring("callback", sprintf("{\"cbid\": %d}", icbid))
turnoff
endin
instr ecpa_rmclip
icbid = p4
ichannel = p5
iscene = p6
iclipindex arr3d_index giecpa_fn, ichannel, iscene, 0
; if playing, stop
index = 0
while (index < 5) do
tabw_i 0, iclipindex + index, giecpa_fn
index += 1
od
io_sendstring("callback", sprintf("{\"cbid\": %d}", icbid))
turnoff
endin
opcode _ecpa_getnext, i, iii
ichannel, iscene, ifollowaction xin
inextscene = iscene
if (ifollowaction == 0) then ; repeat
goto output
elseif (ifollowaction == 1 || ifollowaction == 2) then ; next or previous
isceneindex = (ifollowaction == 1) ? iscene + 1 : iscene - 1
while ((ifollowaction == 1 && isceneindex < giecpa_scenenumber) || (ifollowaction == 2 && isceneindex >= 0)) do
item arr3d_get ichannel, isceneindex, 0
if (item != 0) then
inextscene = isceneindex
goto output
endif
isceneindex += (ifollowaction == 1) ? 1 : -1
od
isceneindex = (ifollowaction == 1) ? 0 : giecpa_scenenumber - 1
while ((ifollowaction == 1 && isceneindex <= iscene) || (ifollowaction == 2 && isceneindex >= iscene)) do
item arr3d_get ichannel, isceneindex, 0
if (item != 0) then
inextscene = isceneindex
goto output
endif
isceneindex += (ifollowaction == 1) ? 1 : -1
od
elseif (ifollowaction == 3) then ; random
isceneindex = 0
insertindex = 0
iactivescenesnum = 0
iactivescenes[] init giecpa_scenenumber
while (isceneindex < giecpa_scenenumber) do
item arr3d_get ichannel, isceneindex, 0
if (item != 0) then
iactivescenesnum += 1
iactivescenes[insertindex] = isceneindex
insertindex += 1
endif
isceneindex += 1
od
inextscene = iactivescenes[round(random(0, iactivescenesnum - 1))]
goto output
endif
output:
xout inextscene
endop
instr ecpa_playslot
icbid = p4
ichannel = p5
iscene = p6
p1 += (ichannel + iscene) / 1000000
p3 = 36000
io_sendstring("callback", sprintf("{\"cbid\": %d, \"status\": -1}", icbid))
iclipindex arr3d_index giecpa_fn, ichannel, iscene, 0
ifollowaction1 = tab_i(iclipindex + 1, giecpa_fn)
ifollowchance = tab_i(iclipindex + 2, giecpa_fn)
ifollowaction2 = tab_i(iclipindex + 3, giecpa_fn)
ilength = tab_i(iclipindex + 4, giecpa_fn)
ifollowaction = (random(0, 1) <= ifollowchance) ? ifollowaction1 : ifollowaction2
iplaybackinstr = nstrnum("ecp_playback") + (icbid / 1000000)
klaunched init 0
if (gkseq_bar_trig == 1 && klaunched == 0) then
klaunched = 1
schedulek(iplaybackinstr, 0, -1, icbid, tab_i(iclipindex, giecpa_fn))
; turnoff other scene instances
isceneindex = 0
while (isceneindex < giecpa_scenenumber) do
if (isceneindex != iscene) then
turnoff2 (ichannel + iscene) / 1000000, 4, 1
endif
isceneindex += 1
od
endif
if (klaunched == 1) then
ktrig nextbeatxof ilength
if (ktrig == 1) then
if (ifollowaction != 4) then ; if not stop
inextscene _ecpa_getnext ichannel, iscene, ifollowaction
schedulek("ecpa_playslot", 0, 1, icbid, ichannel, inextscene)
endif
turnoff
endif
endif
kreleasing init 0
if (release:k() == 1 && kreleasing == 0) then
kreleasing = 1
turnoff2 iplaybackinstr, 4, 1
endif
endin
instr ecpa_playscene
icbid = p4
iscene = p5
klaunched init 0
if (gkseq_bar_trig == 1 && klaunched == 0) then
klaunched = 1
ibaseinstr = nstrnum("ecpa_playslot")
ichannel = 0
while (ichannel < gichannelnumber) do
turnoff2 (ichannel + iscene) / 1000000, 4, 1
ichannel += 1
od
endif
endin
#end
|