Skip to content

The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.

The tray names its sound and word tools, and each opens a sheet

Jareer72379ab731a7
diff --git a/engine/crates/concat/src/lib.rs b/engine/crates/concat/src/lib.rs
index d7fb95a1..c4add212 100644
--- a/engine/crates/concat/src/lib.rs
+++ b/engine/crates/concat/src/lib.rs
@@ -97,7 +97,10 @@ pub fn run() -> Result<(), slint::PlatformError> {
editor.set_audio_params(ModelRc::from(models.audio_params.clone()));
editor.set_adjust_params(ModelRc::from(models.adjust_params.clone()));
editor.set_menu_items(ModelRc::from(models.menu.clone()));
- editor.set_av_items(ModelRc::from(models.av.clone()));
+ app.set_caption_models(ModelRc::from(models.caption_models.clone()));
+ app.set_speech_models(ModelRc::from(models.speech_models.clone()));
+ app.set_speech_voices(ModelRc::from(models.speakers.clone()));
+ app.set_speech_voice_details(ModelRc::from(models.speaker_details.clone()));
app.set_app_menu_items(ModelRc::from(models.bar.clone()));
app.set_transcribers(ModelRc::from(models.transcribers.clone()));
app.set_voices(ModelRc::from(models.voices.clone()));
@@ -823,27 +826,68 @@ pub fn run() -> Result<(), slint::PlatformError> {
state.model_remove(id.as_str());
}));
- // ── the tray's A/V menu ──
- editor.on_av_tools(on_window!(|state| {
- state.av_token += 1;
+ // ── the tray's sound and word tools ──
+ editor.on_captions(on_window!(|state| {
+ state.captions_open();
}));
- editor.on_av_selected(on_window!(|state, action: SharedString| {
- let Some(id) = state.selection.first().cloned() else {
- return;
- };
- match action.as_str() {
- "captions" => state.caption_selected(),
- "speak" => state.speak_selected(),
- "detach" => {
- state.apply(concat_project::Command::DetachAudio { clip_id: id });
- }
- "reattach" => {
- state.apply(concat_project::Command::ReattachAudio { clip_id: id });
- }
- _ => {}
+ editor.on_speak(on_window!(|state| {
+ state.speech_open();
+ }));
+ editor.on_detach_audio(on_window!(|state| {
+ if let Some(clip_id) = state.sole_selection() {
+ state.apply(concat_project::Command::DetachAudio { clip_id });
+ }
+ }));
+ editor.on_reattach_audio(on_window!(|state| {
+ if let Some(clip_id) = state.sole_selection() {
+ state.apply(concat_project::Command::ReattachAudio { clip_id });
}
}));
+ app.on_captions_closed(on_window!(|state| {
+ state.captions.open = false;
+ }));
+ app.on_captions_language_changed(on_window!(|state, index: i32| {
+ state.captions.language = index.clamp(0, studio::TRANSCRIBE_LANGUAGES.len() as i32 - 1);
+ }));
+ app.on_captions_model_changed(on_window!(|state, index: i32| {
+ state.captions.model = index.max(0) as usize;
+ }));
+ app.on_captions_placement_changed(on_window!(|state, index: i32| {
+ state.captions.placement = (index.max(0) as usize).min(2);
+ }));
+ app.on_captions_size_changed(on_window!(|state, index: i32| {
+ state.captions.size = (index.max(0) as usize).min(2);
+ }));
+ app.on_captions_begin(on_window!(|state| {
+ state.captions_run();
+ }));
+ app.on_captions_cancel(on_window!(|state| {
+ state.captions_cancel();
+ }));
+
+ app.on_speech_closed(on_window!(|state| {
+ state.speech.open = false;
+ }));
+ app.on_speech_text_edited(on_window!(|state, text: SharedString| {
+ state.speech.text = text.to_string();
+ }));
+ app.on_speech_voice_changed(on_window!(|state, index: i32| {
+ state.speech.voice = index.max(0) as usize;
+ }));
+ app.on_speech_model_changed(on_window!(|state, index: i32| {
+ state.speech.model = index.max(0) as usize;
+ }));
+ app.on_speech_pace_changed(on_window!(|state, index: i32| {
+ state.speech.pace = (index.max(0) as usize).min(2);
+ }));
+ app.on_speech_begin(on_window!(|state| {
+ state.speech_run();
+ }));
+ app.on_speech_cancel(on_window!(|state| {
+ state.speech_cancel();
+ }));
+
// ── the title-bar menus ──
app.on_menu_opened(on_window!(|state, index: i32| {
state.open_menu = index;
@@ -868,7 +912,7 @@ pub fn run() -> Result<(), slint::PlatformError> {
state.export.message.clear();
}
"template" => state.save_template(),
- "speech" => state.speak_selected(),
+ "speech" => state.speech_open(),
"settings" => {
state.refresh_models();
state.settings.open = true;
diff --git a/engine/crates/concat/src/studio.rs b/engine/crates/concat/src/studio.rs
index d9ab629a..a7ec3322 100644
--- a/engine/crates/concat/src/studio.rs
+++ b/engine/crates/concat/src/studio.rs
@@ -145,6 +145,56 @@ pub struct ProjectSheet {
pub rate: usize,
}
+/// The captions sheet: the tray's Captions tool, as a form and then as a
+/// progress report.
+#[derive(Default)]
+pub struct CaptionsSheet {
+ pub open: bool,
+ /// The clip being transcribed.
+ pub clip: Option<String>,
+ /// Row in `TRANSCRIBE_LANGUAGES`.
+ pub language: i32,
+ /// Row in the installed transcriber list.
+ pub model: usize,
+ /// 0 bottom, 1 centre, 2 top.
+ pub placement: usize,
+ /// 0 small, 1 medium, 2 large.
+ pub size: usize,
+ pub running: bool,
+ pub progress: f32,
+ /// Why the last run failed, when it did.
+ pub message: String,
+}
+
+/// The speech sheet: a title's words, or any words, read aloud.
+#[derive(Default)]
+pub struct SpeechSheet {
+ pub open: bool,
+ /// The title the words came from, and where the sound lands. None
+ /// reads a script of its own at the playhead.
+ pub clip: Option<String>,
+ pub text: String,
+ /// Row in `Studio::speakers`.
+ pub voice: usize,
+ /// Row in the installed voice model list.
+ pub model: usize,
+ /// 0 slower, 1 natural, 2 faster.
+ pub pace: usize,
+ pub running: bool,
+ pub progress: f32,
+ pub message: String,
+}
+
+/// The paces the speech sheet offers, as the voice's rate multiplier.
+const PACES: [f32; 3] = [0.85, 1.0, 1.15];
+/// Where a caption sits, by the sheet's row: a frame-height fraction from
+/// the centre, positive down. Bottom, centre, top.
+const CAPTION_OFFSETS: [f64; 3] = [0.35, 0.0, -0.35];
+/// A caption's cap height by the sheet's row, as a fraction of the frame.
+const CAPTION_SIZES: [f64; 3] = [0.04, 0.05, 0.065];
+/// A rough speaking rate, for the estimate under the script.
+const CHARS_PER_SECOND: f32 = 14.0;
+
/// The export sheet's state.
pub struct ExportState {
pub open: bool,
@@ -411,8 +461,12 @@ pub struct Models {
/// The colour panel's knobs.
pub adjust_params: Rc<VecModel<AppliedParamData>>,
pub menu: Rc<VecModel<MenuItemData>>,
- pub av: Rc<VecModel<MenuItemData>>,
pub bar: Rc<VecModel<MenuItemData>>,
+ /// The sheets' option lists: what is installed, and who can speak.
+ pub caption_models: Rc<VecModel<SharedString>>,
+ pub speech_models: Rc<VecModel<SharedString>>,
+ pub speakers: Rc<VecModel<SharedString>>,
+ pub speaker_details: Rc<VecModel<SharedString>>,
pub transcribers: Rc<VecModel<ModelData>>,
pub voices: Rc<VecModel<ModelData>>,
pub seats: Rc<VecModel<SeatBox>>,
@@ -443,8 +497,11 @@ impl Models {
audio_params: Rc::new(VecModel::default()),
adjust_params: Rc::new(VecModel::default()),
menu: Rc::new(VecModel::default()),
- av: Rc::new(VecModel::default()),
bar: Rc::new(VecModel::default()),
+ caption_models: Rc::new(VecModel::default()),
+ speech_models: Rc::new(VecModel::default()),
+ speakers: Rc::new(VecModel::default()),
+ speaker_details: Rc::new(VecModel::default()),
transcribers: Rc::new(VecModel::default()),
voices: Rc::new(VecModel::default()),
seats: Rc::new(VecModel::default()),
@@ -536,7 +593,6 @@ pub struct Studio {
pub settings: SettingsState,
pub transcribers: Vec<ModelState>,
pub voices: Vec<ModelState>,
- pub av_token: i32,
pub open_menu: i32,
pub menu_bar_token: i32,
pub menu_target: Option<String>,
@@ -572,6 +628,10 @@ pub struct Studio {
pub title_blocks: HashMap<String, (u32, u32)>,
pub drop: Option<DropPlan>,
pub project_sheet: ProjectSheet,
+ pub captions: CaptionsSheet,
+ pub speech: SpeechSheet,
+ /// Every speaker the voice engine offers, in its own order.
+ pub speakers: Vec<concat_speech::tts::VoiceInfo>,
}
// ── conversions between the document and the window ─────────────────────
@@ -911,7 +971,6 @@ impl Studio {
settings: SettingsState::default(),
transcribers: Vec::new(),
voices: Vec::new(),
- av_token: 0,
open_menu: -1,
menu_bar_token: 0,
menu_target: None,
@@ -933,6 +992,9 @@ impl Studio {
title_blocks: HashMap::new(),
drop: None,
project_sheet: ProjectSheet::default(),
+ captions: CaptionsSheet::default(),
+ speech: SpeechSheet::default(),
+ speakers: Vec::new(),
host,
};
studio.settings.language = studio.prefs.language.unwrap_or(0);
@@ -3127,15 +3189,26 @@ impl Studio {
self.selection = vec![created];
}
- /// Sound to detach, or a title's words to speak - the tray only hangs
- /// the A/V menu when the selection has something to offer it.
- pub fn has_av_tools(&self) -> bool {
- self.sole_selection()
- .and_then(|id| {
- self.clip(&id)
- .map(|clip| clip.kind != model::ClipKind::Image)
- })
- .unwrap_or(false)
+ /// What the tray's sound and word tools may do to the selection: one
+ /// clip with sound to caption, one title to speak, one video clip whose
+ /// sound is on it to detach, or whose sound is off it to put back.
+ fn sound_tools(&self) -> (bool, bool, bool, bool) {
+ let Some(clip) = self.sole_selection().and_then(|id| self.clip(&id)) else {
+ return (false, false, false, false);
+ };
+ let detached = self
+ .timeline()
+ .clips
+ .iter()
+ .any(|other| other.detached_from.as_deref() == Some(clip.id.as_str()));
+ let video = clip.kind == model::ClipKind::Video;
+ (
+ matches!(clip.kind, model::ClipKind::Video | model::ClipKind::Audio),
+ clip.kind == model::ClipKind::Text,
+ video && !detached,
+ (video && detached)
+ || (clip.kind == model::ClipKind::Audio && clip.detached_from.is_some()),
+ )
}
// ── projects ──
@@ -3430,6 +3503,7 @@ impl Studio {
.collect();
}
if let Ok(status) = concat_speech::Speech::status(dirs) {
+ self.speakers = status.voices.clone();
self.voices = status
.models
.iter()
@@ -3561,99 +3635,176 @@ impl Studio {
self.refresh_models();
}
- fn language_code(&self) -> &'static str {
- TRANSCRIBE_LANGUAGES
- .get(self.settings.transcribe_language.max(0) as usize)
- .copied()
- .unwrap_or("auto")
+ /// The models of a kind that are on disk, in the settings' order: the
+ /// rows of a sheet's model list.
+ fn installed(models: &[ModelState]) -> Vec<&ModelState> {
+ models.iter().filter(|model| model.installed).collect()
}
- /// Auto captions for the selected clip: the transcription runs on a
- /// worker and lands as one batch of title clips.
- pub fn caption_selected(&mut self) {
+ /// Opens the captions sheet on the selected clip, with the settings'
+ /// language and the chosen model already picked.
+ pub fn captions_open(&mut self) {
let Some(id) = self.sole_selection() else {
return;
};
- let Some(clip) = self.clip(&id).cloned() else {
+ let installed = Self::installed(&self.transcribers);
+ let model = installed.iter().position(|model| model.active).unwrap_or(0);
+ self.captions = CaptionsSheet {
+ open: true,
+ clip: Some(id),
+ language: self.settings.transcribe_language,
+ model,
+ placement: 0,
+ size: 1,
+ ..CaptionsSheet::default()
+ };
+ }
+
+ /// Runs the pass the sheet describes. The transcription runs on a
+ /// worker, reports into the sheet as it goes, and lands as one batch of
+ /// title clips - one undo step - when it is done.
+ pub fn captions_run(&mut self) {
+ let Some(clip) = self
+ .captions
+ .clip
+ .as_ref()
+ .and_then(|id| self.clip(id))
+ .cloned()
+ else {
+ self.captions.message = "The clip is no longer on the timeline".to_owned();
return;
};
let Some(media) = self.project().media_by_id(&clip.media_id).cloned() else {
- self.notify("This clip has no file to transcribe", true);
+ self.captions.message = "This clip has no file to transcribe".to_owned();
return;
};
- let Some(model) = self
- .transcribers
- .iter()
- .find(|model| model.active && model.installed)
+ let Some(model) = Self::installed(&self.transcribers)
+ .get(self.captions.model)
+ .map(|model| model.id.clone())
else {
- self.notify(
- "Download a transcriber model in Settings > Transcriber first",
- true,
- );
+ self.captions.message =
+ "Download a transcriber model in Settings › Transcriber first".to_owned();
return;
};
+ let language = TRANSCRIBE_LANGUAGES
+ .get(self.captions.language.max(0) as usize)
+ .copied()
+ .unwrap_or("auto");
+ let offset_y = CAPTION_OFFSETS[self.captions.placement.min(2)];
+ let font_size = CAPTION_SIZES[self.captions.size.min(2)];
let request = concat_speech::transcribe::TranscribeRequest {
path: media.path.clone(),
source_start: clip.source_start,
window: clip.duration * clip.speed,
- language: self.language_code().to_owned(),
- model_id: model.id.clone(),
+ language: language.to_owned(),
+ model_id: model,
};
let dirs = self.host.dirs.clone();
let transcriber = Arc::clone(&self.host.transcriber);
- self.notify("Transcribing…", false);
+ self.captions.running = true;
+ self.captions.progress = 0.0;
+ self.captions.message.clear();
spawn(
- move || transcriber.transcribe(&dirs, &request, |_| {}),
- move |studio, _, _, result| match result {
- Ok(segments) => {
- let commands: Vec<Command> = segments
- .iter()
- .map(|segment| Command::AddTextClip {
- track_id: None,
- start: clip.start + segment.start / clip.speed,
- style: Some(TextStyle {
- content: segment.text.clone(),
- font_family: "Inter".to_owned(),
- font_size: 0.05,
- font_weight: 600.0,
- ..TextStyle::default()
- }),
- duration: Some(((segment.end - segment.start) / clip.speed).max(0.2)),
- offset_y: Some(0.35),
- })
- .collect();
- let count = commands.len();
- if count == 0 {
- studio.notify("Nothing was said in that clip", true);
- } else {
- studio.apply(Command::Batch { commands });
- studio.notify(&format!("Added {count} captions"), false);
+ move || {
+ transcriber.transcribe(&dirs, &request, |percent| {
+ on_ui(move |studio, _, _| {
+ studio.captions.progress = (percent as f32 / 100.0).clamp(0.0, 1.0);
+ });
+ })
+ },
+ move |studio, _, _, result| {
+ studio.captions.running = false;
+ match result {
+ Ok(segments) => {
+ let commands: Vec<Command> = segments
+ .iter()
+ .filter(|segment| !segment.text.trim().is_empty())
+ .map(|segment| Command::AddTextClip {
+ track_id: None,
+ start: clip.start + segment.start / clip.speed,
+ style: Some(TextStyle {
+ content: segment.text.trim().to_owned(),
+ font_family: "Inter".to_owned(),
+ font_size,
+ font_weight: 600.0,
+ ..TextStyle::default()
+ }),
+ duration: Some(
+ ((segment.end - segment.start) / clip.speed).max(0.2),
+ ),
+ offset_y: Some(offset_y),
+ })
+ .collect();
+ let count = commands.len();
+ studio.captions.open = false;
+ if count == 0 {
+ studio.notify("Nothing was said in that clip", true);
+ } else {
+ studio.apply(Command::Batch { commands });
+ studio.notify(&format!("Added {count} captions"), false);
+ }
}
+ // Asked for: the sheet is already on its way down.
+ Err(error) if error.contains("cancel") => studio.captions.open = false,
+ Err(error) => studio.captions.message = error,
}
- Err(error) => studio.notify(&error, true),
},
);
}
- /// A title's words, spoken: the WAV lands in the project and on the
- /// timeline at the title's start.
- pub fn speak_selected(&mut self) {
- let Some(id) = self.sole_selection() else {
- return;
+ pub fn captions_cancel(&mut self) {
+ self.host.transcriber.cancel();
+ self.captions.running = false;
+ self.captions.open = false;
+ }
+
+ /// Opens the speech sheet: on the selected title's words when a title
+ /// is selected, else on a blank script to be read at the playhead. The
+ /// voice is the one chosen last time.
+ pub fn speech_open(&mut self) {
+ let title = self
+ .sole_selection()
+ .and_then(|id| self.clip(&id))
+ .filter(|clip| clip.kind == model::ClipKind::Text)
+ .cloned();
+ let installed = Self::installed(&self.voices);
+ let model = installed.iter().position(|model| model.active).unwrap_or(0);
+ let wanted = self.prefs.tts_voice.unwrap_or(DEFAULT_VOICE);
+ let voice = self
+ .speakers
+ .iter()
+ .position(|speaker| speaker.id == wanted)
+ .unwrap_or(0);
+ self.speech = SpeechSheet {
+ open: true,
+ clip: title.as_ref().map(|clip| clip.id.clone()),
+ text: title
+ .and_then(|clip| clip.text.map(|text| text.content))
+ .unwrap_or_default(),
+ voice,
+ model,
+ pace: 1,
+ ..SpeechSheet::default()
};
- let Some(clip) = self.clip(&id).cloned() else {
+ }
+
+ /// Reads the script: the WAV lands in the bin and on the timeline, at
+ /// the title's start or at the playhead.
+ pub fn speech_run(&mut self) {
+ let text = self.speech.text.trim().to_owned();
+ if text.is_empty() {
+ self.speech.message = "Nothing to read yet".to_owned();
return;
- };
- let Some(text) = clip.text.as_ref().map(|text| text.content.clone()) else {
- self.notify("Select a title to speak", true);
+ }
+ let Some(model) = Self::installed(&self.voices)
+ .get(self.speech.model)
+ .map(|model| model.id.clone())
+ else {
+ self.speech.message = "Download a voice model in Settings › Speech first".to_owned();
return;
};
- let Some(model) = self
- .voices
- .iter()
- .find(|model| model.active && model.installed)
- else {
- self.notify("Download a voice model in Settings > Speech first", true);
+ let Some(voice) = self.speakers.get(self.speech.voice).map(|speaker| speaker.id) else {
+ self.speech.message = "No voice to read with".to_owned();
return;
};
let Some(project) = self
@@ -3663,48 +3814,127 @@ impl Studio {
else {
return;
};
+ // Remembered: the voice chosen is the voice wanted next time.
+ self.prefs.tts_voice = Some(voice);
+ self.prefs.save(&self.host.dirs);
+ let start = self
+ .speech
+ .clip
+ .as_ref()
+ .and_then(|id| self.clip(id))
+ .map(|clip| clip.start)
+ .unwrap_or(f64::from(self.playhead));
let request = concat_speech::tts::SpeakRequest {
- model_id: model.id.clone(),
- voice: self.prefs.tts_voice.unwrap_or(DEFAULT_VOICE),
+ model_id: model,
+ voice,
text,
- speed: 1.0,
+ speed: PACES[self.speech.pace.min(2)],
project,
};
let dirs = self.host.dirs.clone();
let speech = Arc::clone(&self.host.speech);
- self.notify("Generating voice…", false);
+ self.speech.running = true;
+ self.speech.progress = 0.0;
+ self.speech.message.clear();
spawn(
move || {
- let spoken = speech.speak(&dirs, &request, |_| {})?;
+ let spoken = speech.speak(&dirs, &request, |fraction| {
+ on_ui(move |studio, _, _| {
+ studio.speech.progress = fraction.clamp(0.0, 1.0);
+ });
+ })?;
let summary = media::probe(&spoken.path)?;
Ok::<_, String>(summary)
},
- move |studio, _, _, result| match result {
- Ok(summary) => {
- let created = studio.apply(Command::AddMedia {
- item: summary.to_new_media(),
- });
- let media_id = created.or_else(|| {
- studio
- .project()
- .media
- .iter()
- .find(|item| item.path == summary.path)
- .map(|item| item.id.clone())
- });
- if let Some(media_id) = media_id {
- studio.apply(Command::AddClipAtFirstFree {
- media_id,
- start: clip.start,
+ move |studio, _, _, result| {
+ studio.speech.running = false;
+ match result {
+ Ok(summary) => {
+ let created = studio.apply(Command::AddMedia {
+ item: summary.to_new_media(),
});
- studio.notify("Voice added at the title", false);
+ let media_id = created.or_else(|| {
+ studio
+ .project()
+ .media
+ .iter()
+ .find(|item| item.path == summary.path)
+ .map(|item| item.id.clone())
+ });
+ studio.speech.open = false;
+ if let Some(media_id) = media_id {
+ studio.apply(Command::AddClipAtFirstFree { media_id, start });
+ studio.notify("Voice added to the timeline", false);
+ }
}
+ Err(error) if error.contains("cancel") => studio.speech.open = false,
+ Err(error) => studio.speech.message = error,
}
- Err(error) => studio.notify(&error, true),
},
);
}
+ pub fn speech_cancel(&mut self) {
+ self.host.speech.cancel();
+ self.speech.running = false;
+ self.speech.open = false;
+ }
+
+ /// "af_heart" as a person would say it: the name, and the accent and
+ /// gender its prefix encodes.
+ fn voice_label(name: &str) -> (String, String) {
+ let (prefix, rest) = name.split_once('_').unwrap_or(("", name));
+ let mut chars = rest.chars();
+ let title = match chars.next() {
+ Some(first) => first.to_uppercase().collect::<String>() + chars.as_str(),
+ None => String::new(),
+ };
+ let accent = match prefix.chars().next() {
+ Some('a') => "American",
+ Some('b') => "British",
+ Some('e') => "Spanish",
+ Some('f') => "French",
+ Some('h') => "Hindi",
+ Some('i') => "Italian",
+ Some('j') => "Japanese",
+ Some('p') => "Portuguese",
+ Some('z') => "Chinese",
+ _ => "",
+ };
+ let gender = match prefix.chars().nth(1) {
+ Some('f') => "female",
+ Some('m') => "male",
+ _ => "",
+ };
+ let detail = [accent, gender]
+ .iter()
+ .filter(|part| !part.is_empty())
+ .copied()
+ .collect::<Vec<_>>()
+ .join(" · ");
+ (title, detail)
+ }
+
+ /// What the sheet's script would take to say, for the line under it.
+ fn speech_estimate(&self) -> String {
+ let chars = self.speech.text.trim().chars().count();
+ if chars == 0 {
+ return "Nothing to read yet".to_owned();
+ }
+ let seconds = chars as f32 / CHARS_PER_SECOND / PACES[self.speech.pace.min(2)];
+ let whole = seconds.round() as i32;
+ let voice = self
+ .speakers
+ .get(self.speech.voice)
+ .map(|speaker| Self::voice_label(&speaker.name).0)
+ .unwrap_or_default();
+ format!(
+ "About {}:{:02} in {voice} · {chars} characters",
+ whole / 60,
+ whole % 60
+ )
+ }
+
/// Packs the open project into the template library.
pub fn save_template(&mut self) {
let Some(session) = self.session.as_ref() else {
@@ -3910,7 +4140,11 @@ impl Studio {
editor.set_tool(self.tool);
editor.set_snap(self.snap);
editor.set_selected_count(self.selection.len() as i32);
- editor.set_has_av_tools(self.has_av_tools());
+ let (can_caption, can_speak, can_detach, can_reattach) = self.sound_tools();
+ editor.set_can_caption(can_caption);
+ editor.set_can_speak(can_speak);
+ editor.set_can_detach(can_detach);
+ editor.set_can_reattach(can_reattach);
editor.set_merge_blocked_because(match self.merge_blocked() {
Some(reason) => reason.into(),
None => SharedString::new(),
@@ -4226,10 +4460,73 @@ impl Studio {
sync(&models.transcribers, Self::model_rows(&self.transcribers));
sync(&models.voices, Self::model_rows(&self.voices));
- let av = self.av_menu();
- editor.set_av_height(Self::menu_height(&av));
- sync(&models.av, av);
- editor.set_av_token(self.av_token);
+ // The speech sheets, and the lists they choose from.
+ let transcribers = Self::installed(&self.transcribers);
+ sync(
+ &models.caption_models,
+ transcribers
+ .iter()
+ .map(|model| SharedString::from(model.name.as_str()))
+ .collect(),
+ );
+ app.set_captions(CaptionsSheetData {
+ open: self.captions.open,
+ clip: self
+ .captions
+ .clip
+ .as_ref()
+ .and_then(|id| self.clip(id))
+ .map(|clip| SharedString::from(clip.name.as_str()))
+ .unwrap_or_default(),
+ language: self.captions.language,
+ model: self.captions.model as i32,
+ placement: self.captions.placement as i32,
+ size: self.captions.size as i32,
+ running: self.captions.running,
+ progress: self.captions.progress,
+ ready: !transcribers.is_empty(),
+ message: self.captions.message.as_str().into(),
+ });
+ let voices = Self::installed(&self.voices);
+ sync(
+ &models.speech_models,
+ voices
+ .iter()
+ .map(|model| SharedString::from(model.name.as_str()))
+ .collect(),
+ );
+ sync(
+ &models.speakers,
+ self.speakers
+ .iter()
+ .map(|speaker| Self::voice_label(&speaker.name).0.into())
+ .collect(),
+ );
+ sync(
+ &models.speaker_details,
+ self.speakers
+ .iter()
+ .map(|speaker| Self::voice_label(&speaker.name).1.into())
+ .collect(),
+ );
+ app.set_speech(SpeechSheetData {
+ open: self.speech.open,
+ text: self.speech.text.as_str().into(),
+ voice: self.speech.voice as i32,
+ model: self.speech.model as i32,
+ pace: self.speech.pace as i32,
+ running: self.speech.running,
+ progress: self.speech.progress,
+ ready: !voices.is_empty(),
+ placement: if self.speech.clip.is_some() {
+ "at the title"
+ } else {
+ "at the playhead"
+ }
+ .into(),
+ estimate: self.speech_estimate().into(),
+ message: self.speech.message.as_str().into(),
+ });
let bar = self.menu_bar();
app.set_app_menu_height(Self::menu_height(&bar));
@@ -4421,54 +4718,6 @@ impl Studio {
rows.iter().map(|row| metrics(row.kind)).sum::<f32>() + 12.0
}
- /// The tray's A/V menu. What it offers depends on what is selected.
- fn av_menu(&self) -> Vec<MenuItemData> {
- let Some(clip) = self.sole_selection().and_then(|id| self.clip(&id)) else {
- return Vec::new();
- };
- let row = |id: &str, label: &str, glyph: Glyph, enabled: bool| MenuItemData {
- id: id.into(),
- label: label.into(),
- kind: MenuRow::Action,
- glyph,
- shortcut: SharedString::new(),
- enabled,
- danger: false,
- checkable: false,
- checked: false,
- };
- if clip.kind == model::ClipKind::Text {
- return vec![row("speak", "Generate voice", Glyph::Volume, true)];
- }
- let has_sound = clip.kind != model::ClipKind::Image;
- let detached = self
- .timeline()
- .clips
- .iter()
- .any(|other| other.detached_from.as_deref() == Some(clip.id.as_str()));
- vec![
- row("captions", "Auto captions", Glyph::TextMark, has_sound),
- MenuItemData {
- kind: MenuRow::Separator,
- ..Default::default()
- },
- row(
- "detach",
- "Detach audio",
- Glyph::Waveform,
- clip.kind == model::ClipKind::Video && !detached,
- ),
- row(
- "reattach",
- "Reattach audio",
- Glyph::Merge,
- (clip.kind == model::ClipKind::Video && detached)
- || (clip.kind == model::ClipKind::Audio && clip.detached_from.is_some()),
- ),
- ]
- }
-
- /// The File / Edit / View menus.
fn menu_bar(&self) -> Vec<MenuItemData> {
let row =
|id: &str, label: String, glyph: Glyph, shortcut: &str, enabled: bool| MenuItemData {
diff --git a/engine/crates/concat/ui/app.slint b/engine/crates/concat/ui/app.slint
index fcebe38f..ffe1f6a2 100644
--- a/engine/crates/concat/ui/app.slint
+++ b/engine/crates/concat/ui/app.slint
@@ -24,6 +24,8 @@ import { ContextMenu, MenuItemData, MenuRow } from "primitives/context-menu.slin
import { ExportData, ExportDialog, ExportPhase } from "dialogs/export.slint";
import { ModelData, SettingsData, SettingsDialog, SystemFactData } from "dialogs/settings.slint";
import { ProjectDialog, ProjectSheetData } from "dialogs/project.slint";
+import { CaptionsDialog, CaptionsSheetData } from "dialogs/captions.slint";
+import { SpeechDialog, SpeechSheetData } from "dialogs/speech.slint";
import { DockDivider, DockSide, SeatBox } from "dock.slint";
import { Editor } from "editor.slint";
import { PaneKind } from "workspace/pane-switcher.slint";
@@ -52,6 +54,7 @@ export {
StageGuideData, StageItemData, TextAlignment, TimelineTabData, TimelineTool,
TrackData, TrackSize, MenuItemData, MenuRow, ExportData, ExportPhase, ModelData, SettingsData,
RecentProjectData, StartData, SystemFactData, ToastData, ProjectSheetData,
+ CaptionsSheetData, SpeechSheetData,
}
export component App inherits Window {
@@ -163,6 +166,31 @@ export component App inherits Window {
callback project-rate-changed(index: int);
callback project-apply();
+ /// The two speech sheets: captions from a clip's sound, and a title's
+ /// words - or any words - read aloud. Their option lists come from what
+ /// is installed, so they are handed over as models.
+ in property <CaptionsSheetData> captions;
+ in property <[string]> caption-models;
+ callback captions-closed();
+ callback captions-language-changed(index: int);
+ callback captions-model-changed(index: int);
+ callback captions-placement-changed(index: int);
+ callback captions-size-changed(index: int);
+ callback captions-begin();
+ callback captions-cancel();
+
+ in property <SpeechSheetData> speech;
+ in property <[string]> speech-models;
+ in property <[string]> speech-voices;
+ in property <[string]> speech-voice-details;
+ callback speech-closed();
+ callback speech-text-edited(text: string);
+ callback speech-voice-changed(index: int);
+ callback speech-model-changed(index: int);
+ callback speech-pace-changed(index: int);
+ callback speech-begin();
+ callback speech-cancel();
+
/// Takes focus back from whatever field holds it. The keyboard scope is
/// where focus rests when nothing is being typed into, so giving it the
/// focus is what "click beside the field" means; Rust calls this for
@@ -417,6 +445,42 @@ export component App inherits Window {
apply => { root.project-apply(); }
}
+ CaptionsDialog {
+ x: 0;
+ y: 0;
+ width: root.width;
+ height: root.height;
+ data: root.captions;
+ models: root.caption-models;
+
+ closed => { root.captions-closed(); }
+ language-changed(index) => { root.captions-language-changed(index); }
+ model-changed(index) => { root.captions-model-changed(index); }
+ placement-changed(index) => { root.captions-placement-changed(index); }
+ size-changed(index) => { root.captions-size-changed(index); }
+ begin => { root.captions-begin(); }
+ cancel => { root.captions-cancel(); }
+ }
+
+ SpeechDialog {
+ x: 0;
+ y: 0;
+ width: root.width;
+ height: root.height;
+ data: root.speech;
+ models: root.speech-models;
+ voices: root.speech-voices;
+ voice-details: root.speech-voice-details;
+
+ closed => { root.speech-closed(); }
+ text-edited(text) => { root.speech-text-edited(text); }
+ voice-changed(index) => { root.speech-voice-changed(index); }
+ model-changed(index) => { root.speech-model-changed(index); }
+ pace-changed(index) => { root.speech-pace-changed(index); }
+ begin => { root.speech-begin(); }
+ cancel => { root.speech-cancel(); }
+ }
+
// Over the workspace and both sheets, under the menus. A tooltip has to
// clear the pane it belongs to — panes clip — and it has no business over
// an open menu, which is the one surface that would rather not be
diff --git a/engine/crates/concat/ui/dialogs/captions.slint b/engine/crates/concat/ui/dialogs/captions.slint
new file mode 100644
index 00000000..cfb3e44f
--- /dev/null
+++ b/engine/crates/concat/ui/dialogs/captions.slint
@@ -0,0 +1,196 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+// SPDX-FileCopyrightText: 2026 Jareer and Concat contributors
+
+import { Theme } from "../theme/theme.slint";
+import { Glyph, Icon } from "../icons.slint";
+import { Button, DialogRow, DialogSection, Modal, Progress } from "../primitives/modal.slint";
+import { SegmentedControl } from "../primitives/segmented-control.slint";
+import { Select } from "../primitives/select.slint";
+
+// Auto captions: what the tray's Captions tool opens.
+//
+// The choices a caption pass turns on - which language the speech is in,
+// which model listens, where the lines sit and how big they are - then one
+// button. While it runs the sheet is the progress report: a transcription
+// knows how far through the sound it is, so it gets a real bar and not a
+// sweep.
+
+export struct CaptionsSheetData {
+ open: bool,
+ /// The clip being transcribed, for the header's note.
+ clip: string,
+ /// 0 Auto, 1 English, 2 Chinese - the transcriber's own list.
+ language: int,
+ /// Row in the installed transcriber list.
+ model: int,
+ /// 0 Bottom, 1 Centre, 2 Top
+ placement: int,
+ /// 0 Small, 1 Medium, 2 Large
+ size: int,
+ running: bool,
+ /// 0..1
+ progress: float,
+ /// A transcriber model is installed.
+ ready: bool,
+ /// Why the last run failed, when it did.
+ message: string,
+}
+
+export component CaptionsDialog inherits Modal {
+ in property <CaptionsSheetData> data;
+ /// The installed transcriber models, by name.
+ in property <[string]> models;
+
+ callback language-changed(index: int);
+ callback model-changed(index: int);
+ callback placement-changed(index: int);
+ callback size-changed(index: int);
+ callback begin();
+ callback cancel();
+
+ open: root.data.open;
+ title: "Auto captions";
+ glyph: Glyph.text-mark;
+ surface-width: 460px;
+ dismissable: !root.data.running;
+ note: root.data.clip;
+
+ VerticalLayout {
+ if !root.data.running: DialogSection {
+ first: true;
+ title: "Transcriber";
+
+ DialogRow {
+ label: "Language";
+ SegmentedControl {
+ options: ["Auto", "English", "Chinese"];
+ current: root.data.language;
+ changed(index) => { root.language-changed(index); }
+ }
+ }
+
+ DialogRow {
+ label: "Model";
+ Select {
+ options: root.models;
+ current: root.data.model;
+ placeholder: "None installed";
+ enabled: root.models.length > 0;
+ changed(index) => { root.model-changed(index); }
+ }
+ }
+
+ if !root.data.ready: Text {
+ text: "Download a transcriber model in Settings › Transcriber first.";
+ color: Theme.fg-muted;
+ font-size: Theme.fs-sm;
+ wrap: word-wrap;
+ }
+ }
+
+ if !root.data.running: DialogSection {
+ title: "Captions";
+
+ DialogRow {
+ label: "Placement";
+ SegmentedControl {
+ options: ["Bottom", "Centre", "Top"];
+ current: root.data.placement;
+ changed(index) => { root.placement-changed(index); }
+ }
+ }
+
+ DialogRow {
+ label: "Size";
+ SegmentedControl {
+ options: ["Small", "Medium", "Large"];
+ current: root.data.size;
+ changed(index) => { root.size-changed(index); }
+ }
+ }
+
+ Text {
+ text: "One title per phrase spoken, cut to the words' own timing,"
+ + " on the first lane with room.";
+ color: Theme.fg-dim;
+ font-size: Theme.fs-sm;
+ wrap: word-wrap;
+ }
+ }
+
+ Rectangle {
+ height: 1px;
+ background: Theme.line;
+ }
+
+ VerticalLayout {
+ padding: 14px;
+ spacing: 10px;
+
+ if root.data.message != "": Rectangle {
+ border-radius: Theme.r;
+ background: Theme.danger-soft;
+
+ HorizontalLayout {
+ padding: 10px;
+ spacing: 8px;
+
+ VerticalLayout {
+ alignment: start;
+ Icon { glyph: Glyph.close; size: 13px; tint: Theme.danger; }
+ }
+
+ Text {
+ horizontal-stretch: 1;
+ text: root.data.message;
+ color: Theme.danger;
+ font-size: Theme.fs-sm;
+ wrap: word-wrap;
+ }
+ }
+ }
+
+ if root.data.running: HorizontalLayout {
+ spacing: 8px;
+
+ Text {
+ horizontal-stretch: 1;
+ text: root.data.progress < 0.02 ? "Loading the model" : "Transcribing";
+ color: Theme.fg;
+ font-size: Theme.fs;
+ vertical-alignment: center;
+ }
+
+ Text {
+ text: "\{Math.round(root.data.progress * 100)}%";
+ color: Theme.fg-muted;
+ font-family: Theme.font-technical;
+ font-size: Theme.fs;
+ vertical-alignment: center;
+ }
+ }
+
+ if root.data.running: Progress { value: root.data.progress; }
+
+ if root.data.running: HorizontalLayout {
+ alignment: start;
+ Button {
+ label: "Cancel";
+ glyph: Glyph.close;
+ ghost: true;
+ clicked => { root.cancel(); }
+ }
+ }
+
+ if !root.data.running: Button {
+ block: true;
+ primary: true;
+ large: true;
+ glyph: Glyph.text-mark;
+ label: "Generate captions";
+ enabled: root.data.ready;
+ clicked => { root.begin(); }
+ }
+ }
+ }
+}
diff --git a/engine/crates/concat/ui/dialogs/speech.slint b/engine/crates/concat/ui/dialogs/speech.slint
new file mode 100644
index 00000000..be3814b3
--- /dev/null
+++ b/engine/crates/concat/ui/dialogs/speech.slint
@@ -0,0 +1,258 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+// SPDX-FileCopyrightText: 2026 Jareer and Concat contributors
+
+import { Theme } from "../theme/theme.slint";
+import { Glyph, Icon } from "../icons.slint";
+import { Button, DialogRow, DialogSection, Modal, Progress } from "../primitives/modal.slint";
+import { SegmentedControl } from "../primitives/segmented-control.slint";
+import { Select } from "../primitives/select.slint";
+
+// Text to speech: what the tray's Speak tool and File › Text to speech open.
+//
+// A text box, a voice and a button is enough to send a job and not enough to
+// get the read you wanted, so the three things that change a read are on the
+// surface: which voice, which model, and the pace. Opened from a title the
+// script is the title's words; opened from the menu it is whatever you type.
+// While it runs the sheet is the progress report, with a clock beside it.
+
+export struct SpeechSheetData {
+ open: bool,
+ text: string,
+ /// Row in the voice list.
+ voice: int,
+ /// Row in the installed voice model list.
+ model: int,
+ /// 0 Slower, 1 Natural, 2 Faster
+ pace: int,
+ running: bool,
+ /// 0..1, as sentences complete.
+ progress: float,
+ /// A voice model is installed.
+ ready: bool,
+ /// Where the sound will land, for the header's note.
+ placement: string,
+ /// "About 0:12 in Heart", or what stops it being read.
+ estimate: string,
+ /// Why the last run failed, when it did.
+ message: string,
+}
+
+export component SpeechDialog inherits Modal {
+ in property <SpeechSheetData> data;
+ in property <[string]> models;
+ in property <[string]> voices;
+ /// "American · female", beside each voice.
+ in property <[string]> voice-details;
+
+ callback text-edited(text: string);
+ callback voice-changed(index: int);
+ callback model-changed(index: int);
+ callback pace-changed(index: int);
+ callback begin();
+ callback cancel();
+
+ open: root.data.open;
+ title: "Text to speech";
+ glyph: Glyph.volume;
+ surface-width: 520px;
+ dismissable: !root.data.running;
+ note: root.data.placement;
+
+ // The script being typed, held apart from `data.text` the way the Field
+ // primitive holds its draft: a TextInput's binding is dropped on the
+ // first keystroke, so the sheet re-seeds it when it opens and never
+ // while it is being typed into.
+ property <string> draft;
+ property <bool> running: root.data.running;
+ /// The script has the caret. Kept up here because the box lives under
+ /// an `if`, and nothing outside one can reach into it.
+ property <bool> typing;
+ changed data => {
+ if (!root.typing) {
+ root.draft = root.data.text;
+ }
+ }
+ init => { root.draft = root.data.text; }
+
+ /// Seconds since the run began; the reference beside the bar.
+ property <int> elapsed;
+ changed running => { root.elapsed = 0; }
+ Timer {
+ interval: 1s;
+ running: root.running;
+ triggered => { root.elapsed += 1; }
+ }
+
+ VerticalLayout {
+ if !root.running: DialogSection {
+ first: true;
+ title: "Script";
+
+ Rectangle {
+ height: 104px;
+ border-radius: Theme.r;
+ background: Theme.well;
+ border-width: 1px;
+ border-color: script.has-focus ? Theme.accent : Theme.line;
+ clip: true;
+
+ script := TextInput {
+ x: 10px;
+ y: 8px;
+ width: parent.width - 20px;
+ height: parent.height - 16px;
+ text <=> root.draft;
+ color: Theme.fg;
+ font-size: Theme.fs-lg;
+ single-line: false;
+ wrap: word-wrap;
+ selection-background-color: Theme.accent;
+ selection-foreground-color: Theme.on-accent;
+ changed has-focus => { root.typing = self.has-focus; }
+ edited => { root.text-edited(self.text); }
+ }
+
+ if root.draft == "" && !script.has-focus: Text {
+ x: 10px;
+ y: 8px;
+ text: "Type the narration to read aloud…";
+ color: Theme.fg-dim;
+ font-size: Theme.fs-lg;
+ }
+ }
+
+ Text {
+ text: root.data.estimate;
+ color: Theme.fg-dim;
+ font-family: Theme.font-technical;
+ font-size: Theme.fs-sm;
+ }
+ }
+
+ if !root.running: DialogSection {
+ title: "Voice";
+
+ DialogRow {
+ label: "Voice";
+ Select {
+ options: root.voices;
+ details: root.voice-details;
+ current: root.data.voice;
+ changed(index) => { root.voice-changed(index); }
+ }
+ }
+
+ DialogRow {
+ label: "Model";
+ Select {
+ options: root.models;
+ current: root.data.model;
+ placeholder: "None installed";
+ enabled: root.models.length > 0;
+ changed(index) => { root.model-changed(index); }
+ }
+ }
+
+ DialogRow {
+ label: "Pace";
+ SegmentedControl {
+ options: ["Slower", "Natural", "Faster"];
+ current: root.data.pace;
+ changed(index) => { root.pace-changed(index); }
+ }
+ }
+
+ if !root.data.ready: Text {
+ text: "Download a voice model in Settings › Speech first.";
+ color: Theme.fg-muted;
+ font-size: Theme.fs-sm;
+ wrap: word-wrap;
+ }
+ }
+
+ Rectangle {
+ height: 1px;
+ background: Theme.line;
+ }
+
+ VerticalLayout {
+ padding: 14px;
+ spacing: 10px;
+
+ if root.data.message != "": Rectangle {
+ border-radius: Theme.r;
+ background: Theme.danger-soft;
+
+ HorizontalLayout {
+ padding: 10px;
+ spacing: 8px;
+
+ VerticalLayout {
+ alignment: start;
+ Icon { glyph: Glyph.close; size: 13px; tint: Theme.danger; }
+ }
+
+ Text {
+ horizontal-stretch: 1;
+ text: root.data.message;
+ color: Theme.danger;
+ font-size: Theme.fs-sm;
+ wrap: word-wrap;
+ }
+ }
+ }
+
+ if root.running: HorizontalLayout {
+ spacing: 8px;
+
+ Text {
+ horizontal-stretch: 1;
+ text: "Generating voice";
+ color: Theme.fg;
+ font-size: Theme.fs;
+ vertical-alignment: center;
+ }
+
+ Text {
+ text: "\{Math.round(root.data.progress * 100)}%";
+ color: Theme.fg-muted;
+ font-family: Theme.font-technical;
+ font-size: Theme.fs;
+ vertical-alignment: center;
+ }
+
+ Text {
+ text: "\{Math.floor(root.elapsed / 60)}:"
+ + (Math.mod(root.elapsed, 60) < 10 ? "0" : "")
+ + "\{Math.mod(root.elapsed, 60)}";
+ color: Theme.fg-dim;
+ font-family: Theme.font-technical;
+ font-size: Theme.fs;
+ vertical-alignment: center;
+ }
+ }
+
+ if root.running: Progress { value: root.data.progress; }
+
+ if root.running: HorizontalLayout {
+ alignment: start;
+ Button {
+ label: "Cancel";
+ glyph: Glyph.close;
+ ghost: true;
+ clicked => { root.cancel(); }
+ }
+ }
+
+ if !root.running: Button {
+ block: true;
+ primary: true;
+ large: true;
+ glyph: Glyph.volume;
+ label: "Generate speech";
+ enabled: root.data.ready && root.data.text != "";
+ clicked => { root.begin(); }
+ }
+ }
+ }
+}
diff --git a/engine/crates/concat/ui/editor.slint b/engine/crates/concat/ui/editor.slint
index 3488fbae..f7ed649d 100644
--- a/engine/crates/concat/ui/editor.slint
+++ b/engine/crates/concat/ui/editor.slint
@@ -186,7 +186,13 @@ export global Editor {
in-out property <bool> snap;
in-out property <int> selected-count;
in-out property <string> merge-blocked-because;
- in-out property <bool> has-av-tools;
+ /// What the tray's sound and word tools may do to the selection: one
+ /// clip with sound to caption, one title to speak, one video clip whose
+ /// sound is on it to detach, or whose sound is off it to put back.
+ in-out property <bool> can-caption;
+ in-out property <bool> can-speak;
+ in-out property <bool> can-detach;
+ in-out property <bool> can-reattach;
in-out property <float> playhead;
in-out property <float> frame-rate;
in-out property <float> scroll-left;
@@ -201,11 +207,12 @@ export global Editor {
callback split();
callback merge();
callback delete-selected();
- callback av-tools();
- in-out property <[MenuItemData]> av-items;
- in-out property <length> av-height;
- in-out property <int> av-token;
- callback av-selected(id: string);
+ /// The tray's tools for a clip's sound and words. The first two open a
+ /// sheet; the last two are the edit itself.
+ callback captions();
+ callback speak();
+ callback detach-audio();
+ callback reattach-audio();
callback add-track();
callback zoom-to-fit(width: length);
callback zoom(factor: float, anchor-seconds: float);
diff --git a/engine/crates/concat/ui/inspector/controls.slint b/engine/crates/concat/ui/inspector/controls.slint
index 8d5d4983..fe659cf3 100644
--- a/engine/crates/concat/ui/inspector/controls.slint
+++ b/engine/crates/concat/ui/inspector/controls.slint
@@ -143,6 +143,12 @@ export global InspectorSearch {
}
// Horizontal fader. Click to jump, drag to ride, double-click to reset.
+//
+// A sunken track the height of a field, filled from the left in the soft
+// accent up to a bar in the full one. The fill is what reads at a glance -
+// how much of the range is dialled in - and the bar, not a bead, is what
+// lands on a value: flat edges have a precision a circle never has, and at
+// zero the bar still sits inside the track rather than hanging off its end.
export component Fader inherits Rectangle {
in-out property <float> value;
in property <float> minimum: 0;
@@ -154,12 +160,18 @@ export component Fader inherits Rectangle {
callback changed(value: float);
- height: 18px;
+ height: Theme.h;
+ border-radius: Theme.r;
+ border-width: 1px;
+ border-color: (touch.has-hover && root.enabled) ? Theme.line-strong : Theme.line;
+ background: Theme.well;
opacity: root.enabled ? 1.0 : 0.45;
+ animate border-color { duration: 100ms; easing: cubic-bezier(0.4, 0, 0.2, 1); }
+
property <float> span: Math.max(root.maximum - root.minimum, 0.000001);
- // The rail is inset so the cap lands under the pointer at both ends
- // instead of a few px short of them.
+ // The rail is inset by the border and two pixels, so the bar lands under
+ // the pointer at both ends instead of a few px short of them.
property <length> inset: 3px;
property <length> usable: Math.max(1px, root.width - 2 * root.inset);
property <float> percent: Fmt.clamp((root.value - root.minimum) / root.span, 0, 1);
@@ -194,33 +206,25 @@ export component Fader inherits Rectangle {
}
}
- rail := Rectangle {
+ fill := Rectangle {
x: root.inset;
- y: (parent.height - self.height) / 2;
- width: root.usable;
- height: 4px;
- border-radius: 2px;
- background: Theme.field-active;
-
- Rectangle {
- x: 0;
- y: 0;
- width: parent.width * root.percent;
- height: parent.height;
- border-radius: 2px;
- background: Theme.accent;
- }
+ y: root.inset;
+ width: root.usable * root.percent;
+ height: parent.height - 2 * root.inset;
+ border-radius: Theme.r-xs;
+ background: Theme.accent-soft;
}
cap := Rectangle {
x: root.inset + root.usable * root.percent - self.width * root.percent;
- y: (parent.height - self.height) / 2;
- width: 10px;
- height: 14px;
- border-radius: 3px;
- background: Theme.fg;
- border-width: 1px;
- border-color: Theme.line-strong;
+ y: root.inset;
+ width: 3px;
+ height: parent.height - 2 * root.inset;
+ border-radius: 2px;
+ background: (touch.has-hover || touch.pressed) && root.enabled
+ ? Theme.accent-hover : Theme.accent;
+
+ animate background { duration: 100ms; easing: cubic-bezier(0.4, 0, 0.2, 1); }
}
}
diff --git a/engine/crates/concat/ui/primitives/panel.slint b/engine/crates/concat/ui/primitives/panel.slint
index 8eb6bbb7..651c9660 100644
--- a/engine/crates/concat/ui/primitives/panel.slint
+++ b/engine/crates/concat/ui/primitives/panel.slint
@@ -86,11 +86,19 @@ export component SectionHeader inherits Rectangle {
in-out property <bool> open: true;
height: 36px;
+ // A step up from the panel, so a column of sections reads as a stack of
+ // labelled drawers rather than one long form - the same lift a dialog's
+ // collapsible group has, and the same answer to the pointer when the
+ // header is one that opens.
+ background: root.collapsible && head.has-hover ? Theme.field : Theme.raised;
+
+ animate background { duration: 100ms; easing: cubic-bezier(0.4, 0, 0.2, 1); }
// Sits below the row so action buttons, added later in the tree, stay on
// top of it; the title Text itself takes no pointer events.
- if root.collapsible: TouchArea {
- mouse-cursor: pointer;
+ head := TouchArea {
+ enabled: root.collapsible;
+ mouse-cursor: root.collapsible ? pointer : default;
clicked => {
root.open = !root.open;
}
diff --git a/engine/crates/concat/ui/timeline/tray.slint b/engine/crates/concat/ui/timeline/tray.slint
index 26071215..cdb33809 100644
--- a/engine/crates/concat/ui/timeline/tray.slint
+++ b/engine/crates/concat/ui/timeline/tray.slint
@@ -4,22 +4,93 @@
import { Theme } from "../theme/theme.slint";
import { Glyph, Icon } from "../icons.slint";
import { IconButton } from "../primitives/panel.slint";
+import { Tip } from "../primitives/tooltip.slint";
import { TimelineTool } from "model.slint";
// The timeline's tool tray.
//
-// The tool set: pointer and razor, then the three edit actions, then snapping
-// and the A/V tools, then add-track, and the view controls pushed to the far
-// end behind the timecode readout. The metrics: 40px tall, 4px between
-// buttons, an 18px hairline with 4px of air on each side between groups.
-// Tight, without crowding a 26px button.
+// The tool set: pointer and razor, then the three edit actions, then
+// snapping, then the tools a clip's sound and words need - captions, a
+// spoken title, detaching the sound - then add-track, and the view controls
+// pushed to the far end behind the timecode readout. The metrics: 40px
+// tall, 4px between buttons, an 18px hairline with 4px of air on each side
+// between groups. Tight, without crowding a 26px button.
//
-// Two decisions worth naming. A disabled Merge carries the reason it is
-// blocked, because a button that greys out without saying why leaves you
-// guessing at the rule: `merge-blocked-because` is accepted and becomes the
-// button's label, which is its accessible name and where a tooltip reads
-// from. And the A/V tools button only reports a press; the popup is the
-// caller's to grow.
+// The sound and word tools carry their names on the bar. They used to hang
+// off one menu button, and a menu is where a tool goes to not be found:
+// nobody looking for captions opens a waveform icon. Greyed rather than
+// absent when the selection cannot use them, because a greyed button with
+// a tip answers "why not" and an absent one only asks it.
+//
+// A disabled Merge carries the reason it is blocked, because a button that
+// greys out without saying why leaves you guessing at the rule:
+// `merge-blocked-because` is accepted and becomes the button's label, which
+// is its accessible name and where a tooltip reads from.
+
+// A tool with its name beside its mark: the same chip an IconButton is,
+// wide enough for a word.
+component TrayTool inherits Rectangle {
+ in property <Glyph> glyph;
+ in property <string> caption;
+ /// what the tip says; the reason, when the tool is greyed
+ in property <string> label;
+ in property <bool> enabled: true;
+
+ callback clicked();
+
+ property <bool> lit: touch.has-hover && root.enabled;
+ property <brush> tint: root.lit ? Theme.fg : Theme.fg-muted;
+
+ width: text.preferred-width + 35px;
+ min-height: 26px;
+
+ chip := Rectangle {
+ y: (root.height - self.height) / 2;
+ width: root.width;
+ height: 26px;
+ border-radius: Theme.r-sm;
+ opacity: root.enabled ? 1.0 : 0.4;
+ background: !root.enabled ? Colors.transparent
+ : touch.pressed ? Theme.field-active
+ : touch.has-hover ? Theme.field
+ : Colors.transparent;
+
+ animate background { duration: 100ms; easing: cubic-bezier(0.4, 0, 0.2, 1); }
+
+ HorizontalLayout {
+ padding-left: 8px;
+ padding-right: 9px;
+ spacing: 5px;
+
+ VerticalLayout {
+ alignment: center;
+ Icon {
+ glyph: root.glyph;
+ size: 14px;
+ tint: root.tint;
+ }
+ }
+
+ text := Text {
+ text: root.caption;
+ color: root.tint;
+ font-size: Theme.fs-sm;
+ vertical-alignment: center;
+ }
+ }
+
+ touch := TouchArea {
+ enabled: root.enabled;
+ mouse-cursor: pointer;
+ clicked => { root.clicked(); }
+ }
+
+ Tip {
+ text: root.label;
+ active: touch.has-hover;
+ }
+ }
+}
component Divider inherits Rectangle {
width: 9px;
@@ -39,8 +110,12 @@ export component TimelineTray inherits Rectangle {
in property <int> selected-count;
/// Empty when the selection can be merged; otherwise why it cannot.
in property <string> merge-blocked-because;
- /// The selected clip has sound to detach or words to speak.
- in property <bool> has-av-tools;
+ /// What the selection can have done to its sound and its words. Each
+ /// is one clip's worth of truth, decided by Rust; see the Editor global.
+ in property <bool> can-caption;
+ in property <bool> can-speak;
+ in property <bool> can-detach;
+ in property <bool> can-reattach;
/// hh:mm:ss:ff at the playhead, formatted by the caller
in property <string> readout;
@@ -49,7 +124,10 @@ export component TimelineTray inherits Rectangle {
callback split();
callback merge();
callback delete-selected();
- callback av-tools(at-x: length);
+ callback captions();
+ callback speak();
+ callback detach();
+ callback reattach();
callback add-track();
callback fit();
callback zoom(factor: float);
@@ -74,7 +152,7 @@ export component TimelineTray inherits Rectangle {
IconButton {
glyph: Glyph.pointer;
- label: "Select (V)";
+ label: "Select (A or V)";
icon-size: 16px;
checked: root.tool == TimelineTool.select;
clicked => { root.tool-changed(TimelineTool.select); }
@@ -91,7 +169,7 @@ export component TimelineTray inherits Rectangle {
IconButton {
glyph: Glyph.split;
- label: "Split at playhead (S)";
+ label: "Split at playhead (S, or ⌘B for every clip)";
icon-size: 16px;
clicked => { root.split(); }
}
@@ -138,24 +216,38 @@ export component TimelineTray inherits Rectangle {
clicked => { root.snap-changed(!root.snap); }
}
- // Only while the selected clip has tools to offer — sound to detach or
- // transcribe, or a title's words to speak. A menu of grey rows teaches
- // nothing, so the button is absent rather than disabled.
- if root.has-av-tools: HorizontalLayout {
- spacing: 0px;
- Divider { }
- av := IconButton {
- glyph: Glyph.waveform;
- label: "Audio and video tools";
- icon-size: 16px;
- wide: true;
- // Reported in the tray's own coordinates: the button slides
- // along the bar as the selection count and the merge reason
- // come and go, and a menu pinned to a guess would drift off it.
- clicked => {
- root.av-tools(av.absolute-position.x - root.absolute-position.x);
- }
- }
+ Divider { }
+
+ TrayTool {
+ glyph: Glyph.text-mark;
+ caption: "Captions";
+ label: root.can-caption ? "Auto captions from this clip's sound"
+ : "Select one clip with sound to caption it";
+ enabled: root.can-caption;
+ clicked => { root.captions(); }
+ }
+ TrayTool {
+ glyph: Glyph.volume;
+ caption: "Speak";
+ label: root.can-speak ? "Read this title aloud"
+ : "Select a title to read it aloud";
+ enabled: root.can-speak;
+ clicked => { root.speak(); }
+ }
+ // One slot, two verbs: the sound is either on its picture or off it.
+ if !root.can-reattach: TrayTool {
+ glyph: Glyph.waveform;
+ caption: "Detach audio";
+ label: root.can-detach ? "Put this clip's sound on its own lane"
+ : "Select one video clip to detach its sound";
+ enabled: root.can-detach;
+ clicked => { root.detach(); }
+ }
+ if root.can-reattach: TrayTool {
+ glyph: Glyph.merge;
+ caption: "Reattach";
+ label: "Put the detached sound back on its picture";
+ clicked => { root.reattach(); }
}
Divider { }
diff --git a/engine/crates/concat/ui/workspace/seat.slint b/engine/crates/concat/ui/workspace/seat.slint
index 3b2375a3..a2d9d684 100644
--- a/engine/crates/concat/ui/workspace/seat.slint
+++ b/engine/crates/concat/ui/workspace/seat.slint
@@ -277,7 +277,10 @@ export component Seat inherits Rectangle {
snap: Editor.snap;
selected-count: Editor.selected-count;
merge-blocked-because: Editor.merge-blocked-because;
- has-av-tools: Editor.has-av-tools;
+ can-caption: Editor.can-caption;
+ can-speak: Editor.can-speak;
+ can-detach: Editor.can-detach;
+ can-reattach: Editor.can-reattach;
playhead: Editor.playhead;
frame-rate: Editor.frame-rate;
scroll-left: Editor.scroll-left;
@@ -293,11 +296,10 @@ export component Seat inherits Rectangle {
split => { Editor.split(); }
merge => { Editor.merge(); }
delete-selected => { Editor.delete-selected(); }
- av-tools => { Editor.av-tools(); }
- av-items: Editor.av-items;
- av-height: Editor.av-height;
- av-token: Editor.av-token;
- av-selected(id) => { Editor.av-selected(id); }
+ captions => { Editor.captions(); }
+ speak => { Editor.speak(); }
+ detach => { Editor.detach-audio(); }
+ reattach => { Editor.reattach-audio(); }
add-track => { Editor.add-track(); }
zoom-to-fit(width) => { Editor.zoom-to-fit(width); }
zoom(factor, anchor) => { Editor.zoom(factor, anchor); }
diff --git a/engine/crates/concat/ui/workspace/timeline-pane.slint b/engine/crates/concat/ui/workspace/timeline-pane.slint
index 00984c17..6c3fc184 100644
--- a/engine/crates/concat/ui/workspace/timeline-pane.slint
+++ b/engine/crates/concat/ui/workspace/timeline-pane.slint
@@ -5,7 +5,7 @@ import { Theme } from "../theme/theme.slint";
import { Fmt } from "../util.slint";
import { Pane } from "pane.slint";
import { PaneKind, PaneSwitcher } from "pane-switcher.slint";
-import { ContextMenu, MenuItemData } from "../primitives/context-menu.slint";
+import { MenuItemData } from "../primitives/context-menu.slint";
import { HairlineSplitter } from "splitter.slint";
import { ThinScrollbar } from "../primitives/scrollbar.slint";
import {
@@ -38,31 +38,20 @@ export component TimelinePane inherits Rectangle {
in property <bool> snap: true;
in property <int> selected-count;
in property <string> merge-blocked-because;
- in property <bool> has-av-tools;
+ in property <bool> can-caption;
+ in property <bool> can-speak;
+ in property <bool> can-detach;
+ in property <bool> can-reattach;
callback tool-changed(tool: TimelineTool);
callback snap-changed(snap: bool);
callback split();
callback merge();
callback delete-selected();
- callback av-tools();
-
- in property <[MenuItemData]> av-items;
- in property <length> av-height;
- in property <int> av-token;
-
- /// The token, but only for the pane that asked — see the same pair in
- /// lanes.slint. Two timeline seats share one token, and a bump on it
- /// would open a menu in both.
- property <bool> asked-av;
- property <int> own-av-token;
- changed av-token => {
- if (root.asked-av) {
- root.asked-av = false;
- root.own-av-token = root.av-token;
- }
- }
- callback av-selected(id: string);
+ callback captions();
+ callback speak();
+ callback detach();
+ callback reattach();
callback add-track();
callback zoom-to-fit(width: length);
callback zoom(factor: float, anchor-seconds: float);
@@ -191,7 +180,10 @@ export component TimelinePane inherits Rectangle {
snap: root.snap;
selected-count: root.selected-count;
merge-blocked-because: root.merge-blocked-because;
- has-av-tools: root.has-av-tools;
+ can-caption: root.can-caption;
+ can-speak: root.can-speak;
+ can-detach: root.can-detach;
+ can-reattach: root.can-reattach;
readout: Fmt.frames-timecode(root.playhead, root.frame-rate);
tool-changed(tool) => { root.tool-changed(tool); }
@@ -199,15 +191,10 @@ export component TimelinePane inherits Rectangle {
split => { root.split(); }
merge => { root.merge(); }
delete-selected => { root.delete-selected(); }
- av-tools(at-x) => {
- root.asked-av = true;
- av.request-x = at-x;
- // Just under the tray: the menu's own origin is the top of
- // the lane grid, so a couple of pixels is all the air it
- // needs to clear the button it hangs from.
- av.request-y = 2px;
- root.av-tools();
- }
+ captions => { root.captions(); }
+ speak => { root.speak(); }
+ detach => { root.detach(); }
+ reattach => { root.reattach(); }
add-track => { root.add-track(); }
fit => { root.zoom-to-fit(lanes.width); }
// No anchor from a button: a wheel zooms about the pointer and a
@@ -224,22 +211,6 @@ export component TimelinePane inherits Rectangle {
vertical-stretch: 1;
clip: true;
- // Inside the grid rather than beside it: a Pane lays its children
- // out and a layout owns their y, so a menu placed as a sibling of
- // the tabs and the tray cannot position itself. Here the origin is
- // the top of the lanes, which is where the tray's button points
- // anyway. The popup escapes this element's clip on its own.
- av := ContextMenu {
- x: 0;
- y: 0;
- width: parent.width;
- height: parent.height;
- items: root.av-items;
- menu-height: root.av-height;
- token: root.own-av-token;
- selected(id) => { root.av-selected(id); }
- }
-
TrackHeaders {
x: 0;
y: 0;