Skip to content

Commit 008f1e0

Browse files
committed
fix(cutline): list referenced clips top to bottom and label the media id as "id"
"Clips here" and multi-clip references now follow the timeline's lane order (V3, V2, V1, A1, A2...) instead of the order the clips were added. The editor passes its live track order; without one, video lanes run from the highest number down and audio lanes from A1 up. A clip's source line reads "id m_..." instead of an untranslated "media m_...".
1 parent 9030fa6 commit 008f1e0

3 files changed

Lines changed: 46 additions & 7 deletions

File tree

‎plugins/klarkxy/cutline/miniapp/client/app.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ function chatContext(extra = {}) {
430430
return {
431431
fps: projectFps(), projectName: root.name || "", revision: project.revision ?? null,
432432
sequence: { id: seq.id || seqId, name: seq.name || seqId }, compPath,
433-
getMedia, getComp, clips: project.clips.filter((c) => trackOf(c)), ...extra,
433+
getMedia, getComp, clips: project.clips.filter((c) => trackOf(c)), trackOrder: TRACKS.map((t) => t.id), ...extra,
434434
};
435435
}
436436
let chatSending = false;

‎plugins/klarkxy/cutline/miniapp/client/chat-context.js‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,22 @@
104104
return oneLine(c.name || "");
105105
}
106106

