"use server" import { newClap } from "@/lib/clap/newClap" import { newSegment } from "@/lib/clap/newSegment" import { LatentScenes } from "./types" import { serializeClap } from "@/lib/clap/serializeClap" import { getEmptyClap } from "@/lib/clap/emptyClap" import { ClapProject } from "@/lib/clap/types" let defaultSegmentDurationInMs = 2000 /** * This generates a fully valid Clap blob (compressed archive) * * @param param0 * @returns */ export async function addLatentScenesToClap({ scenes = [], clap, debug = false }: { scenes?: LatentScenes clap: ClapProject debug?: boolean }): Promise { if (!Array.isArray(scenes) || !scenes?.length) { return clap } let startTimeInMs = 0 let endTimeInMs = defaultSegmentDurationInMs clap.segments.push(newSegment({ track: 0, startTimeInMs, endTimeInMs, category: "interface", prompt: "", label: "fish", outputType: "interface", })) for (const { characters, locations, actions } of scenes) { startTimeInMs = endTimeInMs endTimeInMs = startTimeInMs + defaultSegmentDurationInMs let track = 0 for (const character of characters) { clap.segments.push(newSegment({ track: track++, startTimeInMs, endTimeInMs, category: "characters", prompt: character, label: character, outputType: "text", })) } for (const location of locations) { clap.segments.push(newSegment({ track: track++, startTimeInMs, endTimeInMs, category: "location", prompt: location, label: location, outputType: "text", })) } for (const action of actions) { clap.segments.push(newSegment({ track: track++, startTimeInMs, endTimeInMs, category: "action", prompt: action, label: action, outputType: "text", })) } clap.segments.push(newSegment({ track: track++, startTimeInMs, endTimeInMs, category: "video", prompt: "video", label: "video", outputType: "video", })) } if (debug) { console.log("latentScenesToClap: unpacked Clap content = ", JSON.stringify(clap, null, 2)) } return clap }