Skip to content

Make videos on the computer you already own. FreeVideo runs MiniMax H3 in as little as 8 GB of VRAM and 16 GB of RAM, and adapts its acceleration path to your hardware.

Editor music: separated music can be replaced in place from the generation bar, with guide...

Bowen Xuec1db179a23df
diff --git a/web/editor_genbar.js b/web/editor_genbar.js
index 7d2d3e4..c8183c0 100644
--- a/web/editor_genbar.js
+++ b/web/editor_genbar.js
@@ -220,9 +220,10 @@ export function createEditorGenbar(host, {state, t, actions, text = ''}) {
host.classList.toggle('fv-ed-genbar-music', !presets.hidden);
}
references?.update(busy, busy ? undefined : actions.references.visible() || false);
- // A piece already made, failed or stopped is made again in place.
- const made = musical && !!music.target(selection)?.clip && music.target(selection).clip.pending !== 'draft';
- const verb = made ? t('Regenerate', '重新生成') : t('Generate', '生成');
+ // A piece already made, failed or stopped is made again in place; separated music is replaced in place.
+ const aimed = musical ? music.target(selection) : null;
+ const made = !!aimed?.clip && aimed.clip.pending !== 'draft';
+ const verb = aimed?.replace ? t('Replace music', '替换配乐') : made ? t('Regenerate', '重新生成') : t('Generate', '生成');
generate.textContent = verb;
// Never disabled for a reason the press itself can explain or fix; only until the server says it can generate.
generate.disabled = busy || !!previewSelection || !!actions.generationWaiting?.();
diff --git a/web/editor_music.js b/web/editor_music.js
index ff39c66..4994093 100644
--- a/web/editor_music.js
+++ b/web/editor_music.js
@@ -119,7 +119,7 @@ export function createEditorMusic({state, store, t, completeSources = async () =
if (!found?.clip || api.running({kind: 'clip', ids: [id]}) || found.clip.text === text) return false;
state.apply(t('Edit description', '修改说明'), record => {
const next = JSON.parse(JSON.stringify(record));
- next.tracks.find(track => track.id === music.MUSIC_TRACK).clips.find(clip => clip.id === id).text = text;
+ next.tracks.flatMap(track => track.clips).find(clip => clip.id === id).text = text;
return next;
});
return true;
@@ -152,7 +152,7 @@ export function createEditorMusic({state, store, t, completeSources = async () =
const pack = await Promise.resolve().then(() => store.musicPack()).catch(() => null);
if (pack && !pack.ready && pack.disk_ok === false) return {say: musicFailureText('disk_space', t)};
const pick = preset(); words = text.trim();
- state.apply(t('Generate', '生成'), record => {
+ state.apply(found.replace ? t('Replace music', '替换配乐') : t('Generate', '生成'), record => {
const next = music.rememberPreset(record, pick);
if (id) return music.remakeMusic(next, id, {text: words, ...pick});
const planned = music.planMusic(next, {start: found.start, frames: found.frames, text: words, ...pick});
diff --git a/web/editor_music_model.js b/web/editor_music_model.js
index 2f020e9..40faeb3 100644
--- a/web/editor_music_model.js
+++ b/web/editor_music_model.js
@@ -14,12 +14,17 @@ export const MUSIC_MOODS = ['calm', 'upbeat', 'tense', 'warm', 'sad'];
const fail = code => { throw new model.EditError(code); };
const end = clip => clip.start + clip.frames;
const lane = record => record.tracks.find(track => track.id === MUSIC_TRACK) || null;
+// Where music is made: the music track, and the music separated out of a sound clip, which new music can replace.
+const lanes = record => record.tracks.filter(track => track.kind === 'audio' && (track.id === MUSIC_TRACK || track.stem === 'music'));
+const laneOf = (record, id) => lanes(record).find(track => track.clips.some(clip => clip.id === id)) || null;
// The music track's planned or running pieces: no file yet, waiting for (or made by) a music job.
-export const isMusicPart = (record, clip) => !!clip && !clip.source && clip.pending !== null
- && !!lane(record)?.clips.some(other => other.id === clip.id);
+export const isMusicPart = (record, clip) => !!clip && !clip.source && clip.pending !== null && !!laneOf(record, clip.id);
// A finished piece the music job made: its file sits in the music folder.
export const isGeneratedMusic = clip => clip?.source?.kind === 'generated' && /^freevideo-music\/[a-z]+(-[a-z]+)?-[0-9a-f]{32}\.mp4$/.test(clip.source.id);
+// The music separated out of a sound clip, as separation left it.
+export const isSeparatedMusic = (record, clip) => !!clip?.stem_of && !!clip.source && !isGeneratedMusic(clip)
+ && laneOf(record, clip.id)?.stem === 'music';
export const DEFAULT_PRESET = {style: 'cinematic', mood: 'calm'};
const preset = value => MUSIC_STYLES.includes(value?.style) && MUSIC_MOODS.includes(value?.mood) ? {style: value.style, mood: value.mood} : null;
@@ -33,20 +38,24 @@ export function rememberPreset(record, value) {
next.settings = {...(next.settings || {}), music: chosen};
return model.parse(next);
}
-// What a selection on the music track asks for: an empty stretch drawn or clicked there, or one piece of music
-// there (made again in place). Null for anything else.
+// What a selection asks for: an empty stretch drawn or clicked on the music track, one piece of music there or on
+// the separated music track (made again in place), or the separated music itself (replaced in place, `replace`).
+// Null for anything else.
export function musicTarget(record, selection) {
+ if (!selection) return null;
const track = lane(record);
- if (!track || !selection) return null;
if (selection.kind === 'range' && selection.tracks?.length === 1 && selection.tracks[0] === MUSIC_TRACK
|| selection.kind === 'gap' && selection.track === MUSIC_TRACK) {
+ if (!track) return null;
const frames = Math.min(selection.frames, MAX_MUSIC_FRAMES);
if (track.clips.some(clip => clip.start < selection.start + frames && end(clip) > selection.start)) return null;
return {start: selection.start, frames};
}
if (selection.kind !== 'clip' || selection.ids.length !== 1) return null;
- const clip = track.clips.find(clip => clip.id === selection.ids[0]);
- if (!clip || !(isMusicPart(record, clip) || isGeneratedMusic(clip))) return null;
+ const clip = laneOf(record, selection.ids[0])?.clips.find(clip => clip.id === selection.ids[0]);
+ if (!clip) return null;
+ if (isSeparatedMusic(record, clip)) return clip.frames <= MAX_MUSIC_FRAMES ? {start: clip.start, frames: clip.frames, id: clip.id, clip, replace: true} : null;
+ if (!(isMusicPart(record, clip) || isGeneratedMusic(clip))) return null;
return {start: clip.start, frames: clip.frames, id: clip.id, clip};
}
@@ -67,15 +76,24 @@ export function planMusic(record, {start, frames, text = '', style, mood}) {
}
// Made again in place: a finished, failed or stopped piece becomes a planned one over the same stretch, with the
// words and preset given; its volume, fades and lowering stay. One undo brings the previous piece back.
+// Separated music is replaced the same way: it stays a part of the clip it came from (deleting every separated
+// part still gives that clip its sound back), takes the music's own speed, and is lowered during speech.
export function remakeMusic(record, id, {text = '', style, mood}) {
if (typeof text !== 'string') fail('text');
const chosen = preset({style, mood}) || fail('preset');
- const next = model.serialize(record), clip = next.tracks.find(track => track.id === MUSIC_TRACK)?.clips.find(clip => clip.id === id);
- if (!clip || !(isGeneratedMusic(clip) || !clip.source && clip.pending !== null)) fail('missing');
- if (next.tracks.find(track => track.id === MUSIC_TRACK).locked) fail('locked');
+ const separated = isSeparatedMusic(record, model.find(record, id));
+ const next = model.serialize(record), track = next.tracks.find(track => track.clips.some(clip => clip.id === id));
+ const clip = laneOf(next, id) && track.clips.find(clip => clip.id === id);
+ if (!clip || !(separated || isGeneratedMusic(clip) || !clip.source && clip.pending !== null)) fail('missing');
+ if (separated && clip.frames > MAX_MUSIC_FRAMES) fail('too_long');
+ if (track.locked) fail('locked');
if (['queued', 'running'].includes(clip.pending)) fail('busy');
Object.assign(clip, {source: null, in: 0, length: clip.frames, text, pending: 'draft', reason: null, job: null, versions: [], music: chosen});
delete clip.splice;
+ if (separated) {
+ for (const name of ['speed', 'speed_audio', 'speed_phase', 'reverse']) delete clip[name];
+ clip.duck = true;
+ }
return model.parse(next);
}
@@ -90,7 +108,7 @@ export function musicRequest(record, id, {seed} = {}) {
}
function change(record, id, job, edit) {
- const next = model.serialize(record), clip = next.tracks.find(track => track.id === MUSIC_TRACK)?.clips.find(clip => clip.id === id);
+ const next = model.serialize(record), clip = laneOf(next, id)?.clips.find(clip => clip.id === id);
if (!clip || clip.source || clip.pending === null) return null;
if (job !== undefined && clip.job !== job) return null;
edit(clip);
@@ -128,5 +146,5 @@ export function retryMusic(record, id) {
}) ?? fail('missing');
}
// The pieces still waiting for a job after the page opens again, to watch or to mark failed.
-export const musicJobs = record => (lane(record)?.clips || []).filter(clip => !clip.source && clip.job && ['queued', 'running'].includes(clip.pending))
+export const musicJobs = record => lanes(record).flatMap(track => track.clips).filter(clip => !clip.source && clip.job && ['queued', 'running'].includes(clip.pending))
.map(clip => ({id: clip.id, job: clip.job}));
diff --git a/web/editor_tracks.js b/web/editor_tracks.js
index 1e8e79d..654a52f 100644
--- a/web/editor_tracks.js
+++ b/web/editor_tracks.js
@@ -514,6 +514,10 @@ export function createTracks(host, {state, sources = {}, t = en => en, actions =
row = {element: node, head, empty}; rows.set(track.id, row); parted ||= !!track.stem;
}
row.head.title = name; row.head.querySelector('span').textContent = name;
+ // Guide targets ("take me there"): the lanes where a range is dragged out for speech or music, and the
+ // separated music lane where new music replaces the old.
+ const tourId = track.stem === 'music' ? 'audio-music-stem' : track.stem ? '' : {a1: 'audio-a1-track', a2: 'audio-a2-track'}[track.id] || '';
+ if (tourId) row.element.dataset.tourId = tourId; else delete row.element.dataset.tourId;
row.empty.hidden = track.clips.length > 0;
// A picture track with any block description grows a strip for it under the pictures.
const noted = !!actions.describedTrack?.(track); row.element.dataset.noted = String(noted);
@@ -590,6 +594,8 @@ export function createTracks(host, {state, sources = {}, t = en => en, actions =
addAudio.dataset.sign = addAudio.textContent.slice(0, 1); // Phone widths show the sign alone.
addAudio.title = '';
addAudio.setAttribute('aria-label', addAudio.textContent);
+ // Without Audio 2 the guide points at the button that adds it.
+ if (twoAudio) delete addAudio.dataset.tourId; else addAudio.dataset.tourId = 'audio-a2-track';
setTrackHeight(top - 6);
layout();
// The parts of a fresh split appear under the sound they came from: show them from the top.