107+
/** Where a clip's track sits on the timeline, top to bottom (`ctx.trackOrder`,
108+
e.g. ["V3","V2","V1","A1",…]). Without an order: video lanes from the
109+
highest number down, then audio lanes from A1 up — the default layout. */
110+
function trackRank(ctx) {
111+
const order = Array.isArray(ctx && ctx.trackOrder) ? ctx.trackOrder : null;
112+
if (order && order.length) {
113+
const at = new Map(order.map((id, i) => [String(id), i]));
114+
return (c) => (at.has(String(c.track)) ? at.get(String(c.track)) : order.length);
115+
}
116+
return (c) => {
117+
const m = /^([VA])(\d+)$/.exec(String(c.track));
118+
if (!m) return 1e6;
119+
return m[1] === "V" ? -Number(m[2]) : 1e3 + Number(m[2]);
120+
};
121+
}
122+
107123
function header(T) {
108124
return [`[${T("Cutline reference")}]`];
109125
}
@@ -131,7 +147,7 @@
131147
if (c.mediaId) {
132148
const m = ctx.getMedia ? ctx.getMedia(c.mediaId) : null;
133149
const file = m ? oneLine(m.name || fileName(m.src)) : "";
134-
lines.push(` ${T("Source")}: ${file ? `“${file}” · ` : ""}media ${c.mediaId} · ${T("in point")} ${seconds(c.in || 0)}s`);
150+
lines.push(` ${T("Source")}: ${file ? `“${file}” · ` : ""}id ${c.mediaId} · ${T("in point")} ${seconds(c.in || 0)}s`);
135151
}
136152
if (c.kind === "comp" && c.compId) lines.push(` ${T("Composition")}: id ${c.compId}`);
137153
const flags = [];
@@ -157,7 +173,8 @@
157173
* @param {Function} [T]
158174
*/
159175
function clipsReference(clips, ctx, T = identity) {
160-
const list = (clips || []).filter(Boolean).slice().sort((a, b) => (a.start - b.start) || String(a.track).localeCompare(String(b.track)));
176+
const rank = trackRank(ctx);
177+
const list = (clips || []).filter(Boolean).slice().sort((a, b) => (a.start - b.start) || rank(a) - rank(b));
161178
const lines = header(T);
162179
lines.push(list.length === 1 ? `- ${T("Clip")}: ` + clipLines(list[0], ctx, T).join("\n") :
163180
`- ${T("Clips ({n})", { n: list.length })}:`);
@@ -183,7 +200,9 @@
183200
const lines = header(T);
184201
lines.push(`- ${T("Time")}: ${at(t, ctx.fps)} · ${T("frame")} ${frameOf(t, ctx.fps)}`);
185202
if (ctx.track) lines.push(`- ${T("Track")}: ${ctx.track}`);
186-
const under = (ctx.clips || []).filter((c) => t >= c.start && t < c.start + c.duration);
203+
const rank = trackRank(ctx);
204+
const under = (ctx.clips || []).filter((c) => t >= c.start && t < c.start + c.duration)
205+
.sort((a, b) => rank(a) - rank(b) || a.start - b.start);
187206
if (under.length) {
188207
lines.push(`- ${T("Clips here")}:`);
189208
for (const c of under.slice(0, MAX_CLIPS)) {

‎plugins/klarkxy/cutline/tests/chat-context.test.mjs‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ test('a clip reference names the clip, its time, its source and where the user i
3232
'[Cutline reference]',
3333
'- Clip: c_1 · video · track V1',
3434
' Timeline: 00:02:00 → 00:05:15 (2s → 5.5s, 3.5s)',
35-
' Source: “interview.mp4” · media m_1 · in point 1.25s',
35+
' Source: “interview.mp4” · id m_1 · in point 1.25s',
3636
'- Pointed at: 00:03:06 (3.2s) · frame 96',
3737
'- Sequence: Main (id main)',
3838
'- Project: Demo · revision 42 · 30 fps',
@@ -61,15 +61,35 @@ test('a moment lists the clips under it and the track it was taken on', () => {
6161
const text = Chat.timeReference(3.2, ctx({ clips: [video, title, { ...video, id: 'c_3', start: 9 }], track: 'V1' }));
6262
assert.match(text, /^- Time: 00:03:06 \(3\.2s\) · frame 96$/m);
6363
assert.match(text, /^- Track: V1$/m);
64-
assert.match(text, /^ {2}- c_1 · video · track V1 · 2s → 5\.5s$/m);
65-
assert.match(text, /^ {2}- c_2 · text · track V2 · “Hello” · 0s → 4s$/m);
64+
assert.match(text, /^ {2}- c_2 · text · track V2 · “Hello” · 0s → 4s\n {2}- c_1 · video · track V1 · 2s → 5\.5s$/m,
65+
'V2 sits above V1 on the timeline');
6666
assert.doesNotMatch(text, /c_3/, 'a clip after the moment is not under it');
6767

6868
const empty = Chat.timeReference(20, ctx({ clips: [video] }));
6969
assert.match(empty, /^- Clips here: none$/m);
7070
assert.doesNotMatch(empty, /Track:/);
7171
});
7272

73+
test('clips are listed top to bottom, the way the timeline shows the lanes', () => {
74+
const at = (id, track) => ({ id, kind: 'shape', track, start: 0, duration: 5 });
75+
const clips = [at('c_a3', 'A3'), at('c_v1', 'V1'), at('c_a1', 'A1'), at('c_v2', 'V2'), at('c_v10', 'V10')];
76+
const order = (text) => [...text.matchAll(/c_(?:a3|v1|a1|v2|v10)\b/g)].map((m) => m[0]);
77+
78+
/* The editor passes its own lane order: it wins, even when it is unusual. */
79+
const custom = ctx({ clips, trackOrder: ['V10', 'V2', 'V1', 'A1', 'A3'] });
80+
assert.deepEqual(order(Chat.timeReference(1, custom)), ['c_v10', 'c_v2', 'c_v1', 'c_a1', 'c_a3']);
81+
assert.deepEqual(order(Chat.clipsReference(clips, custom)), ['c_v10', 'c_v2', 'c_v1', 'c_a1', 'c_a3'],
82+
'clips that start together are listed lane by lane');
83+
84+
/* Without one: video from the highest number down, then audio from A1 up,
85+
with V10 above V2 (numbers, not text). */
86+
assert.deepEqual(order(Chat.timeReference(1, ctx({ clips }))), ['c_v10', 'c_v2', 'c_v1', 'c_a1', 'c_a3']);
87+
88+
/* Time still comes first in a clip list. */
89+
const later = [{ ...at('c_v2', 'V2'), start: 3 }, at('c_a1', 'A1')];
90+
assert.deepEqual(order(Chat.clipsReference(later, ctx())), ['c_a1', 'c_v2']);
91+
});
92+
7393
test('a marker reference carries its time, label and colour', () => {
7494
const text = Chat.markerReference({ t: 5, label: 'beat drop', color: 'red' }, ctx());
7595
assert.match(text, /^- Marker: 00:05:00 \(5s\) · frame 150 · “beat drop” · red$/m);

0 commit comments

Comments
 (0)