Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
382 lines (337 loc) · 18.2 KB
/
Copy pathscript.js
File metadata and controls
382 lines (337 loc) · 18.2 KB
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
let currentShowData = null;
document.getElementById('importBtn').addEventListener('click', () => {
document.getElementById('jsonInput').click();
});
document.getElementById('jsonInput').addEventListener('change', function (e) {
const file = e.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function (evt) {
try {
currentShowData = JSON.parse(evt.target.result);
renderPreview(currentShowData);
document.getElementById('exportBtn').disabled = false;
document.getElementById('statsBtn').disabled = false;
} catch (err) {
alert('Error reading JSON. Make sure it is valid.');
}
};
reader.readAsText(file);
});
document.getElementById('exportBtn').addEventListener('click', () => {
if (!currentShowData) return;
const appleScriptText = generateAppleScript(currentShowData);
downloadScript(appleScriptText, `${currentShowData.meta?.title || 'showfile'}_import.applescript`);
});
function renderPreview(data) {
const metaContainer = document.getElementById('metaContainer');
const treeContainer = document.getElementById('treeContainer');
if (data.meta) {
metaContainer.classList.remove('hidden');
document.getElementById('metaTitle').textContent = data.meta.title || 'Untitled';
document.getElementById('metaTech').textContent = `Designed by: ${data.meta.tech || 'Unknown'} | Revision: ${data.meta.revision || '-'}`;
}
treeContainer.innerHTML = '';
if (!data.cues || data.cues.length === 0) {
treeContainer.innerHTML = '<div class="empty-state">No cues found in the JSON.</div>';
return;
}
let lastVideoKey = null;
data.cues.forEach((cueData) => {
const processedCues = processBlock(cueData, lastVideoKey);
const hasNewVideo = cueData.video && cueData.video.trim() !== '' && !cueData.video.toLowerCase().includes('stop') && !cueData.video.toLowerCase().includes('fade out');
if (hasNewVideo) {
lastVideoKey = cueData.video
.toLowerCase()
.replace(/^(audio:|vid:|stop|finish|end|parar|out|off|fade out:|fade down:|fade up:|pause:|down|bajar|baixar|pausar|pujar|subir|up|play \+ up)\s*/g, '')
.trim();
} else if (cueData.video && cueData.video.trim() !== '') {
lastVideoKey = null;
}
const groupHtml = `
<div class="tree-group">
<div class="group-header">
<span class="group-num">Scene ${cueData.scene}</span>
<span class="group-name">${cueData.trigger || 'No trigger (GO)'}</span>
</div>
<div class="group-children">
${processedCues
.map(
(cue) => `
<div class="tree-cue">
<div class="cue-icon ${cue.iconClass}">${cue.iconText}</div>
<span class="cue-type">${cue.type}</span>
<span class="cue-name">${cue.name}</span>
</div>
`
)
.join('')}
</div>
</div>
`;
treeContainer.insertAdjacentHTML('beforeend', groupHtml);
});
}
function processBlock(cueData, currentLastVideo = null) {
const internalCues = [];
const keywordsStop = ['stop', 'finish', 'end', 'parar', 'out', 'off', 'fade out'];
const keywordsDown = ['down', 'bajar', 'baixar'];
const keywordsPause = ['pausar', 'pause'];
const keywordsUp = ['pujar', 'subir', 'up'];
if (cueData.lights && cueData.lights.trim() !== '') {
internalCues.push({
type: 'Network',
name: `LIGHT: ${cueData.lights}`,
iconClass: 'light',
iconText: 'NET'
});
}
if (cueData.audio && cueData.audio.trim() !== '') {
const parts = cueData.audio.split(/\|\||->/);
parts.forEach((part) => {
const text = part.toLowerCase().trim();
if (text === '') return;
if (keywordsStop.some((word) => text.includes(word))) {
internalCues.push({ type: 'Fade', name: `FADE OUT & STOP: ${part.trim()}`, iconClass: 'fade', iconText: 'FAD' });
} else if (keywordsDown.some((word) => text.includes(word))) {
internalCues.push({ type: 'Fade', name: `FADE DOWN: ${part.trim()}`, iconClass: 'fade', iconText: 'FAD' });
} else if (keywordsPause.some((word) => text.includes(word))) {
internalCues.push({ type: 'Target', name: `PAUSE: ${part.trim()}`, iconClass: 'fade', iconText: 'TAR' });
} else if (keywordsUp.some((word) => text.includes(word))) {
internalCues.push({ type: 'Fade', name: `FADE UP: ${part.trim()}`, iconClass: 'fade', iconText: 'FAD' });
} else {
internalCues.push({ type: 'Audio', name: `AUDIO: ${part.trim()}`, iconClass: 'audio', iconText: 'AUD' });
}
});
}
if (cueData.video && cueData.video.trim() !== '') {
const text = cueData.video.toLowerCase();
if (text.includes('stop') || text.includes('fade out')) {
internalCues.push({ type: 'Fade', name: `FADE OUT VID: ${cueData.video}`, iconClass: 'fade', iconText: 'FAD' });
} else {
if (currentLastVideo) {
internalCues.push({ type: 'Fade', name: `FADE OUT PREV VID (3s)`, iconClass: 'fade', iconText: 'FAD' });
}
internalCues.push({ type: 'Video', name: `VID: ${cueData.video}${currentLastVideo ? ' (Pre-wait 3s)' : ''}`, iconClass: 'video', iconText: 'VID' });
internalCues.push({ type: 'Fade', name: `FADE IN VID: ${cueData.video}${currentLastVideo ? ' (Pre-wait 3s)' : ''}`, iconClass: 'fade', iconText: 'FAD' });
}
}
return internalCues;
}
function generateAppleScript(data) {
let script = 'tell application "QLab"\n\ttell front workspace\n';
const cNet = document.getElementById('colorNet').value;
const cAudio = document.getElementById('colorAudio').value;
const cVideo = document.getElementById('colorVideo').value;
const audioTargets = {};
const videoTargets = {};
let cueCounter = 1;
let lastVideoKey = null;
const cleanTargetName = (str) => {
return str
.toLowerCase()
.replace(/^(audio:|vid:|stop|finish|end|parar|out|off|fade out:|fade down:|fade up:|pause:|down|bajar|baixar|pausar|pujar|subir|up|play \+ up)\s*/g, '')
.trim();
};
const keywordsStop = ['stop', 'finish', 'end', 'parar', 'out', 'off', 'fade out'];
const keywordsDown = ['down', 'bajar', 'baixar'];
const keywordsPause = ['pausar', 'pause'];
const keywordsUp = ['pujar', 'subir', 'up'];
data.cues.forEach((cueData) => {
script += `\t\t-- Scene Group: ${cueData.scene}\n`;
script += `\t\tmake type "Group"\n`;
script += `\t\tset groupCue to last item of (selected as list)\n`;
script += `\t\tset q number of groupCue to "${cueData.scene}.${cueData.subscene}"\n`;
script += `\t\tset q name of groupCue to "${cueData.trigger}"\n`;
script += `\t\tset notes of groupCue to "${cueData.trigger}"\n`;
script += `\t\tset mode of groupCue to timeline\n\n`;
if (cueData.lights && cueData.lights.trim() !== '') {
script += `\t\t\tmake type "Network"\n`;
script += `\t\t\tset newCue to last item of (selected as list)\n`;
script += `\t\t\tset q name of newCue to "LIGHT: ${cueData.lights}"\n`;
script += `\t\t\tset q color of newCue to "${cNet}"\n`;
script += `\t\t\tmove newCue to end of groupCue\n`;
}
if (cueData.audio && cueData.audio.trim() !== '') {
const parts = cueData.audio.split(/\|\||->/);
parts.forEach((part) => {
const text = part.toLowerCase().trim();
if (text === '') return;
if (keywordsStop.some((word) => text.includes(word)) || keywordsDown.some((word) => text.includes(word)) || keywordsPause.some((word) => text.includes(word)) || keywordsUp.some((word) => text.includes(word))) return;
const nameKey = cleanTargetName(part);
audioTargets[nameKey] = `A${cueCounter++}`;
});
parts.forEach((part) => {
const text = part.toLowerCase().trim();
if (text === '') return;
const nameKey = cleanTargetName(part);
if (keywordsStop.some((word) => text.includes(word))) {
script += `\t\t\tmake type "Fade"\n`;
script += `\t\t\tset newCue to last item of (selected as list)\n`;
script += `\t\t\tset q name of newCue to "FADE OUT: ${part.trim()}"\n`;
script += `\t\t\tmove newCue to end of groupCue\n`;
if (audioTargets[nameKey]) {
script += `\t\t\tset cue target of newCue to cue "${audioTargets[nameKey]}"\n`;
}
script += `\t\t\tsetLevel newCue row 0 column 0 db -120\n`;
script += `\t\t\tset stop target when done of newCue to true\n`;
delete audioTargets[nameKey];
} else if (keywordsDown.some((word) => text.includes(word))) {
script += `\t\t\tmake type "Fade"\n`;
script += `\t\t\tset newCue to last item of (selected as list)\n`;
script += `\t\t\tset q name of newCue to "FADE DOWN: ${part.trim()}"\n`;
script += `\t\t\tmove newCue to end of groupCue\n`;
if (audioTargets[nameKey]) {
script += `\t\t\tset cue target of newCue to cue "${audioTargets[nameKey]}"\n`;
}
script += `\t\t\tsetLevel newCue row 0 column 0 db -24\n`;
} else if (keywordsPause.some((word) => text.includes(word))) {
script += `\t\t\tmake type "Target"\n`;
script += `\t\t\tset newCue to last item of (selected as list)\n`;
script += `\t\t\tset q name of newCue to "PAUSE: ${part.trim()}"\n`;
script += `\t\t\tmove newCue to end of groupCue\n`;
if (audioTargets[nameKey]) {
script += `\t\t\tset cue target of newCue to cue "${audioTargets[nameKey]}"\n`;
}
} else if (keywordsUp.some((word) => text.includes(word))) {
script += `\t\t\tmake type "Fade"\n`;
script += `\t\t\tset newCue to last item of (selected as list)\n`;
script += `\t\t\tset q name of newCue to "FADE UP: ${part.trim()}"\n`;
script += `\t\t\tmove newCue to end of groupCue\n`;
if (audioTargets[nameKey]) {
script += `\t\t\tset cue target of newCue to cue "${audioTargets[nameKey]}"\n`;
}
script += `\t\t\tsetLevel newCue row 0 column 0 db 0\n`;
} else {
script += `\t\t\tmake type "Audio"\n`;
script += `\t\t\tset newCue to last item of (selected as list)\n`;
script += `\t\t\tset q name of newCue to "AUDIO: ${part.trim()}"\n`;
script += `\t\t\tset q color of newCue to "${cAudio}"\n`;
if (audioTargets[nameKey]) {
script += `\t\t\tset q number of newCue to "${audioTargets[nameKey]}"\n`;
}
script += `\t\t\tmove newCue to end of groupCue\n`;
}
});
}
if (cueData.video && cueData.video.trim() !== '') {
const text = cueData.video.toLowerCase();
const nameKey = cleanTargetName(cueData.video);
if (text.includes('stop') || text.includes('fade out')) {
script += `\t\t\tmake type "Fade"\n`;
script += `\t\t\tset fadeCue to last item of (selected as list)\n`;
script += `\t\t\tset q name of fadeCue to "FADE OUT VID: ${cueData.video}"\n`;
script += `\t\t\tmove fadeCue to end of groupCue\n`;
if (videoTargets[nameKey]) {
script += `\t\t\tset cue target of fadeCue to cue "${videoTargets[nameKey]}"\n`;
}
script += `\t\t\tset duration of fadeCue to 3.0\n`;
script += `\t\t\tset do opacity of fadeCue to true\n`;
script += `\t\t\tset opacity of fadeCue to 0.0\n`;
script += `\t\t\tset stop target when done of fadeCue to true\n`;
delete videoTargets[nameKey];
lastVideoKey = null;
} else {
videoTargets[nameKey] = `V${cueCounter++}`;
if (lastVideoKey && videoTargets[lastVideoKey]) {
script += `\t\t\tmake type "Fade"\n`;
script += `\t\t\tset fadeOld to last item of (selected as list)\n`;
script += `\t\t\tset q name of fadeOld to "FADE OUT PREVIOUS VIDEO"\n`;
script += `\t\t\tmove fadeOld to end of groupCue\n`;
script += `\t\t\tset cue target of fadeOld to cue "${videoTargets[lastVideoKey]}"\n`;
script += `\t\t\tset duration of fadeOld to 3.0\n`;
script += `\t\t\tset do opacity of fadeOld to true\n`;
script += `\t\t\tset opacity of fadeOld to 0.0\n`;
script += `\t\t\tset stop target when done of fadeOld to true\n`;
}
script += `\t\t\tmake type "Video"\n`;
script += `\t\t\tset vidCue to last item of (selected as list)\n`;
script += `\t\t\tset q name of vidCue to "VID: ${cueData.video}"\n`;
script += `\t\t\tset q color of vidCue to "${cVideo}"\n`;
if (videoTargets[nameKey]) {
script += `\t\t\tset q number of vidCue to "${videoTargets[nameKey]}"\n`;
}
if (lastVideoKey) {
script += `\t\t\tset pre wait of vidCue to 3.0\n`;
}
script += `\t\t\tmove vidCue to end of groupCue\n`;
script += `\t\t\tset opacity of vidCue to 0.0\n`;
script += `\t\t\tmake type "Fade"\n`;
script += `\t\t\tset fadeCue to last item of (selected as list)\n`;
script += `\t\t\tset q name of fadeCue to "FADE IN VID: ${cueData.video}"\n`;
if (lastVideoKey) {
script += `\t\t\tset pre wait of fadeCue to 3.0\n`;
}
script += `\t\t\tmove fadeCue to end of groupCue\n`;
script += `\t\t\tset cue target of fadeCue to vidCue\n`;
script += `\t\t\tset do opacity of fadeCue to true\n`;
script += `\t\t\tset opacity of fadeCue to 1.0\n`;
lastVideoKey = nameKey;
}
}
script += `\n`;
});
script += '\tend tell\nend tell';
return script;
}
function downloadScript(text, filename) {
const element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
document.getElementById('treeContainer').addEventListener('click', (e) => {
const header = e.target.closest('.group-header');
if (header) {
header.parentElement.classList.toggle('collapsed');
}
});
document.getElementById('statsBtn').addEventListener('click', () => {
if (!currentShowData) return;
let total = 0,
net = 0,
aud = 0,
vid = 0,
fad = 0,
tar = 0;
let lastVideoKey = null;
currentShowData.cues.forEach((cueData) => {
const cues = processBlock(cueData, lastVideoKey);
const hasNewVideo = cueData.video && cueData.video.trim() !== '' && !cueData.video.toLowerCase().includes('stop') && !cueData.video.toLowerCase().includes('fade out');
if (hasNewVideo) {
lastVideoKey = cueData.video
.toLowerCase()
.replace(/^(audio:|vid:|stop|finish|end|parar|out|off|fade out:|fade down:|fade up:|pause:|down|bajar|baixar|pausar|pujar|subir|up|play \+ up)\s*/g, '')
.trim();
} else if (cueData.video && cueData.video.trim() !== '') {
lastVideoKey = null;
}
total += cues.length;
cues.forEach((c) => {
if (c.type === 'Network') net++;
if (c.type === 'Audio') aud++;
if (c.type === 'Video') vid++;
if (c.type === 'Fade') fad++;
if (c.type === 'Target') tar++;
});
});
const modal = document.createElement('div');
modal.className = 'modal-overlay';
modal.innerHTML = `
<div class="modal-content">
<h3>Workspace stats</h3>
<div class="stat-row"><span>Total usable cues:</span><strong>${total}</strong></div>
<div class="stat-row"><span>Network (lights):</span><span>${net}</span></div>
<div class="stat-row"><span>Audio:</span><span>${aud}</span></div>
<div class="stat-row"><span>Video:</span><span>${vid}</span></div>
<div class="stat-row"><span>Fade:</span><span>${fad}</span></div>
<div class="stat-row"><span>Target (pause):</span><span>${tar}</span></div>
<button id="closeModalBtn" style="width:100%">Close</button>
</div>
`;
document.body.appendChild(modal);
document.getElementById('closeModalBtn').onclick = () => modal.remove();
});