Skip to content

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

feat(audio): adjust volume for selected sound clips together

chiarorosa8f2e292470ba
diff --git a/src/crates/concat/src/batch_volume.rs b/src/crates/concat/src/batch_volume.rs
new file mode 100644
index 00000000..225a29b1
--- /dev/null
+++ b/src/crates/concat/src/batch_volume.rs
@@ -0,0 +1,113 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+// SPDX-FileCopyrightText: 2026 Jareer and Concat contributors
+
+//! The audio-only batch exposed by the inspector, separate from title styling.
+use concat_project::model::{ClipKind, Project};
+
+/// A batch must consist entirely of sound sources. Mixed selections are not
+/// silently reduced to a subset; locked lanes are left untouched.
+pub fn targets(
+ project: &Project,
+ selection: &[String],
+ locked: impl Fn(&str) -> bool,
+) -> Vec<String> {
+ if selection.len() < 2 {
+ return Vec::new();
+ }
+ let all_sound = selection.iter().all(|id| {
+ project
+ .active()
+ .clip(id)
+ .is_some_and(|clip| match clip.kind {
+ ClipKind::Audio => true,
+ ClipKind::Video => project
+ .media_by_id(&clip.media_id)
+ .is_some_and(|m| m.has_audio),
+ _ => false,
+ })
+ });
+ if all_sound {
+ selection
+ .iter()
+ .filter(|id| {
+ project
+ .active()
+ .clip(id)
+ .is_some_and(|clip| !locked(&clip.track_id))
+ })
+ .cloned()
+ .collect()
+ } else {
+ Vec::new()
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use concat_project::model::Clip;
+
+ fn project(kinds: &[ClipKind]) -> (Project, Vec<String>) {
+ let mut project = Project::new();
+ let mut selection = Vec::new();
+ for (i, kind) in kinds.iter().enumerate() {
+ let id = format!("c{i}");
+ project
+ .active_mut()
+ .clips
+ .push(Clip::blank(&id, "T1", *kind, "clip", 0.0, 10.0).into());
+ selection.push(id);
+ }
+ (project, selection)
+ }
+
+ #[test]
+ fn audio_clips_keep_selection_order() {
+ let (project, mut ids) = project(&[ClipKind::Audio, ClipKind::Audio]);
+ ids.reverse();
+ assert_eq!(targets(&project, &ids, |_| false), ids);
+ }
+
+ #[test]
+ fn mixed_or_missing_clips_do_not_enable_batch_volume() {
+ for kind in [ClipKind::Text, ClipKind::Image, ClipKind::Video] {
+ let (project, ids) = project(&[ClipKind::Audio, kind]);
+ assert!(targets(&project, &ids, |_| false).is_empty());
+ }
+ let (project, mut ids) = project(&[ClipKind::Audio, ClipKind::Audio]);
+ ids.push("missing".into());
+ assert!(targets(&project, &ids, |_| false).is_empty());
+ }
+
+ #[test]
+ fn video_requires_an_audio_stream_and_can_mix_with_audio_clips() {
+ let (mut project, ids) = project(&[ClipKind::Audio, ClipKind::Video]);
+ std::sync::Arc::make_mut(&mut project.active_mut().clips[1]).media_id = "m1".into();
+ project.media.push(concat_project::model::MediaItem {
+ id: "m1".into(),
+ has_audio: true,
+ ..Default::default()
+ });
+ assert_eq!(targets(&project, &ids, |_| false), ids);
+ project.media[0].has_audio = false;
+ assert!(targets(&project, &ids, |_| false).is_empty());
+ }
+
+ #[test]
+ fn locked_lanes_are_not_targets_even_when_only_one_unlocked_clip_remains() {
+ let (mut project, ids) = project(&[ClipKind::Audio, ClipKind::Audio]);
+ std::sync::Arc::make_mut(&mut project.active_mut().clips[1]).track_id = "T2".into();
+ assert_eq!(
+ targets(&project, &ids, |track| track == "T1"),
+ vec![ids[1].clone()]
+ );
+ assert!(targets(&project, &ids, |_| true).is_empty());
+ }
+
+ #[test]
+ fn single_selection_stays_with_the_existing_inspector() {
+ let (project, ids) = project(&[ClipKind::Audio]);
+ assert!(targets(&project, &ids, |_| false).is_empty());
+ assert!(targets(&project, &[], |_| false).is_empty());
+ }
+}
diff --git a/src/crates/concat/src/lib.rs b/src/crates/concat/src/lib.rs
index dbf21d55..540efdf1 100644
--- a/src/crates/concat/src/lib.rs
+++ b/src/crates/concat/src/lib.rs
@@ -31,6 +31,7 @@ mod ui {
slint::include_modules!();
}
+mod batch_volume;
mod chips;
mod dock;
mod fonts;
diff --git a/src/crates/concat/src/studio.rs b/src/crates/concat/src/studio.rs
index 20006854..087cb06f 100644
--- a/src/crates/concat/src/studio.rs
+++ b/src/crates/concat/src/studio.rs
@@ -3603,6 +3603,10 @@ impl Studio {
}
}
+ fn volume_targets(&self) -> Vec<String> {
+ crate::batch_volume::targets(self.project(), &self.selection, |track| self.locked(track))
+ }
+
pub fn sole_selection(&self) -> Option<String> {
(self.selection.len() == 1).then(|| self.selection[0].clone())
}
@@ -4565,7 +4569,10 @@ impl Studio {
/// One field of the selected clip, on the echo. `clip_commit` turns the
/// accumulated edits into commands.
pub fn clip_set(&mut self, field: ClipField, value: f32) {
- let ids = self.edit_targets();
+ let mut ids = self.edit_targets();
+ if ids.is_empty() && field == ClipField::Volume {
+ ids = self.volume_targets();
+ }
if ids.is_empty() {
return;
}
@@ -8954,9 +8961,13 @@ impl Studio {
}
fn selected(&self) -> SelectedClipData {
- // The one clip, or the first of a batch of titles: the panel shows
- // its values and writes to all of them; see `edit_targets`.
- let targets = self.edit_targets();
+ // Titles share their styling controls; a sound batch exposes volume
+ // alone, using the first unlocked clip as the displayed reference.
+ let mut targets = self.edit_targets();
+ let batch_volume = targets.is_empty();
+ if batch_volume {
+ targets = self.volume_targets();
+ }
let Some(clip) = targets.first().and_then(|id| self.clip(id)) else {
return SelectedClipData::default();
};
@@ -8981,6 +8992,7 @@ impl Studio {
SelectedClipData {
present: true,
batch: targets.len() as i32,
+ batch_volume,
frame_width: self.output_size().0 as i32,
frame_height: self.output_size().1 as i32,
id: clip.id.as_str().into(),
@@ -10917,6 +10929,11 @@ mod tests {
// A size is a size for every title in the batch.
assert_eq!(batch_value(ClipField::FontSize, 0.08, 0.05, 0.02), 0.08);
assert_eq!(relative_property(ClipField::FontSize), None);
+ // Volume is absolute: different starting gains land on the same level.
+ assert_eq!(relative_property(ClipField::Volume), None);
+ for current in [0.0, 0.25, 1.0, 2.0] {
+ assert_eq!(batch_value(ClipField::Volume, 0.5, 1.0, current), 0.5);
+ }
}
#[test]
diff --git a/src/crates/concat/ui/inspector/clip-inspector.slint b/src/crates/concat/ui/inspector/clip-inspector.slint
index c8320129..51a72f95 100644
--- a/src/crates/concat/ui/inspector/clip-inspector.slint
+++ b/src/crates/concat/ui/inspector/clip-inspector.slint
@@ -1592,7 +1592,7 @@ export component AudioPanel inherits VerticalLayout {
/// The Source section has something to offer: a choice of audio track.
/// A file's colour range used to sit here too and is the media's now,
/// in the bin card's menu: it is a fact about the file, not the cut.
- property <bool> choosing: root.audio-tracks.length > 1;
+ property <bool> choosing: !root.selected.batch-volume && root.audio-tracks.length > 1;
callback set(field: ClipField, value: float);
callback commit();
@@ -1657,7 +1657,7 @@ export component AudioPanel inherits VerticalLayout {
if volume.open: SectionBody {
Param {
label: I18n.t("common.level");
- keyable: true;
+ keyable: !root.selected.batch-volume;
field: ClipField.volume;
rail: true;
value <=> root.level;
@@ -1678,7 +1678,7 @@ export component AudioPanel inherits VerticalLayout {
}
}
- Section {
+ if !root.selected.batch-volume: Section {
fades := SectionHeader {
title: I18n.t("clipInspector.fades");
collapsible: true;
@@ -1726,7 +1726,7 @@ export component AudioPanel inherits VerticalLayout {
// Whether the voice keeps its pitch when the rate is not 1. Here and
// not on the Speed tab: the rate is the clip's, but what it does to the
// sound is the sound's business, beside the level it is mixed at.
- Section {
+ if !root.selected.batch-volume: Section {
SectionHeader {
title: I18n.t("clipInspector.pitch");
}
diff --git a/src/crates/concat/ui/phone/editor.slint b/src/crates/concat/ui/phone/editor.slint
index 1a8d69ea..a8df31d7 100644
--- a/src/crates/concat/ui/phone/editor.slint
+++ b/src/crates/concat/ui/phone/editor.slint
@@ -212,8 +212,8 @@ export component PhoneEditor inherits Rectangle {
property <bool> has-clip: Editor.selected-clip.present;
property <ClipKind> kind: Editor.selected-clip.kind;
- property <bool> is-video: root.kind == ClipKind.video;
- property <bool> is-audio: root.kind == ClipKind.audio;
+ property <bool> is-video: !Editor.selected-clip.batch-volume && root.kind == ClipKind.video;
+ property <bool> is-audio: Editor.selected-clip.batch-volume || root.kind == ClipKind.audio;
property <bool> is-image: root.kind == ClipKind.image;
property <bool> is-text: root.kind == ClipKind.text;
property <bool> is-layer: root.kind == ClipKind.filter;
@@ -743,7 +743,7 @@ export component PhoneEditor inherits Rectangle {
current: root.sheet == "clip-layer";
clicked => { root.show("clip-layer", true); }
}
- if root.is-video || root.is-audio: ToolItem {
+ if (root.is-video || root.is-audio) && !Editor.selected-clip.batch-volume: ToolItem {
glyph: Glyph.clock;
label: I18n.t("common.speed");
current: root.sheet == "clip-speed";
@@ -1052,7 +1052,7 @@ export component PhoneEditor inherits Rectangle {
set(field, value) => { Editor.clip-set(field, value); }
commit => { Editor.clip-commit(); }
}
- ProcessorRows {
+ if !Editor.selected-clip.batch-volume: ProcessorRows {
applied: Editor.applied-audio;
params: Editor.audio-params;
add(id) => { Editor.chain-add(true, id); }
@@ -1062,7 +1062,7 @@ export component PhoneEditor inherits Rectangle {
}
commit => { Editor.clip-commit(); }
}
- PresetStack {
+ if !Editor.selected-clip.batch-volume: PresetStack {
noun: I18n.t("common.audioEffect");
library-title: I18n.t("configPane.audioEffects");
shelf: 2;
diff --git a/src/crates/concat/ui/timeline/model.slint b/src/crates/concat/ui/timeline/model.slint
index f7f95c02..6951de8c 100644
--- a/src/crates/concat/ui/timeline/model.slint
+++ b/src/crates/concat/ui/timeline/model.slint
@@ -279,6 +279,8 @@ export struct SelectedClipData {
/// how many clips the panel writes to: one, or every selected title
/// when several are selected together, shown by the first's values
batch: int,
+ /// Only the volume control is available for this selection.
+ batch-volume: bool,
id: string,
/// the output frame's size, so a fraction can be shown in pixels
frame-width: int,
diff --git a/src/crates/concat/ui/workspace/config-pane.slint b/src/crates/concat/ui/workspace/config-pane.slint
index 68123885..085014b6 100644
--- a/src/crates/concat/ui/workspace/config-pane.slint
+++ b/src/crates/concat/ui/workspace/config-pane.slint
@@ -229,7 +229,7 @@ export component ConfigPane inherits Rectangle {
/// it has no transform, no gain and no rate, and every other tab could
/// only say "nothing here".
property <bool> is-layer: root.selected.kind == ClipKind.filter;
- property <[string]> tabs: root.is-text ? ["Text"]
+ property <[string]> tabs: root.selected.batch-volume ? ["Audio"] : root.is-text ? ["Text"]
: root.is-layer ? ["Filter"]
: root.is-shape ? ["Video"]
: root.is-image ? ["Video", "Effects"]
@@ -237,7 +237,7 @@ export component ConfigPane inherits Rectangle {
: ["Video", "Audio", "Effects"];
/// The same tabs in the interface's language. `tabs` stays English,
/// because the panels are picked by comparing against it.
- property <[string]> tabs-shown: root.is-text ? [I18n.t("common.text")]
+ property <[string]> tabs-shown: root.selected.batch-volume ? [I18n.t("common.audio")] : root.is-text ? [I18n.t("common.text")]
: root.is-layer ? [I18n.t("configPane.filter")]
: root.is-shape ? [I18n.t("configPane.vectorImage")]
: root.is-image ? [I18n.t("common.video"), I18n.t("common.effects")]
@@ -688,7 +688,7 @@ export component ConfigPane inherits Rectangle {
// A sound clip's speed, under its level and fades: one
// knob is not a page of its own. A picture's sound
// rides the picture's, set under Video › Basic.
- if root.is-audio: SpeedPanel {
+ if root.is-audio && !root.selected.batch-volume: SpeedPanel {
first: false;
selected: root.selected;
set(field, value) => { root.clip-set(field, value); }
@@ -698,7 +698,7 @@ export component ConfigPane inherits Rectangle {
// they are chain links like any other, but they are the
// ones a sound clip usually needs, so they get a switch
// rather than a search.
- ProcessorRows {
+ if !root.selected.batch-volume: ProcessorRows {
applied: root.applied-audio;
params: root.audio-params;
add(id) => { root.chain-add(true, id); }
@@ -708,7 +708,7 @@ export component ConfigPane inherits Rectangle {
}
commit => { root.clip-commit(); }
}
- PresetStack {
+ if !root.selected.batch-volume: PresetStack {
noun: I18n.t("common.audioEffect");
library-title: I18n.t("configPane.audioEffects");
shelf: 2;