Skip to content

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

feat(audio): a sound effect dragged onto the timeline is a sound layer over everything heard under it

Jareer2606aff12f95
diff --git a/src/crates/concat-export/src/flatten.rs b/src/crates/concat-export/src/flatten.rs
index 826cc32c..4305007d 100644
--- a/src/crates/concat-export/src/flatten.rs
+++ b/src/crates/concat-export/src/flatten.rs
@@ -76,6 +76,23 @@ pub fn flatten_timeline_in(
});
}
+ // A sound layer: no file and no picture, a chain over the mix
+ // for its span, its opacity the strength and its fades the
+ // ramps, silent with its lane.
+ if clip.kind == ModelClipKind::SoundLayer {
+ return Some(ExportClip {
+ hidden: true,
+ muted: track.muted || clip.muted == Some(true),
+ volume: 0.0,
+ fade_in: clip.fade_in,
+ fade_out: clip.fade_out,
+ filter_chain: audio_filter_chain(&clip.filters),
+ opacity: clip.opacity,
+ has_audio: Some(false),
+ ..ExportClip::blank(ClipKind::SoundLayer, clip.start, clip.duration, index)
+ });
+ }
+
let media = project.media.iter().find(|item| item.id == clip.media_id)?;
let kind = match clip.kind {
@@ -84,7 +101,10 @@ pub fn flatten_timeline_in(
ModelClipKind::Image => ClipKind::Image,
// Handled above; unreachable spelled as a skip so a new
// kind fails soft.
- ModelClipKind::Text | ModelClipKind::Layer | ModelClipKind::Shape => return None,
+ ModelClipKind::Text
+ | ModelClipKind::Layer
+ | ModelClipKind::SoundLayer
+ | ModelClipKind::Shape => return None,
};
Some(ExportClip {
path: media.path.clone(),
diff --git a/src/crates/concat-export/src/lib.rs b/src/crates/concat-export/src/lib.rs
index 1b2af9ee..18be3a86 100644
--- a/src/crates/concat-export/src/lib.rs
+++ b/src/crates/concat-export/src/lib.rs
@@ -66,6 +66,12 @@ pub enum ClipKind {
/// composited beneath its track for its span, blended back by its
/// opacity, ramped by its fades. See `composite_treated`.
Layer,
+ /// A treatment of the sound: its `filter_chain` runs over the mix of
+ /// every audible clip for its span, its opacity how much of the treated
+ /// sound replaces the untreated, ramped by its fades. No picture, and
+ /// no sound of its own; see [`audio_buses`].
+ #[serde(rename = "soundLayer")]
+ SoundLayer,
}
impl ClipKind {
@@ -1243,7 +1249,8 @@ pub fn render_on(
reporter.cancelled()?;
reporter.emit(0, total_frames, "mixing audio");
let mix: Vec<AudioClip> = sound.iter().flat_map(|clip| audio_pieces(clip)).collect();
- audio::mix_to_file(&mix, timeline_end.as_f64(), &mixed)
+ let buses = audio_buses(&resolved);
+ audio::mix_to_file_with(&mix, &buses, timeline_end.as_f64(), &mixed)
.map_err(|error| error.to_string())?;
reporter.cancelled()?;
@@ -1338,6 +1345,31 @@ fn track_slice(track: &AnimTrack, x0: f64, x1: f64) -> AnimTrack {
AnimTrack::new(keys)
}
+/// The sound layers among `clips`, as the mixer runs them over the sum:
+/// those on a lane that is not muted with a chain that does something, in
+/// the order of their lanes from the bottom up and then of their starts,
+/// so two that overlap are heard as the lanes stack them. Playback and
+/// the export both read them from here.
+pub fn audio_buses(clips: &[ExportClip]) -> Vec<audio::AudioBus> {
+ let mut layers: Vec<&ExportClip> = clips
+ .iter()
+ .filter(|clip| clip.kind == ClipKind::SoundLayer && !clip.muted)
+ .collect();
+ layers.sort_by(|a, b| a.track.cmp(&b.track).then(a.start.total_cmp(&b.start)));
+ layers
+ .into_iter()
+ .map(|clip| audio::AudioBus {
+ start: clip.start,
+ duration: clip.duration,
+ filter_chain: clip.filter_chain.clone(),
+ strength: clip.opacity.clamp(0.0, 1.0),
+ fade_in: clip.fade_in,
+ fade_out: clip.fade_out,
+ })
+ .filter(audio::AudioBus::audible)
+ .collect()
+}
+
/// The engine's view of one audible clip - or several, when its speed
/// changes over it. Sound can only change tempo in steps, so a curve is cut
/// into pieces of constant rate, each at the mean of its stretch of the
@@ -3317,6 +3349,7 @@ mod tests {
duration: Some(2.0),
effect_id: "concat.adjust".into(),
name: "Adjustment".into(),
+ sound: false,
})
.expect("adds the layer")
.created_id
diff --git a/src/crates/concat-host/src/playback.rs b/src/crates/concat-host/src/playback.rs
index 4ca7e33d..d54f8113 100644
--- a/src/crates/concat-host/src/playback.rs
+++ b/src/crates/concat-host/src/playback.rs
@@ -15,6 +15,12 @@
//! memory stays bounded however long the material is, and a reopened
//! project pays nothing.
//!
+//! - Where a sound layer runs, the clips cannot each carry it: its chain is
+//! over their sum. The stretch is mixed once instead, through the
+//! exporter's own mix with the layer over it, and plays as one span in
+//! their place - see [`with_sound_layers`]. Until it lands the clips
+//! under it play as they are, so an edit there is never silence.
+//!
//! - One cpal output stream mixes the mapped clips sample by sample, with
//! volume and fades applied at mix time. Gain-only edits therefore never
//! re-decode, and what a fade sounds like has exactly one definition: this
@@ -122,6 +128,196 @@ pub struct ClipSpec {
/// FFmpeg audio filter chain, or empty.
#[serde(default)]
pub chain: String,
+ /// When set, this span is not a file but the mix of these clips under
+ /// sound layers, over `start` to `start + duration` of the timeline,
+ /// and it plays in their place there; see [`with_sound_layers`]. The
+ /// fields above that describe a file are then unused.
+ #[serde(default)]
+ pub bus: Option<BusMix>,
+}
+
+/// The clips a stretch under sound layers mixes, and the layers.
+#[derive(Clone, Debug, Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct BusMix {
+ /// Every audible clip with something inside the stretch, whole: the
+ /// mix cuts each at the stretch's edges on its own clock.
+ pub clips: Vec<ClipSpec>,
+ /// The sound layers over the stretch, in the order they are heard.
+ pub layers: Vec<BusSpec>,
+}
+
+/// One sound layer, as a spec carries it; see `concat_media::audio::AudioBus`.
+#[derive(Clone, Debug, Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct BusSpec {
+ /// Timeline seconds.
+ pub start: f64,
+ /// Timeline seconds it runs.
+ pub duration: f64,
+ /// The FFmpeg audio filters it runs over the mix.
+ pub chain: String,
+ /// How much of the treated sound replaces the untreated, `0..=1`.
+ pub strength: f64,
+ /// Ramp in, seconds.
+ pub fade_in: f64,
+ /// Ramp out, seconds.
+ pub fade_out: f64,
+}
+
+impl BusSpec {
+ fn engine(&self) -> concat_media::audio::AudioBus {
+ concat_media::audio::AudioBus {
+ start: self.start,
+ duration: self.duration,
+ filter_chain: self.chain.clone(),
+ strength: self.strength,
+ fade_in: self.fade_in,
+ fade_out: self.fade_out,
+ }
+ }
+}
+
+impl ClipSpec {
+ /// The engine's view of this clip, for a mix.
+ fn engine(&self) -> concat_media::audio::AudioClip {
+ concat_media::audio::AudioClip {
+ path: PathBuf::from(&self.path),
+ stream: self.audio_stream.map(|index| index as usize),
+ start: self.start,
+ duration: self.duration,
+ source_start: self.source_start,
+ speed: self.speed,
+ preserve_pitch: self.preserve_pitch,
+ volume: f64::from(self.volume),
+ volume_curve: track_of(&self.volume_curve),
+ fade_in: self.fade_in,
+ fade_out: self.fade_out,
+ filter_chain: self.chain.clone(),
+ }
+ }
+}
+
+/// What a flattened edit makes audible, as playback takes it: every clip
+/// with sound through the exporter's own cut into pieces, so a curve or a
+/// reverse sounds in the window as it will in the file, and the stretches
+/// under sound layers mixed as the file mixes them. One definition for
+/// every shell - the desktop window and the phone's alike.
+pub fn audible(clips: &[concat_export::ExportClip]) -> Vec<ClipSpec> {
+ let specs = clips
+ .iter()
+ .filter(|clip| {
+ !clip.muted
+ && (clip.kind == concat_export::ClipKind::Audio
+ || (clip.kind == concat_export::ClipKind::Video
+ && clip.has_audio.unwrap_or(true)))
+ })
+ .flat_map(concat_export::audio_pieces)
+ .map(|piece| ClipSpec {
+ path: piece.path.to_string_lossy().into_owned(),
+ audio_stream: piece.stream.map(|index| index as u32),
+ start: piece.start,
+ duration: piece.duration,
+ source_start: piece.source_start,
+ volume: piece.volume as f32,
+ volume_curve: piece
+ .volume_curve
+ .keys()
+ .iter()
+ .map(|key| GainKey {
+ at: key.at,
+ gain: key.value,
+ ease: [key.ease.x1, key.ease.y1, key.ease.x2, key.ease.y2],
+ })
+ .collect(),
+ fade_in: piece.fade_in,
+ fade_out: piece.fade_out,
+ speed: piece.speed,
+ preserve_pitch: piece.preserve_pitch,
+ chain: piece.filter_chain,
+ bus: None,
+ })
+ .collect();
+ with_sound_layers(specs, &concat_export::audio_buses(clips))
+}
+
+/// `specs` with the stretches under sound layers mixed apart: one span per
+/// run of layers that touch or overlap, carrying every clip with something
+/// inside it and the layers over it. The clips themselves stay in the set,
+/// whole - the player silences them under a span once that span is
+/// decoded, and until then they are what is heard.
+///
+/// Layers are grouped so a span is the whole of what they cover together:
+/// two that overlap are one sum treated twice, not two sums.
+pub fn with_sound_layers(
+ mut specs: Vec<ClipSpec>,
+ layers: &[concat_media::audio::AudioBus],
+) -> Vec<ClipSpec> {
+ let layers: Vec<&concat_media::audio::AudioBus> =
+ layers.iter().filter(|layer| layer.audible()).collect();
+ if layers.is_empty() {
+ return specs;
+ }
+ // In the order given, which is the order they are heard; grouped by
+ // where they reach.
+ let mut order: Vec<usize> = (0..layers.len()).collect();
+ order.sort_by(|&a, &b| layers[a].start.total_cmp(&layers[b].start));
+ let mut groups: Vec<(f64, f64, Vec<usize>)> = Vec::new();
+ for index in order {
+ let layer = layers[index];
+ match groups.last_mut() {
+ Some((_, end, members)) if layer.start <= *end => {
+ *end = end.max(layer.end());
+ members.push(index);
+ }
+ _ => groups.push((layer.start, layer.end(), vec![index])),
+ }
+ }
+ let spans: Vec<ClipSpec> = groups
+ .into_iter()
+ .map(|(start, end, mut members)| {
+ members.sort_unstable();
+ let clips = specs
+ .iter()
+ .filter(|spec| spec.start < end && spec.start + spec.duration > start)
+ .cloned()
+ .collect();
+ let over = members
+ .into_iter()
+ .map(|index| {
+ let layer = layers[index];
+ BusSpec {
+ start: layer.start,
+ duration: layer.duration,
+ chain: layer.filter_chain.clone(),
+ strength: layer.strength,
+ fade_in: layer.fade_in,
+ fade_out: layer.fade_out,
+ }
+ })
+ .collect();
+ ClipSpec {
+ path: String::new(),
+ audio_stream: None,
+ start,
+ duration: end - start,
+ source_start: 0.0,
+ volume: 1.0,
+ volume_curve: Vec::new(),
+ fade_in: 0.0,
+ fade_out: 0.0,
+ speed: 1.0,
+ preserve_pitch: true,
+ chain: String::new(),
+ bus: Some(BusMix {
+ clips,
+ layers: over,
+ }),
+ }
+ })
+ .collect();
+ specs.extend(spans);
+ specs
}
/// Where playback tells the window what it cannot ask: the clock, and the
@@ -227,6 +423,10 @@ struct ActiveClip {
fade_in: f64,
fade_out: f64,
pcm: Arc<Pcm>,
+ /// Timeline stretches where a mixed span under sound layers plays in
+ /// this clip's place, so it is silent there; empty for that span
+ /// itself and wherever no layer is.
+ covered: Arc<[(f64, f64)]>,
}
/// A spec's gain keys as the engine's track.
@@ -250,6 +450,10 @@ fn gain_at(clip: &ActiveClip, local: f64) -> f32 {
if local < 0.0 || local > clip.duration {
return 0.0;
}
+ let at = clip.start + local;
+ if clip.covered.iter().any(|&(from, to)| at >= from && at < to) {
+ return 0.0;
+ }
// The ride, where there is one, replaces the constant - the same
// precedence the mixer's filtergraph gives it, so the window and the
// file agree about how loud the clip is at every instant.
@@ -598,6 +802,14 @@ impl Playback {
let specs = locked(&self.specs);
let now = self.tick.fetch_add(1, Ordering::Relaxed) + 1;
let mut cache = locked(&self.cache);
+ // The stretches a mixed span under sound layers already covers:
+ // the clips there fall silent only once it is ready to take over.
+ let covered: Arc<[(f64, f64)]> = specs
+ .iter()
+ .filter(|spec| spec.bus.is_some() && cache.contains_key(&decode_key(spec)))
+ .map(|spec| (spec.start, spec.start + spec.duration))
+ .collect();
+ let none: Arc<[(f64, f64)]> = Arc::from(Vec::new());
let active: Vec<ActiveClip> = specs
.iter()
.filter_map(|spec| {
@@ -611,6 +823,11 @@ impl Playback {
fade_in: spec.fade_in,
fade_out: spec.fade_out,
pcm: Arc::clone(&entry.pcm),
+ covered: if spec.bus.is_some() {
+ Arc::clone(&none)
+ } else {
+ Arc::clone(&covered)
+ },
})
})
.collect();
@@ -790,6 +1007,43 @@ fn decode_key(spec: &ClipSpec) -> String {
hash = hash.wrapping_mul(0x0000_0100_0000_01b3);
}
};
+ // A mixed span is everything its mix is made of, gain and fades
+ // included: they are baked into it, where a clip's are applied live.
+ if let Some(bus) = &spec.bus {
+ eat(b"bus");
+ eat(&spec.start.to_bits().to_le_bytes());
+ eat(&spec.duration.to_bits().to_le_bytes());
+ for clip in &bus.clips {
+ eat(decode_key(clip).as_bytes());
+ for number in [
+ clip.start,
+ clip.fade_in,
+ clip.fade_out,
+ f64::from(clip.volume),
+ ] {
+ eat(&number.to_bits().to_le_bytes());
+ }
+ for key in &clip.volume_curve {
+ for number in [key.at, key.gain].iter().chain(key.ease.iter()) {
+ eat(&number.to_bits().to_le_bytes());
+ }
+ }
+ }
+ for layer in &bus.layers {
+ eat(b"layer");
+ for number in [
+ layer.start,
+ layer.duration,
+ layer.strength,
+ layer.fade_in,
+ layer.fade_out,
+ ] {
+ eat(&number.to_bits().to_le_bytes());
+ }
+ eat(layer.chain.as_bytes());
+ }
+ return format!("{hash:016x}");
+ }
eat(spec.path.as_bytes());
eat(&spec.source_start.to_bits().to_le_bytes());
eat(&spec.duration.to_bits().to_le_bytes());
@@ -828,6 +1082,10 @@ fn decode(spec: &ClipSpec, project: &Path, key: &str) -> Result<Pcm, String> {
std::fs::create_dir_all(&directory)
.map_err(|error| format!("could not create {}: {error}", directory.display()))?;
+ if let Some(bus) = &spec.bus {
+ return mix_span(spec, bus, &directory, key, &destination);
+ }
+
// Speed first, then the clip's own filters - the same order the export
// graph applies, because these are one definition, not two. The engine
// owns what speed *means*; this function only decodes.
@@ -878,6 +1136,55 @@ fn decode(spec: &ClipSpec, project: &Path, key: &str) -> Result<Pcm, String> {
Pcm::open(&destination)
}
+/// Mixes a stretch under sound layers to the cache and maps it: the
+/// exporter's own mix of the clips with the layers over the sum, so what
+/// plays here is what the file will hold.
+fn mix_span(
+ spec: &ClipSpec,
+ bus: &BusMix,
+ directory: &Path,
+ key: &str,
+ destination: &Path,
+) -> Result<Pcm, String> {
+ let clips: Vec<concat_media::audio::AudioClip> =
+ bus.clips.iter().map(ClipSpec::engine).collect();
+ let layers: Vec<concat_media::audio::AudioBus> =
+ bus.layers.iter().map(BusSpec::engine).collect();
+ let temporary = directory.join(format!("{key}.wav.decoding"));
+ let result = (|| -> Result<(), String> {
+ let mut file = std::io::BufWriter::new(
+ std::fs::File::create(&temporary)
+ .map_err(|error| format!("could not create {}: {error}", temporary.display()))?,
+ );
+ let mut writer = WavWriter::start(&mut file)?;
+ let mut failed: Option<String> = None;
+ concat_media::audio::mix_pcm(
+ &clips,
+ &layers,
+ spec.start,
+ spec.start + spec.duration,
+ |bytes| {
+ if let Err(error) = writer.write(&mut file, bytes) {
+ failed = Some(error);
+ }
+ Ok(())
+ },
+ )
+ .map_err(|error| error.to_string())?;
+ if let Some(error) = failed {
+ return Err(error);
+ }
+ writer.finish(&mut file)
+ })();
+ if let Err(error) = result {
+ let _ = std::fs::remove_file(&temporary);
+ return Err(error);
+ }
+ std::fs::rename(&temporary, destination)
+ .map_err(|error| format!("could not commit {}: {error}", destination.display()))?;
+ Pcm::open(destination)
+}
+
/// Writes the RIFF/WAVE framing around 16-bit stereo samples at
/// [`PCM_RATE`]: a header with placeholder sizes first, patched once the
/// sample count is known.
@@ -1267,6 +1574,131 @@ mod tests {
bytes
}
+ fn layer(start: f64, duration: f64) -> concat_media::audio::AudioBus {
+ concat_media::audio::AudioBus {
+ start,
+ duration,
+ filter_chain: "lowpass=f=60,lowpass=f=60".to_owned(),
+ strength: 1.0,
+ fade_in: 0.0,
+ fade_out: 0.0,
+ }
+ }
+
+ fn tone_spec(path: &std::path::Path, start: f64, duration: f64) -> super::ClipSpec {
+ super::ClipSpec {
+ path: path.to_string_lossy().into_owned(),
+ audio_stream: None,
+ start,
+ duration,
+ source_start: 0.0,
+ volume: 1.0,
+ volume_curve: Vec::new(),
+ fade_in: 0.0,
+ fade_out: 0.0,
+ speed: 1.0,
+ preserve_pitch: true,
+ chain: String::new(),
+ bus: None,
+ }
+ }
+
+ /// Layers that touch or overlap are mixed as one stretch, apart from
+ /// one further on; each stretch takes the clips with something inside
+ /// it, and the clips stay in the set.
+ #[test]
+ fn sound_layers_are_mixed_in_stretches_of_the_clips_beneath_them() {
+ let path = std::path::Path::new("a.wav");
+ let specs = vec![tone_spec(path, 0.0, 2.0), tone_spec(path, 5.0, 3.0)];
+ let mixed =
+ super::with_sound_layers(specs, &[layer(1.0, 1.0), layer(6.0, 1.0), layer(1.5, 1.0)]);
+ assert_eq!(mixed.len(), 4, "two clips and two stretches");
+ let stretches: Vec<&super::ClipSpec> =
+ mixed.iter().filter(|spec| spec.bus.is_some()).collect();
+ assert_eq!(
+ (stretches[0].start, stretches[0].duration),
+ (1.0, 1.5),
+ "the first two layers are one stretch"
+ );
+ let first = stretches[0].bus.as_ref().expect("a mix");
+ assert_eq!(first.layers.len(), 2);
+ assert_eq!(
+ first
+ .layers
+ .iter()
+ .map(|layer| layer.start)
+ .collect::<Vec<_>>(),
+ vec![1.0, 1.5],
+ "heard in the order given"
+ );
+ assert_eq!(first.clips.len(), 1, "only the clip under it");
+ assert_eq!((stretches[1].start, stretches[1].duration), (6.0, 1.0));
+ assert_eq!(
+ stretches[1].bus.as_ref().expect("a mix").clips[0].start,
+ 5.0
+ );
+ // No layer that does anything, nothing added.
+ let mut idle = layer(0.0, 1.0);
+ idle.strength = 0.0;
+ assert_eq!(
+ super::with_sound_layers(vec![tone_spec(path, 0.0, 2.0)], &[idle]).len(),
+ 1
+ );
+ }
+
+ /// A stretch under a sound layer decodes to the mix with the layer
+ /// over it - the tone taken away by the low-pass - for exactly its
+ /// length, and silences a clip under it only where it covers.
+ #[test]
+ fn a_stretch_under_a_sound_layer_decodes_to_the_treated_mix() {
+ let dir = std::env::temp_dir().join(format!("concat-stretch-{}", std::process::id()));
+ std::fs::create_dir_all(&dir).expect("a folder");
+ let rate = super::PCM_RATE;
+ let mut data = Vec::new();
+ for index in 0..rate * 3 {
+ let t = f64::from(index) / f64::from(rate);
+ let value = (0.5 * (2.0 * std::f64::consts::PI * 440.0 * t).sin() * 32767.0) as i16;
+ data.extend_from_slice(&value.to_le_bytes());
+ data.extend_from_slice(&value.to_le_bytes());
+ }
+ let source = dir.join("tone.wav");
+ {
+ let mut file = std::fs::File::create(&source).expect("creates");
+ let mut writer = super::WavWriter::start(&mut file).expect("starts");
+ writer.write(&mut file, &data).expect("writes");
+ writer.finish(&mut file).expect("finishes");
+ }
+ let specs =
+ super::with_sound_layers(vec![tone_spec(&source, 0.0, 3.0)], &[layer(1.0, 1.0)]);
+ let stretch = specs
+ .iter()
+ .find(|spec| spec.bus.is_some())
+ .expect("a stretch");
+ let key = super::decode_key(stretch);
+ let pcm = super::decode(stretch, &dir, &key).expect("mixes");
+ let peak = (rate / 10..rate * 9 / 10)
+ .map(|frame| pcm.sample(u64::from(frame), 0).abs())
+ .fold(0.0_f32, f32::max);
+ let frames = pcm.frames;
+ let _ = std::fs::remove_dir_all(&dir);
+ assert_eq!(frames, u64::from(rate), "a second, the stretch's length");
+ assert!(peak < 0.05, "the tone came through at {peak}");
+
+ let clip = super::ActiveClip {
+ start: 0.0,
+ duration: 3.0,
+ volume: 1.0,
+ volume_curve: super::Track::default(),
+ fade_in: 0.0,
+ fade_out: 0.0,
+ pcm: std::sync::Arc::new(pcm),
+ covered: std::sync::Arc::from(vec![(1.0, 2.0)]),
+ };
+ assert_eq!(super::gain_at(&clip, 0.5), 1.0);
+ assert_eq!(super::gain_at(&clip, 1.5), 0.0, "the stretch plays here");
+ assert_eq!(super::gain_at(&clip, 2.0), 1.0);
+ }
+
#[test]
fn finds_the_data_chunk_past_the_headers() {
let bytes = wav(8, &[1, 2, 3, 4, 5, 6, 7, 8]);
diff --git a/src/crates/concat-host/tests/export.rs b/src/crates/concat-host/tests/export.rs
index 92b9320d..50085936 100644
--- a/src/crates/concat-host/tests/export.rs
+++ b/src/crates/concat-host/tests/export.rs
@@ -1725,6 +1725,7 @@ fn every_edit_still_exports() {
duration: Some(3.0),
effect_id: "concat.glow".to_owned(),
name: "Glow".to_owned(),
+ sound: false,
});
let exported = studio.export("layer");
exported.expect_length(end);
@@ -2064,6 +2065,96 @@ fn an_export_decodes_on_the_hardware_when_preferred() {
}
}
+/// A sound layer over two seconds of the clock changes the export's sound
+/// there and nowhere else. Two clips sound under it, the clock and a
+/// second copy of it a lane up, so what it treats is their sum. The tone
+/// of the clock's third second, inside the layer, comes out of the
+/// low-pass changed; its first and fifth, either side, are what an export
+/// without the layer has, give or take what the encoder does near the
+/// layer's edges. Muting the layer's lane takes it off.
+#[test]
+fn a_sound_layer_treats_the_mix_for_its_span_alone() {
+ let scratch = Scratch::new("sound-layer");
+ let wav = scratch.path().join("clock.wav");
+ clock_wav(&wav, 6);
+ let mut studio = Studio::new(scratch.path(), "Sound layer", video(WIDTH, HEIGHT, 30, 1));
+ let clock = studio.import(&wav);
+ let lanes: Vec<String> = studio
+ .project()
+ .active()
+ .tracks
+ .iter()
+ .map(|track| track.id.clone())
+ .collect();
+ for lane in &lanes[..2] {
+ studio.apply(Command::AddClip {
+ media_id: clock.clone(),
+ track_id: lane.clone(),
+ start: 0.0,
+ ripple: false,
+ });
+ }
+ let plain = studio.export("no layer");
+ plain.expect_sound(6.0);
+
+ let layer = studio
+ .apply(Command::AddLayerClip {
+ track_id: None,
+ start: 2.0,
+ duration: Some(2.0),
+ effect_id: "concat.underwater".to_owned(),
+ name: "Underwater".to_owned(),
+ sound: true,
+ })
+ .expect("a layer has an id");
+ let treated = studio.export("sound layer");
+ treated.expect_length(6.0);
+ treated.expect_sound(6.0);
+
+ // How far apart two exports' sound is over `[from, to)`, as the root
+ // mean square of their difference.
+ let apart = |a: &Exported, b: &Exported, from: f64, to: f64| {
+ let (a, b) = (
+ a.audio.as_ref().expect("sound"),
+ b.audio.as_ref().expect("sound"),
+ );
+ let at = |seconds: f64| (seconds * f64::from(RATE)) as usize * 2;
+ let range = at(from)..at(to).min(a.len()).min(b.len());
+ let count = range.len().max(1) as f64;
+ let sum: f64 = range
+ .map(|index| (f64::from(a[index]) - f64::from(b[index])).powi(2))
+ .sum();
+ (sum / count).sqrt()
+ };
+ let inside = apart(&plain, &treated, 3.1, 3.9);
+ let before = apart(&plain, &treated, 1.1, 1.9);
+ let after = apart(&plain, &treated, 5.1, 5.9);
+ eprintln!("sound layer: {inside:.4} inside, {before:.4} before, {after:.4} after");
+ assert!(
+ inside > 0.1,
+ "the layer's span is {inside:.4} from the plain mix"
+ );
+ assert!(
+ before < 0.01,
+ "before the layer the mix moved by {before:.4}"
+ );
+ assert!(after < 0.01, "after the layer the mix moved by {after:.4}");
+ // The tone is still there to treat: a filter, not a mute.
+ treated.expect_tone(1.5);
+ treated.expect_tone(5.5);
+
+ // A muted lane silences the layer as it silences a clip.
+ let lane = studio.clip(&layer).track_id.clone();
+ studio.apply(Command::SetTrackFlag {
+ track_id: lane,
+ flag: TrackFlag::Muted,
+ value: true,
+ });
+ let muted = studio.export("sound layer muted");
+ let off = apart(&plain, &muted, 3.1, 3.9);
+ assert!(off < 0.01, "a muted layer still moved the mix by {off:.4}");
+}
+
/// A reversed copy of a span plays its seconds backwards, picture and
/// sound, and comes out of the host's reverse job as one file the
/// timeline reads like any other. The screen recording's seconds 1 to 6
diff --git a/src/crates/concat-mcp/src/tools.rs b/src/crates/concat-mcp/src/tools.rs
index b9eb7ca4..dce61c94 100644
--- a/src/crates/concat-mcp/src/tools.rs
+++ b/src/crates/concat-mcp/src/tools.rs
@@ -388,7 +388,7 @@ pub fn catalogue() -> Vec<Tool> {
command(
"effect_layer_add",
"Add an effect layer",
- "Places an effect or look as a layer over the timeline: from `start` for `duration` seconds (5 s when absent), it treats everything beneath it. `effectId` is a package id from `effects_list`; the layer's opacity (via `clip_update`) is how strongly it applies. To put an effect on one clip instead, set that clip's `videoEffects` with `clip_update`.",
+ "Places an effect or look as a layer over the timeline: from `start` for `duration` seconds (5 s when absent), it treats everything beneath it. `effectId` is a package id from `effects_list`; the layer's opacity (via `clip_update`) is how strongly it applies. To put an effect on one clip instead, set that clip's `videoEffects` with `clip_update`. With `sound: true` and an \"audio\" package it is a sound layer (kind \"soundLayer\"): its chain, in the clip's `filters`, treats the mix of everything audible for its span, its opacity the wet/dry and its fades the ramps.",
"addLayerClip",
),
command(
diff --git a/src/crates/concat-media/src/audio.rs b/src/crates/concat-media/src/audio.rs
index 75aa9ff5..793c0005 100644
--- a/src/crates/concat-media/src/audio.rs
+++ b/src/crates/concat-media/src/audio.rs
@@ -76,6 +76,46 @@ pub struct AudioClip {
pub filter_chain: String,
}
+/// A treatment of the whole mix over a stretch of the timeline: a sound
+/// layer. Its chain hears only what plays inside its span, and what it
+/// gives back takes the untreated mix's place there by `strength`, ramped
+/// in and out by its fades - the reading a picture layer gets over the
+/// tracks beneath it, given to sound.
+///
+/// A bus over the sum and not the same chain copied onto every clip under
+/// it: a compressor or a limiter over the sum is a different sound from
+/// one on each part, and a reverb over the sum is one room rather than
+/// several.
+#[derive(Clone, Debug, PartialEq)]
+pub struct AudioBus {
+ /// Where the span starts on the timeline, in seconds.
+ pub start: f64,
+ /// How long it runs, in seconds.
+ pub duration: f64,
+ /// The FFmpeg audio filters run over the mix. Validated, not trusted.
+ pub filter_chain: String,
+ /// How much of the treated sound replaces the untreated, `0..=1`: the
+ /// layer's wet and dry.
+ pub strength: f64,
+ /// Seconds over which the treatment comes in from the span's start.
+ pub fade_in: f64,
+ /// Seconds over which it goes out into the span's end.
+ pub fade_out: f64,
+}
+
+impl AudioBus {
+ /// Where the span ends on the timeline.
+ pub fn end(&self) -> f64 {
+ self.start + self.duration
+ }
+
+ /// Whether the bus changes anything: a chain to run, some strength to
+ /// run it at, and some time to run it for.
+ pub fn audible(&self) -> bool {
+ !self.filter_chain.is_empty() && self.strength > 0.0 && self.duration > 0.0
+ }
+}
+
/// An FFmpeg `volume` expression for a gain that changes over a clip, or
/// Straight segments per eased one, when a gain ride is flattened for the
/// filtergraph.
@@ -210,23 +250,120 @@ pub fn tempo_stages(speed: f64) -> Vec<f64> {
/// rather than treating silence as a stream. The caller decides membership
/// by probing; this function decides what the mix means.
pub fn mix_graph(clips: &[AudioClip]) -> Result<String> {
- mix_graph_from(clips, &vec![0.0; clips.len()])
+ mix_graph_with(clips, &[])
+}
+
+/// [`mix_graph`] with sound layers over the mix: each bus treats the sum
+/// of every clip for its span, in the order given.
+pub fn mix_graph_with(clips: &[AudioClip], buses: &[AudioBus]) -> Result<String> {
+ let heard: Vec<Heard> = clips.iter().map(Heard::whole).collect();
+ mix_graph_from(clips, &heard, 0.0, buses)
}
-/// [`mix_graph`] for inputs that did not land exactly on their in-point:
-/// `leads[N]` is how many seconds before its clip's in-point input `N`
-/// starts, which the graph cuts off the front. A container seek lands on
-/// the packet at or before the target - a whole AAC frame early, 21 ms -
-/// and `mix_to_file` measures the miss from the first decoded frame; on
-/// the continuous clock it stamps, the trim is then exact. A lead below
-/// zero is sound that starts after the in-point - a file whose picture
-/// starts before its sound - and that much silence goes in front.
-fn mix_graph_from(clips: &[AudioClip], leads: &[f64]) -> Result<String> {
+/// How much of one clip an input of the mix carries, and how it landed.
+#[derive(Clone, Copy, Debug, PartialEq)]
+struct Heard {
+ /// Seconds into the clip's span where what is heard starts: zero for
+ /// the whole clip, more for one a window cuts into.
+ from: f64,
+ /// Seconds into the clip's span where it stops.
+ to: f64,
+ /// How many seconds before that point the input actually starts. A
+ /// container seek lands on the packet at or before the target - a
+ /// whole AAC frame early, 21 ms - and `run_mix` measures the miss from
+ /// the first decoded frame; on the continuous clock it stamps, the
+ /// graph's cut is then exact. A lead below zero is sound that starts
+ /// after that point - a file whose picture starts before its sound -
+ /// and that much silence goes in front.
+ lead: f64,
+}
+
+impl Heard {
+ /// All of `clip`, landed exactly.
+ fn whole(clip: &AudioClip) -> Heard {
+ Heard {
+ from: 0.0,
+ to: clip.duration,
+ lead: 0.0,
+ }
+ }
+
+ /// The part of `clip` inside the timeline's `[from, to)`, or None when
+ /// none of it is.
+ fn inside(clip: &AudioClip, from: f64, to: f64) -> Option<Heard> {
+ let start = (from - clip.start).max(0.0);
+ let end = (to - clip.start).min(clip.duration);
+ (end > start).then_some(Heard {
+ from: start,
+ to: end,
+ lead: 0.0,
+ })
+ }
+}
+
+/// The few milliseconds a bus's hard edges are softened over. Its chain is
+/// cut in and out of the mix where its span starts and ends, and an edge
+/// with no length at all is a click.
+const BUS_EDGE: f64 = 0.002;
+
+/// One bus's stage of the graph, from `[s{index}]` to `[s{index + 1}]`,
+/// with `origin` the timeline second the graph's clock starts at.
+///
+/// Three copies of the mix are summed: the mix itself, the mix taken away
+/// again by the bus's ramp and strength, and the chain's output given back
+/// by the same. Outside the span the second and third are silence - an
+/// `afade` silences what lies before a fade in and after a fade out - so
+/// the mix passes there sample for sample; inside it the treated sound has
+/// taken `strength` of the untreated one's place. The chain is fed only
+/// what plays inside the span, so an echo does not repeat what came before
+/// the layer, and what it rings on with past the span is cut at the end.
+fn bus_stage(index: usize, bus: &AudioBus, origin: f64) -> String {
+ let start = (bus.start - origin).max(0.0);
+ let end = start + bus.duration.max(0.0);
+ let edge = BUS_EDGE.min(bus.duration / 2.0).max(1e-4);
+ let ramp_in = bus.fade_in.clamp(edge, bus.duration.max(edge));
+ let ramp_out = bus.fade_out.clamp(edge, bus.duration.max(edge));
+ let strength = bus.strength.clamp(0.0, 1.0);
+ let gate = format!(
+ "afade=t=in:st={start:.6}:d={edge:.6},afade=t=out:st={:.6}:d={edge:.6}",
+ (end - edge).max(start)
+ );
+ let ramp = format!(
+ "afade=t=in:st={start:.6}:d={ramp_in:.6},afade=t=out:st={:.6}:d={ramp_out:.6}",
+ (end - ramp_out).max(start)
+ );
+ let chain = &bus.filter_chain;
+ let (here, next) = (format!("s{index}"), format!("s{}", index + 1));
+ // Restamped after the sum, as before the first stage: a chain's
+ // output need not stamp its frames the way its input did, and the
+ // next stage's fades are placed by the stamps.
+ format!(
+ "[{here}]asplit=3[{here}d][{here}u][{here}t];\
+ [{here}u]{ramp},volume=-{strength:.6}[{here}n];\
+ [{here}t]{gate},{chain},{ramp},volume={strength:.6}[{here}w];\
+ [{here}d][{here}n][{here}w]amix=inputs=3:normalize=0,aresample={MIX_RATE},asetpts=N/SR/TB[{next}]"
+ )
+}
+
+/// The graph for `clips`, each heard as `heard` says, on a clock that
+/// starts at the timeline's `origin` second, with `buses` over the sum.
+fn mix_graph_from(
+ clips: &[AudioClip],
+ heard: &[Heard],
+ origin: f64,
+ buses: &[AudioBus],
+) -> Result<String> {
let mut chains: Vec<String> = Vec::new();
for (index, clip) in clips.iter().enumerate() {
validate_chain(&clip.filter_chain)?;
- let delay_ms = (clip.start * 1000.0).round().max(0.0) as i64;
+ let heard = heard
+ .get(index)
+ .copied()
+ .unwrap_or_else(|| Heard::whole(clip));
+ let delay_ms = ((clip.start + heard.from - origin) * 1000.0)
+ .round()
+ .max(0.0) as i64;
let speed = clamp_speed(clip.speed);
// Each input is cut to its in-point, restamped from zero, then delayed
@@ -240,7 +377,7 @@ fn mix_graph_from(clips: &[AudioClip], leads: &[f64]) -> Result<String> {
// paused recordings) cannot park frames outside the mix, and the
// out-point is a sample count too - it stops feeding the input at
// `duration * speed` source seconds; see `MixInput::clip_samples`.
- let lead = leads.get(index).copied().unwrap_or(0.0);
+ let lead = heard.lead;
let mut stage = if lead > 0.0 {
format!("[{index}:a]atrim=start={lead:.6},asetpts=PTS-STARTPTS")
} else if lead < -0.0005 {
@@ -254,6 +391,15 @@ fn mix_graph_from(clips: &[AudioClip], leads: &[f64]) -> Result<String> {
stage.push_str(&filter);
}
+ // A clip a window cuts into is shaped on its own clock still: its
+ // gain ride and its fades are read from where the clip starts, so
+ // what is heard of it here is what the whole clip has at that
+ // moment. The stamps are moved on by what was cut, and back after.
+ let cut = heard.from > 0.0;
+ if cut {
+ stage.push_str(&format!(",asetpts=PTS-STARTPTS+{:.6}/TB", heard.from));
+ }
+
// Filters first: they are what the clip *is* now, and gain and fades
// are adjustments applied to that result. Reversing the order would
// let a compressor inside a filter chain undo the fade.
@@ -282,6 +428,9 @@ fn mix_graph_from(clips: &[AudioClip], leads: &[f64]) -> Result<String> {
clip.fade_out
));
}
+ if cut {
+ stage.push_str(",asetpts=PTS-STARTPTS");
+ }
stage.push_str(&format!(",adelay={delay_ms}:all=1[a{index}]"));
chains.push(stage);
@@ -290,11 +439,13 @@ fn mix_graph_from(clips: &[AudioClip], leads: &[f64]) -> Result<String> {
let inputs: String = (0..clips.len())
.map(|index| format!("[a{index}]"))
.collect();
- let mix = if clips.len() == 1 {
+ let mix = match clips.len() {
+ // Nothing to hear: silence, for as long as it is read, so a window
+ // with no clip in it still comes out its length.
+ 0 => format!("anullsrc=r={MIX_RATE}:cl=stereo[mixed]"),
// amix with one input would still apply its normalisation curve.
- format!("{inputs}anull[mixed]")
- } else {
- format!("{inputs}amix=inputs={}:normalize=0[mixed]", clips.len())
+ 1 => format!("{inputs}anull[mixed]"),
+ count => format!("{inputs}amix=inputs={count}:normalize=0[mixed]"),
};
// The `aresample` is load-bearing, and not about sample rates.
@@ -325,7 +476,26 @@ fn mix_graph_from(clips: &[AudioClip], leads: &[f64]) -> Result<String> {
// split makes - so the trim never saw the end come and the pad went on
// forever: an export with a split clip never finished. `mix_to_file`
// counts the samples it takes instead, on the clock it stamps itself.
- chains.push(format!("{mix};[mixed]aresample={MIX_RATE},apad[out]"));
+ //
+ // The sound layers go between the two: over the sum, and before the
+ // pad, so a chain never runs over the silence the reader takes past
+ // the end. Their fades are placed by the stamps, so the mix is
+ // restamped from its own sample count first - `N/SR` is the graph's
+ // clock, which starts at `origin` - rather than trusting what `amix`
+ // and the resampler left on it.
+ let mut stages = String::new();
+ let mut count = 0;
+ for bus in buses.iter().filter(|bus| bus.audible()) {
+ validate_chain(&bus.filter_chain)?;
+ stages.push(';');
+ stages.push_str(&bus_stage(count, bus, origin));
+ count += 1;
+ }
+ chains.push(if count == 0 {
+ format!("{mix};[mixed]aresample={MIX_RATE},apad[out]")
+ } else {
+ format!("{mix};[mixed]aresample={MIX_RATE},asetpts=N/SR/TB[s0]{stages};[s{count}]apad[out]")
+ });
Ok(chains.join(";"))
}
@@ -376,24 +546,195 @@ impl MixInput {
///
/// Every clip's file must contain an audio stream; see [`mix_graph`].
pub fn mix_to_file(clips: &[AudioClip], duration: f64, destination: &Path) -> Result<()> {
+ mix_to_file_with(clips, &[], duration, destination)
+}
+
+/// [`mix_to_file`] with sound layers over the mix; see [`AudioBus`].
+pub fn mix_to_file_with(
+ clips: &[AudioClip],
+ buses: &[AudioBus],
+ duration: f64,
+ destination: &Path,
+) -> Result<()> {
ffi::init();
// A bad chain is refused before any file is opened.
- for clip in clips {
- validate_chain(&clip.filter_chain)?;
+ for chain in clips
+ .iter()
+ .map(|clip| &clip.filter_chain)
+ .chain(buses.iter().map(|bus| &bus.filter_chain))
+ {
+ validate_chain(chain)?;
}
+
+ // The encoder, and the file it writes into.
+ let codec = encoder::find_by_name("aac").ok_or_else(|| Error::Missing {
+ what: "encoder",
+ name: "aac".to_owned(),
+ })?;
+ let mut output = ffmpeg::format::output(destination)
+ .map_err(|error| ffi::fail("create", destination, error))?;
+ let global_header = output
+ .format()
+ .flags()
+ .contains(ffmpeg::format::Flags::GLOBAL_HEADER);
+ let mut audio = ffmpeg::codec::Context::new_with_codec(codec)
+ .encoder()
+ .audio()
+ .map_err(|error| ffi::fail("audio encoder", destination, error))?;
+ audio.set_rate(MIX_RATE as i32);
+ audio.set_format(MIX_FORMAT);
+ audio.set_ch_layout(ChannelLayout::STEREO);
+ audio.set_bit_rate(192_000);
+ audio.set_time_base(ffmpeg::Rational::new(1, MIX_RATE as i32));
+ if global_header {
+ audio.set_flags(ffmpeg::codec::Flags::GLOBAL_HEADER);
+ }
+ let mut encoder = audio
+ .open()
+ .map_err(|error| ffi::fail("open encoder", destination, error))?;
+ let frame_size = encoder.frame_size().max(1);
+ {
+ let mut stream = output
+ .add_stream(codec)
+ .map_err(|error| ffi::fail("add stream", destination, error))?;
+ stream.copy_parameters_from_context(&encoder);
+ stream.set_time_base(ffmpeg::Rational::new(1, MIX_RATE as i32));
+ }
+ output
+ .write_header()
+ .map_err(|error| ffi::fail("write header", destination, error))?;
+ let stream_time_base = output
+ .stream(0)
+ .map(|stream| stream.time_base())
+ .unwrap_or(ffmpeg::Rational::new(1, MIX_RATE as i32));
+
+ let encoder_time_base = ffmpeg::Rational::new(1, MIX_RATE as i32);
+ let drain = |encoder: &mut encoder::audio::Encoder,
+ output: &mut ffmpeg::format::context::Output|
+ -> Result<()> {
+ loop {
+ let mut packet = ffmpeg::Packet::empty();
+ match encoder.receive_packet(&mut packet) {
+ Ok(()) => {
+ packet.set_stream(0);
+ packet.rescale_ts(encoder_time_base, stream_time_base);
+ packet
+ .write_interleaved(output)
+ .map_err(|error| ffi::fail("write packet", destination, error))?;
+ }
+ Err(ffmpeg::Error::Eof) => return Ok(()),
+ Err(error) if ffi::is_again(&error) => return Ok(()),
+ Err(error) => return Err(ffi::fail("encode", destination, error)),
+ }
+ }
+ };
+
+ run_mix(
+ clips,
+ buses,
+ (0.0, duration),
+ "fltp",
+ Some(frame_size),
+ destination,
+ |mixed| {
+ encoder
+ .send_frame(mixed)
+ .map_err(|error| ffi::fail("encode", destination, error))?;
+ drain(&mut encoder, &mut output)
+ },
+ )?;
+
+ // Flushed and closed whichever way the mix ended: an m4a without its
+ // trailer cannot be opened by the muxer.
+ encoder
+ .send_eof()
+ .map_err(|error| ffi::fail("encode", destination, error))?;
+ drain(&mut encoder, &mut output)?;
+ output
+ .write_trailer()
+ .map_err(|error| ffi::fail("write trailer", destination, error))
+}
+
+/// The mix of the timeline's `[from, to)` - every clip inside it, cut at
+/// its edges, with `buses` over the sum - as 16-bit stereo at
+/// [`MIX_RATE`], handed to `write` a frame's interleaved bytes at a time.
+///
+/// What a player that mixes clips itself plays where a sound layer runs:
+/// the layer is over the sum, which no one clip's sound can carry, so the
+/// span is mixed here, once, the way the export mixes it. A clip a window
+/// cuts into keeps its own clock (see `Heard`), so the window's sound is
+/// the export's sound over the same stretch.
+pub fn mix_pcm(
+ clips: &[AudioClip],
+ buses: &[AudioBus],
+ from: f64,
+ to: f64,
+ mut write: impl FnMut(&[u8]) -> Result<()>,
+) -> Result<()> {
+ ffi::init();
+ for chain in clips
+ .iter()
+ .map(|clip| &clip.filter_chain)
+ .chain(buses.iter().map(|bus| &bus.filter_chain))
+ {
+ validate_chain(chain)?;
+ }
+ run_mix(
+ clips,
+ buses,
+ (from, to),
+ "s16",
+ None,
+ Path::new("the mix"),
+ |mixed| {
+ // Packed: one plane, two channels of two bytes a sample. The
+ // plane can be padded past the samples, so it is cut to them.
+ let bytes = mixed.samples() * 4;
+ let plane = mixed.data(0);
+ write(&plane[..bytes.min(plane.len())])
+ },
+ )
+}
+
+/// Opens the clips heard inside `window`, builds their graph and runs it,
+/// handing `take` every frame of the mix in `format` (stereo, at
+/// [`MIX_RATE`]) until the window's length has been taken. `frame_size`,
+/// when given, is what each frame is cut to - an encoder's frame.
+fn run_mix(
+ clips: &[AudioClip],
+ buses: &[AudioBus],
+ window: (f64, f64),
+ format: &str,
+ frame_size: Option<u32>,
+ destination: &Path,
+ mut take: impl FnMut(&Audio) -> Result<()>,
+) -> Result<()> {
+ let (from, to) = window;
let missing = |name: &str| Error::Missing {
what: "filter",
name: name.to_owned(),
};
+ // The clips with something inside the window, and how much of each.
+ let mut members: Vec<AudioClip> = Vec::new();
+ let mut heard: Vec<Heard> = Vec::new();
+ for clip in clips {
+ if let Some(part) = Heard::inside(clip, from, to) {
+ members.push(clip.clone());
+ heard.push(part);
+ }
+ }
+
// Open every input first, and read one frame from each: the graph's
// sources are described by what actually comes out of the decoders.
- let mut inputs: Vec<MixInput> = Vec::with_capacity(clips.len());
- let mut first_frames: Vec<Audio> = Vec::with_capacity(clips.len());
- let mut leads: Vec<f64> = Vec::with_capacity(clips.len());
+ let mut inputs: Vec<MixInput> = Vec::with_capacity(members.len());
+ let mut first_frames: Vec<Audio> = Vec::with_capacity(members.len());
let mut graph = filter::Graph::new();
- for (index, clip) in clips.iter().enumerate() {
+ for (index, clip) in members.iter().enumerate() {
let path = clip.path.as_path();
+ let speed = clamp_speed(clip.speed);
+ // Where in the source what is heard of the clip begins.
+ let in_point = clip.source_start + heard[index].from * speed;
let mut input =
ffmpeg::format::input(path).map_err(|error| ffi::fail("open", path, error))?;
let stream_index =
@@ -413,9 +754,8 @@ pub fn mix_to_file(clips: &[AudioClip], duration: f64, destination: &Path) -> Re
.map_err(|error| ffi::fail("open decoder", path, error))?;
// Near the in-point: the packet at or before it. The graph cuts the
// rest, by the lead measured off the first frame below.
- if clip.source_start > 0.0 {
- let target =
- ((clip.source_start + start) * f64::from(ffmpeg::sys::AV_TIME_BASE)) as i64;
+ if in_point > 0.0 {
+ let target = ((in_point + start) * f64::from(ffmpeg::sys::AV_TIME_BASE)) as i64;
let _ = input.seek(target, ..=target);
}
let label = format!("{index}:a");
@@ -441,9 +781,9 @@ pub fn mix_to_file(clips: &[AudioClip], duration: f64, destination: &Path) -> Re
let landed = first
.timestamp()
.and_then(|ticks| ffi::seconds(ticks, time_base))
- .map_or(clip.source_start, |at| at.as_f64() - start);
- let lead = clip.source_start - landed;
- leads.push(lead);
+ .map_or(in_point, |at| at.as_f64() - start);
+ let lead = in_point - landed;
+ heard[index].lead = lead;
// Our continuous PTS: sample count from the start of this clip.
first.set_pts(Some(0));
// The out-point lives here, not in the filtergraph: how many source
@@ -451,10 +791,10 @@ pub fn mix_to_file(clips: &[AudioClip], duration: f64, destination: &Path) -> Re
// sped-up clip covers more source than its timeline length, hence
// the speed factor. The first frame goes into the graph separately
// below, so it counts towards the total.
+ let span = heard[index].to - heard[index].from;
mix_input.samples_sent = first.samples() as i64;
- mix_input.clip_samples = ((clip.duration * clamp_speed(clip.speed) + lead).max(0.0)
- * f64::from(first.rate()))
- .round() as i64;
+ mix_input.clip_samples =
+ ((span * speed + lead).max(0.0) * f64::from(first.rate())).round() as i64;
// One sample per time-base tick: the PTS we stamp is a plain
// running sample count, so the graph's clock is the sample clock.
let args = format!(
@@ -482,10 +822,10 @@ pub fn mix_to_file(clips: &[AudioClip], duration: f64, destination: &Path) -> Re
)
.map_err(|error| ffi::fail("buffer sink", destination, error))?;
- // The plan's `[out]` lands on the encoder's own format before the sink.
- let graph_spec = mix_graph_from(clips, &leads)?;
+ // The plan's `[out]` lands on the reader's own format before the sink.
+ let graph_spec = mix_graph_from(&members, &heard, from, buses)?;
let spec = format!(
- "{graph_spec};[out]aformat=sample_fmts=fltp:sample_rates={MIX_RATE}:channel_layouts=stereo[sink]"
+ "{graph_spec};[out]aformat=sample_fmts={format}:sample_rates={MIX_RATE}:channel_layouts=stereo[sink]"
);
let mut parser = graph
.input("sink", 0)
@@ -501,80 +841,18 @@ pub fn mix_to_file(clips: &[AudioClip], duration: f64, destination: &Path) -> Re
graph
.validate()
.map_err(|error| ffi::fail("filter graph", destination, error))?;
-
- // The encoder, and the file it writes into.
- let codec = encoder::find_by_name("aac").ok_or_else(|| Error::Missing {
- what: "encoder",
- name: "aac".to_owned(),
- })?;
- let mut output = ffmpeg::format::output(destination)
- .map_err(|error| ffi::fail("create", destination, error))?;
- let global_header = output
- .format()
- .flags()
- .contains(ffmpeg::format::Flags::GLOBAL_HEADER);
- let mut audio = ffmpeg::codec::Context::new_with_codec(codec)
- .encoder()
- .audio()
- .map_err(|error| ffi::fail("audio encoder", destination, error))?;
- audio.set_rate(MIX_RATE as i32);
- audio.set_format(MIX_FORMAT);
- audio.set_ch_layout(ChannelLayout::STEREO);
- audio.set_bit_rate(192_000);
- audio.set_time_base(ffmpeg::Rational::new(1, MIX_RATE as i32));
- if global_header {
- audio.set_flags(ffmpeg::codec::Flags::GLOBAL_HEADER);
- }
- let mut encoder = audio
- .open()
- .map_err(|error| ffi::fail("open encoder", destination, error))?;
- let frame_size = encoder.frame_size().max(1);
- {
- let mut stream = output
- .add_stream(codec)
- .map_err(|error| ffi::fail("add stream", destination, error))?;
- stream.copy_parameters_from_context(&encoder);
- stream.set_time_base(ffmpeg::Rational::new(1, MIX_RATE as i32));
- }
- output
- .write_header()
- .map_err(|error| ffi::fail("write header", destination, error))?;
- let stream_time_base = output
- .stream(0)
- .map(|stream| stream.time_base())
- .unwrap_or(ffmpeg::Rational::new(1, MIX_RATE as i32));
- {
+ if let Some(frame_size) = frame_size {
let mut sink = graph.get("sink").expect("the graph has a sink");
sink.sink().set_frame_size(frame_size);
}
- let encoder_time_base = ffmpeg::Rational::new(1, MIX_RATE as i32);
// Where the mix ends, in samples of our own clock. The graph pads
// silence past the last clip for as long as it is asked, and its
// timestamps are not to be trusted for the cut - `amix` drops them once
// an input ends early - so the count of what has been taken is the
// whole of the decision, and the last frame is shortened to land on it.
- let total_samples = (duration.max(0.0) * f64::from(MIX_RATE)).round() as i64;
+ let total_samples = ((to - from).max(0.0) * f64::from(MIX_RATE)).round() as i64;
let mut written_samples: i64 = 0;
- let drain = |encoder: &mut encoder::audio::Encoder,
- output: &mut ffmpeg::format::context::Output|
- -> Result<()> {
- loop {
- let mut packet = ffmpeg::Packet::empty();
- match encoder.receive_packet(&mut packet) {
- Ok(()) => {
- packet.set_stream(0);
- packet.rescale_ts(encoder_time_base, stream_time_base);
- packet
- .write_interleaved(output)
- .map_err(|error| ffi::fail("write packet", destination, error))?;
- }
- Err(ffmpeg::Error::Eof) => return Ok(()),
- Err(error) if ffi::is_again(&error) => return Ok(()),
- Err(error) => return Err(ffi::fail("encode", destination, error)),
- }
- }
- };
// Feed the sources round-robin and drain the sink after every push, so
// no input runs ahead of the others by more than a frame: what a filter
@@ -605,18 +883,14 @@ pub fn mix_to_file(clips: &[AudioClip], duration: f64, destination: &Path) -> Re
}
mixed.set_pts(Some(written_samples));
written_samples += mixed.samples() as i64;
- encoder
- .send_frame(&mixed)
- .map_err(|error| ffi::fail("encode", destination, error))?;
- drain(&mut encoder, &mut output)?;
+ take(&mixed)?;
if written_samples >= total_samples {
break 'mix;
}
}
// The graph ran dry before the timeline's end: nothing left
- // to pad from. Break, do not return: the finalisation below
- // this loop flushes the encoder and writes the trailer, and
- // an m4a without its trailer cannot be opened by the muxer.
+ // to pad from. Break, do not return: the caller still has
+ // its encoder to flush and its trailer to write.
Err(ffmpeg::Error::Eof) => break 'mix,
Err(error) if ffi::is_again(&error) => break,
Err(error) => return Err(ffi::fail("filter output", destination, error)),
@@ -671,14 +945,7 @@ pub fn mix_to_file(clips: &[AudioClip], duration: f64, destination: &Path) -> Re
}
}
}
-
- encoder
- .send_eof()
- .map_err(|error| ffi::fail("encode", destination, error))?;
- drain(&mut encoder, &mut output)?;
- output
- .write_trailer()
- .map_err(|error| ffi::fail("write trailer", destination, error))
+ Ok(())
}
/// Joins an already-encoded video file and audio file into `output`.
@@ -983,7 +1250,10 @@ mod tests {
#[test]
fn an_input_that_landed_early_is_cut_to_its_in_point() {
- let graph = mix_graph_from(&[clip("a.mp4"), clip("b.mp4")], &[0.0213, 0.0]).expect("valid");
+ let clips = [clip("a.mp4"), clip("b.mp4")];
+ let mut heard: Vec<Heard> = clips.iter().map(Heard::whole).collect();
+ heard[0].lead = 0.0213;
+ let graph = mix_graph_from(&clips, &heard, 0.0, &[]).expect("valid");
assert!(
graph.contains("[0:a]atrim=start=0.021300,asetpts=PTS-STARTPTS,"),
"graph was: {graph}"
@@ -1241,6 +1511,183 @@ mod tests {
);
}
+ fn bus(start: f64, duration: f64, chain: &str) -> AudioBus {
+ AudioBus {
+ start,
+ duration,
+ filter_chain: chain.to_owned(),
+ strength: 1.0,
+ fade_in: 0.0,
+ fade_out: 0.0,
+ }
+ }
+
+ #[test]
+ fn a_bus_runs_over_the_sum_between_the_resampler_and_the_pad() {
+ let graph = mix_graph_with(
+ &[clip("a.mp4"), clip("b.mp4")],
+ &[bus(1.0, 2.0, "lowpass=f=300")],
+ )
+ .expect("valid");
+ let mixed = graph
+ .find("[mixed]aresample=48000,asetpts=N/SR/TB[s0]")
+ .expect("into the bus");
+ let chain = graph.find("lowpass=f=300").expect("the chain");
+ let pad = graph.find("[s1]apad[out]").expect("out of the bus");
+ assert!(mixed < chain && chain < pad, "graph was: {graph}");
+ // Fed only what plays inside its span, and given back there.
+ assert!(
+ graph.contains(
+ "afade=t=in:st=1.000000:d=0.002000,afade=t=out:st=2.998000:d=0.002000,lowpass"
+ ),
+ "graph was: {graph}"
+ );
+ assert!(
+ graph.contains("amix=inputs=3:normalize=0"),
+ "graph was: {graph}"
+ );
+ }
+
+ #[test]
+ fn a_bus_with_nothing_to_do_leaves_the_graph_as_it_was() {
+ let plain = mix_graph(&[clip("a.mp4")]).expect("valid");
+ let mut idle = bus(0.0, 1.0, "lowpass=f=300");
+ idle.strength = 0.0;
+ for buses in [vec![idle], vec![bus(0.0, 1.0, "")]] {
+ assert_eq!(
+ mix_graph_with(&[clip("a.mp4")], &buses).expect("valid"),
+ plain
+ );
+ }
+ }
+
+ #[test]
+ fn a_bus_chain_that_escapes_its_slot_is_refused() {
+ assert!(matches!(
+ mix_graph_with(&[clip("a.mp4")], &[bus(0.0, 1.0, "anull[x]")]),
+ Err(Error::InvalidFilterChain { .. })
+ ));
+ }
+
+ /// A clip a window cuts into keeps its own clock: its fades are read
+ /// from where it starts, the stamps moved on by what was cut.
+ #[test]
+ fn a_clip_cut_by_a_window_is_shaped_on_its_own_clock() {
+ let mut shaped = clip("a.mp4");
+ shaped.start = 1.0;
+ shaped.fade_in = 0.5;
+ let heard = Heard::inside(&shaped, 1.25, 4.0).expect("inside");
+ assert_eq!((heard.from, heard.to), (0.25, 2.0));
+ let graph = mix_graph_from(&[shaped], &[heard], 1.25, &[]).expect("valid");
+ assert!(
+ graph.contains("asetpts=PTS-STARTPTS+0.250000/TB,afade=t=in:st=0:d=0.5000,asetpts=PTS-STARTPTS,adelay=0:all=1"),
+ "graph was: {graph}"
+ );
+ assert!(Heard::inside(&clip("a.mp4"), 2.0, 3.0).is_none());
+ }
+
+ /// A 440 Hz tone at half scale, stereo 16-bit, as a WAV of `seconds`.
+ fn tone_wav(path: &Path, seconds: f64) {
+ let count = (seconds * f64::from(MIX_RATE)) as usize;
+ let mut data = Vec::with_capacity(count * 4);
+ for index in 0..count {
+ let t = index as f64 / f64::from(MIX_RATE);
+ let value = (0.5 * (2.0 * std::f64::consts::PI * 440.0 * t).sin() * 32767.0) as i16;
+ data.extend_from_slice(&value.to_le_bytes());
+ data.extend_from_slice(&value.to_le_bytes());
+ }
+ let mut bytes = Vec::with_capacity(44 + data.len());
+ bytes.extend_from_slice(b"RIFF");
+ bytes.extend_from_slice(&(36 + data.len() as u32).to_le_bytes());
+ bytes.extend_from_slice(b"WAVEfmt ");
+ bytes.extend_from_slice(&16u32.to_le_bytes());
+ bytes.extend_from_slice(&1u16.to_le_bytes());
+ bytes.extend_from_slice(&2u16.to_le_bytes());
+ bytes.extend_from_slice(&MIX_RATE.to_le_bytes());
+ bytes.extend_from_slice(&(MIX_RATE * 4).to_le_bytes());
+ bytes.extend_from_slice(&4u16.to_le_bytes());
+ bytes.extend_from_slice(&16u16.to_le_bytes());
+ bytes.extend_from_slice(b"data");
+ bytes.extend_from_slice(&(data.len() as u32).to_le_bytes());
+ bytes.extend_from_slice(&data);
+ std::fs::write(path, bytes).expect("writes the wav");
+ }
+
+ /// The left channel of `mix_pcm` over `[from, to)`.
+ fn left(clips: &[AudioClip], buses: &[AudioBus], from: f64, to: f64) -> Vec<i16> {
+ let mut bytes = Vec::new();
+ mix_pcm(clips, buses, from, to, |chunk| {
+ bytes.extend_from_slice(chunk);
+ Ok(())
+ })
+ .expect("mixes");
+ bytes
+ .chunks_exact(4)
+ .map(|frame| i16::from_le_bytes([frame[0], frame[1]]))
+ .collect()
+ }
+
+ /// The loudest sample difference between `a` and `b` over seconds
+ /// `[from, to)` of both.
+ fn worst(a: &[i16], b: &[i16], from: f64, to: f64) -> i32 {
+ let at = |seconds: f64| (seconds * f64::from(MIX_RATE)) as usize;
+ (at(from)..at(to).min(a.len()).min(b.len()))
+ .map(|index| (i32::from(a[index]) - i32::from(b[index])).abs())
+ .max()
+ .unwrap_or(0)
+ }
+
+ /// A sound layer changes the mix over its span and nowhere else, and a
+ /// window of the mix - what playback plays where a layer runs - is the
+ /// whole mix over the same stretch.
+ #[test]
+ fn a_bus_treats_its_span_alone_and_a_window_of_it_is_the_whole_mix_there() {
+ let dir = std::env::temp_dir().join(format!("concat-bus-{}", std::process::id()));
+ std::fs::create_dir_all(&dir).expect("a folder");
+ let source = dir.join("tone.wav");
+ tone_wav(&source, 4.0);
+ let mut tone = clip("tone.wav");
+ tone.path = source.clone();
+ tone.duration = 4.0;
+ let clips = [tone];
+ // A low-pass far under the tone all but takes it away.
+ let buses = [bus(1.0, 2.0, "lowpass=f=60,lowpass=f=60")];
+
+ let plain = left(&clips, &[], 0.0, 4.0);
+ let treated = left(&clips, &buses, 0.0, 4.0);
+ let window = left(&clips, &buses, 0.5, 3.5);
+ let _ = std::fs::remove_dir_all(&dir);
+
+ assert_eq!(plain.len(), 4 * MIX_RATE as usize);
+ assert_eq!(treated.len(), plain.len());
+ assert_eq!(window.len(), 3 * MIX_RATE as usize);
+ // Untouched before the span and after it, sample for sample.
+ assert_eq!(worst(&plain, &treated, 0.0, 0.999), 0);
+ assert_eq!(worst(&plain, &treated, 3.001, 4.0), 0);
+ // Inside it the tone is all but gone.
+ let peak = |samples: &[i16], from: f64, to: f64| {
+ let at = |seconds: f64| (seconds * f64::from(MIX_RATE)) as usize;
+ samples[at(from)..at(to)]
+ .iter()
+ .map(|sample| i32::from(*sample).abs())
+ .max()
+ .unwrap_or(0)
+ };
+ assert!(
+ peak(&plain, 1.2, 2.8) > 15_000,
+ "the tone is there untreated"
+ );
+ assert!(
+ peak(&treated, 1.2, 2.8) < 3_000,
+ "the tone came through at {}",
+ peak(&treated, 1.2, 2.8)
+ );
+ // The window is the whole mix from half a second on.
+ let offset = (0.5 * f64::from(MIX_RATE)) as usize;
+ let difference = worst(&treated[offset..], &window, 0.0, 3.0);
+ assert!(difference <= 1, "the window differs by {difference}");
+ }
+
#[test]
fn ordinary_chains_pass_validation() {
for good in [
diff --git a/src/crates/concat-mobile/src/lib.rs b/src/crates/concat-mobile/src/lib.rs
index 1af58dc8..0550d755 100644
--- a/src/crates/concat-mobile/src/lib.rs
+++ b/src/crates/concat-mobile/src/lib.rs
@@ -20,7 +20,7 @@ use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::{Arc, Mutex};
use concat_host::Session;
-use concat_host::playback::{ClipSpec, GainKey, Playback, PlaybackEvents};
+use concat_host::playback::{ClipSpec, Playback, PlaybackEvents};
use concat_project::Command;
mod render;
@@ -362,45 +362,10 @@ fn rate_of(fraction: &str) -> (i64, i64) {
}
}
-/// The audible clips of a flattened edit, as playback takes them.
-///
-/// A copy of `studio::audio_specs` in the Slint window's crate - which is
-/// exactly the point of the spike's report: this belongs in the host, where
-/// both shells would share it.
+/// The audible clips of a flattened edit, as playback takes them - the
+/// host's one definition, which the desktop window plays too.
fn audio_specs(clips: &[concat_export::ExportClip]) -> Vec<ClipSpec> {
- clips
- .iter()
- .filter(|clip| {
- !clip.muted
- && (clip.kind == concat_export::ClipKind::Audio
- || (clip.kind == concat_export::ClipKind::Video
- && clip.has_audio.unwrap_or(true)))
- })
- .flat_map(concat_export::audio_pieces)
- .map(|piece| ClipSpec {
- path: piece.path.to_string_lossy().into_owned(),
- audio_stream: piece.stream.map(|index| index as u32),
- start: piece.start,
- duration: piece.duration,
- source_start: piece.source_start,
- volume: piece.volume as f32,
- volume_curve: piece
- .volume_curve
- .keys()
- .iter()
- .map(|key| GainKey {
- at: key.at,
- gain: key.value,
- ease: [key.ease.x1, key.ease.y1, key.ease.x2, key.ease.y2],
- })
- .collect(),
- fade_in: piece.fade_in,
- fade_out: piece.fade_out,
- speed: piece.speed,
- preserve_pitch: piece.preserve_pitch,
- chain: piece.filter_chain,
- })
- .collect()
+ concat_host::playback::audible(clips)
}
#[cfg(test)]
diff --git a/src/crates/concat-project/src/commands/clips.rs b/src/crates/concat-project/src/commands/clips.rs
index 9a1acd01..a72824ea 100644
--- a/src/crates/concat-project/src/commands/clips.rs
+++ b/src/crates/concat-project/src/commands/clips.rs
@@ -205,6 +205,7 @@ pub(super) fn apply(
duration,
effect_id,
name,
+ sound,
} => {
let duration = duration
.unwrap_or(DEFAULT_LAYER_DURATION)
@@ -216,7 +217,9 @@ pub(super) fn apply(
// Over the picture, as a title is: a layer treats what is
// beneath it, and the bottom-first walk put one under the
// footage whenever a lower lane was free, where it treated
- // nothing.
+ // nothing. A sound layer treats every lane alike, and goes
+ // over the picture too, where it reads as a treatment and
+ // not as one more sound.
None => first_free_track_above(timeline, start, duration)
.unwrap_or_else(|| fresh_track(timeline, mint)),
};
@@ -227,9 +230,17 @@ pub(super) fn apply(
} else {
name
};
- let mut clip =
- Clip::blank(id.clone(), track_id, ClipKind::Layer, name, start, duration);
- clip.video_effects = vec![AppliedFilter::new(effect_id)];
+ let kind = if sound {
+ ClipKind::SoundLayer
+ } else {
+ ClipKind::Layer
+ };
+ let mut clip = Clip::blank(id.clone(), track_id, kind, name, start, duration);
+ if sound {
+ clip.filters = vec![AppliedFilter::new(effect_id)];
+ } else {
+ clip.video_effects = vec![AppliedFilter::new(effect_id)];
+ }
timeline.clips.push(Arc::new(clip));
Ok(Outcome {
created_id: Some(id),
diff --git a/src/crates/concat-project/src/commands/mod.rs b/src/crates/concat-project/src/commands/mod.rs
index f66afd3c..0acd9787 100644
--- a/src/crates/concat-project/src/commands/mod.rs
+++ b/src/crates/concat-project/src/commands/mod.rs
@@ -397,7 +397,8 @@ pub enum Command {
/// Places a layer: a look or an effect over a span of the timeline that
/// treats everything beneath it. No media; the chain starts as the one
/// package named, at its defaults, and the clip's opacity is how hard it
- /// is applied.
+ /// is applied. With `sound`, a sound layer: an audio package, run over
+ /// the mix of everything audible for its span.
AddLayerClip {
/// The lane to place it on. None picks the first free lane *above*
/// the highest one occupied over its span, minting one at the top
@@ -409,10 +410,17 @@ pub enum Command {
/// Seconds on the timeline; the editorial default when absent.
#[serde(default)]
duration: Option<f64>,
- /// The package the layer applies, e.g. "concat.warm".
+ /// The package the layer applies, e.g. "concat.warm", or an audio
+ /// one, e.g. "concat.telephone", with `sound`.
effect_id: String,
/// What the lane calls it.
name: String,
+ /// True lays a sound layer ([`crate::model::ClipKind::SoundLayer`]):
+ /// the package goes on the clip's `filters`, and the layer treats
+ /// the soundtrack rather than the picture. Absent is a picture
+ /// layer.
+ #[serde(default)]
+ sound: bool,
},
/// Gives a clip a speed curve, or takes it away. The source covered is
/// held constant, as a speed change does, so the clip's timeline length
diff --git a/src/crates/concat-project/src/doc.rs b/src/crates/concat-project/src/doc.rs
index 69660602..34d5b4d2 100644
--- a/src/crates/concat-project/src/doc.rs
+++ b/src/crates/concat-project/src/doc.rs
@@ -262,7 +262,9 @@ fn settle_clip(
return None;
}
match clip.kind {
- ClipKind::Text | ClipKind::Layer | ClipKind::Shape => clip.media_id.clear(),
+ ClipKind::Text | ClipKind::Layer | ClipKind::SoundLayer | ClipKind::Shape => {
+ clip.media_id.clear()
+ }
ClipKind::Video | ClipKind::Audio | ClipKind::Image => {
if !media.iter().any(|item| item.id == clip.media_id) {
return None;
diff --git a/src/crates/concat-project/src/lib.rs b/src/crates/concat-project/src/lib.rs
index 356ab923..f6dae4f2 100644
--- a/src/crates/concat-project/src/lib.rs
+++ b/src/crates/concat-project/src/lib.rs
@@ -3987,6 +3987,7 @@ mod tests {
duration: Some(3.0),
effect_id: "concat.adjust".into(),
name: "Adjustment".into(),
+ sound: false,
})
.expect("adds")
.created_id
@@ -4005,6 +4006,106 @@ mod tests {
);
}
+ /// A sound layer carries its package on the sound's chain and none on
+ /// the picture's, lands over the footage as a picture layer does, is
+ /// written as a kind of its own and read back as one, and goes with an
+ /// undo.
+ #[test]
+ fn a_sound_layer_carries_an_audio_chain_and_round_trips() {
+ let mut editor = Editor::new();
+ let media_id = editor
+ .apply(media("/a.mp4", 10.0, true))
+ .expect("adds")
+ .created_id
+ .expect("id");
+ let video_track = editor.project().active().tracks[2].id.clone();
+ editor
+ .apply(Command::AddClip {
+ media_id,
+ track_id: video_track.clone(),
+ start: 0.0,
+ ripple: false,
+ })
+ .expect("adds");
+ let layer_id = editor
+ .apply(Command::AddLayerClip {
+ track_id: None,
+ start: 1.0,
+ duration: Some(3.0),
+ effect_id: "concat.telephone".into(),
+ name: "Telephone".into(),
+ sound: true,
+ })
+ .expect("adds")
+ .created_id
+ .expect("id");
+ let timeline = editor.project().active();
+ let layer = timeline.clip(&layer_id).expect("exists");
+ assert_eq!(layer.kind, ClipKind::SoundLayer);
+ assert_eq!(layer.media_id, "");
+ assert_eq!(layer.filters.len(), 1);
+ assert_eq!(layer.filters[0].id, "concat.telephone");
+ assert!(layer.video_effects.is_empty(), "nothing on the picture");
+ let row = |id: &str| timeline.tracks.iter().position(|t| t.id == id);
+ assert!(row(&layer.track_id) > row(&video_track));
+
+ let document = editor.to_document(&settings());
+ let written = document["timelines"][0]["clips"]
+ .as_array()
+ .expect("clips")
+ .iter()
+ .find(|clip| clip["id"] == layer_id.as_str())
+ .expect("written");
+ assert_eq!(written["kind"], "soundLayer");
+ let reopened = Editor::from_document(&document).expect("reads");
+ assert_eq!(
+ reopened.project().active().clip(&layer_id),
+ editor.project().active().clip(&layer_id),
+ "read back as it was written"
+ );
+
+ // A copy is laid as a layer and then made like the source, the way
+ // the window copies, pastes and duplicates one: kind, chain,
+ // strength and ramps all come with it.
+ let mut source = editor
+ .project()
+ .active()
+ .clip(&layer_id)
+ .expect("exists")
+ .clone();
+ source.filters[0].params.insert("drive".to_owned(), 6.0);
+ source.opacity = 0.5;
+ source.fade_in = 0.25;
+ let copy_id = editor
+ .apply(Command::AddLayerClip {
+ track_id: Some(source.track_id.clone()),
+ start: 4.0,
+ duration: Some(source.duration),
+ effect_id: source.filters[0].id.clone(),
+ name: source.name.clone(),
+ sound: true,
+ })
+ .expect("adds")
+ .created_id
+ .expect("id");
+ editor
+ .apply(Command::MatchClip {
+ clip_id: copy_id.clone(),
+ like: Box::new(source.clone()),
+ })
+ .expect("matches");
+ let copy = editor.project().active().clip(&copy_id).expect("exists");
+ assert_eq!(copy.kind, ClipKind::SoundLayer);
+ assert_eq!(copy.filters, source.filters);
+ assert_eq!((copy.opacity, copy.fade_in), (0.5, 0.25));
+ assert_eq!(copy.start, 4.0);
+
+ while editor.project().active().clip(&layer_id).is_some() {
+ assert!(editor.undo());
+ }
+ assert!(editor.project().active().clip(&copy_id).is_none());
+ }
+
#[test]
fn a_caption_on_an_empty_timeline_lands_on_the_bottom_lane() {
let mut editor = Editor::new();
@@ -5171,6 +5272,7 @@ mod tests {
duration: Some(1.0),
effect_id: "concat.warm".into(),
name: name.into(),
+ sound: false,
})
.expect("a layer");
}
diff --git a/src/crates/concat-project/src/model.rs b/src/crates/concat-project/src/model.rs
index 28c1399c..218eed78 100644
--- a/src/crates/concat-project/src/model.rs
+++ b/src/crates/concat-project/src/model.rs
@@ -64,6 +64,18 @@ pub enum ClipKind {
/// lives in [`Clip::video_effects`], its strength in [`Clip::opacity`]
/// and its ramps in the fades.
Layer,
+ /// A treatment of the sound for as long as it runs: its chain, in
+ /// [`Clip::filters`], works on the mix of everything audible over its
+ /// span - a voice changer, a room or a telephone over the whole
+ /// soundtrack, not one clip of it. No media behind it; how much of the
+ /// treated sound replaces the untreated is [`Clip::opacity`], the
+ /// strength a picture layer has, and its ramps are the fades. A kind of
+ /// its own rather than a flag on [`ClipKind::Layer`], so it stays what
+ /// it is with its chain emptied, and a build that predates it leaves it
+ /// out as a clip it cannot play rather than reading it as a picture
+ /// layer that treats nothing.
+ #[serde(rename = "soundLayer")]
+ SoundLayer,
/// A shape: a square, a circle, an arrow, drawn over the picture. No
/// media behind it; what it is and how it is painted lives in
/// [`Clip::shape`], and it is placed and scaled like a still.
@@ -1841,7 +1853,8 @@ pub struct Clip {
/// Keep voices at their natural pitch when `speed` is not 1. On by
/// default; off gives the tape-machine chipmunk/slow-motion sound.
pub preserve_pitch: bool,
- /// Audio filters, in order - order is audible.
+ /// Audio filters, in order - order is audible. On a sound layer, the
+ /// chain it runs over the mix.
#[serde(default)]
#[serde(deserialize_with = "wire::list")]
pub filters: Vec<AppliedFilter>,
diff --git a/src/crates/concat/locales/ar.json b/src/crates/concat/locales/ar.json
index 2b778f92..4299a782 100644
--- a/src/crates/concat/locales/ar.json
+++ b/src/crates/concat/locales/ar.json
@@ -114,6 +114,7 @@
"clipInspector.smartEraser": "ممحاة ذكية",
"clipInspector.smoothness": "النعومة",
"clipInspector.softness": "النعومة",
+ "clipInspector.soundLayerTreatsTheMix": "تعالج طبقة الصوت كل ما تسمعه طوال مدة تشغيلها. قصّها على المخطط الزمني لتغيير ما تغطيه.",
"clipInspector.source": "المصدر",
"clipInspector.stabilize": "تثبيت الصورة",
"clipInspector.stabilizeEased": "كُبّرت إلى {0}%. تثبيت كل إطار يتطلب {1}%، لذا تُثبَّت أكثر اللحظات اهتزازًا بدرجة أقل؛ ارفع أقصى تكبير لتثبيتها تمامًا.",
diff --git a/src/crates/concat/locales/az.json b/src/crates/concat/locales/az.json
index 7a2b75a7..aefda884 100644
--- a/src/crates/concat/locales/az.json
+++ b/src/crates/concat/locales/az.json
@@ -114,6 +114,7 @@
"clipInspector.smartEraser": "Ağıllı pozan",
"clipInspector.smoothness": "Hamarlıq",
"clipInspector.softness": "Yumşaqlıq",
+ "clipInspector.soundLayerTreatsTheMix": "Səs qatı işlədiyi müddətdə eşidilən hər şeyi emal edir. Əhatə etdiyini dəyişmək üçün onu zaman xəttində kəsin.",
"clipInspector.source": "Mənbə",
"clipInspector.stabilize": "Stabilləşdir",
"clipInspector.stabilizeEased": "{0}% böyüdüldü. Hər kadrı tam sabitləmək üçün {1}% lazım olardı, ona görə ən çox titrəyən anlar daha az sabitlənib. Onları da tam sabitləmək üçün Maks. böyütməni artırın.",
diff --git a/src/crates/concat/locales/bn.json b/src/crates/concat/locales/bn.json
index 267c9e47..d03e98bf 100644
--- a/src/crates/concat/locales/bn.json
+++ b/src/crates/concat/locales/bn.json
@@ -114,6 +114,7 @@
"clipInspector.smartEraser": "স্মার্ট ইরেজার",
"clipInspector.smoothness": "মসৃণতা",
"clipInspector.softness": "কোমলতা",
+ "clipInspector.soundLayerTreatsTheMix": "সাউন্ড লেয়ার যতক্ষণ চলে, ততক্ষণ শোনা সবকিছুর ওপর কাজ করে। কতটা জুড়ে থাকবে তা বদলাতে টাইমলাইনে এটি ট্রিম করুন।",
"clipInspector.source": "সোর্স",
"clipInspector.stabilize": "স্থির করুন",
"clipInspector.stabilizeEased": "{0}% পর্যন্ত জুম করা হয়েছে। প্রতিটি ফ্রেম স্থির করতে {1}% লাগত, তাই সবচেয়ে বেশি কাঁপা মুহূর্তগুলো কম স্থির করা হয়েছে; পুরোপুরি স্থির করতে সর্বোচ্চ জুম বাড়ান।",
diff --git a/src/crates/concat/locales/de.json b/src/crates/concat/locales/de.json
index a415bd64..9b619171 100644
--- a/src/crates/concat/locales/de.json
+++ b/src/crates/concat/locales/de.json
@@ -114,6 +114,7 @@
"clipInspector.smartEraser": "Smart-Radierer",
"clipInspector.smoothness": "Glättung",
"clipInspector.softness": "Weichheit",
+ "clipInspector.soundLayerTreatsTheMix": "Eine Tonebene bearbeitet alles, was zu hören ist, solange sie läuft. Kürze sie auf der Zeitleiste, um zu ändern, was sie abdeckt.",
"clipInspector.source": "Source",
"clipInspector.stabilize": "Stabilisieren",
"clipInspector.stabilizeEased": "Auf {0}% vergrößert. Jedes Bild ruhig zu halten bräuchte {1}%, daher werden die wackligsten Momente weniger stabilisiert; erhöhe Max. Zoom, um sie ganz zu stabilisieren.",
diff --git a/src/crates/concat/locales/en.json b/src/crates/concat/locales/en.json
index 97ffa50c..b60aed12 100644
--- a/src/crates/concat/locales/en.json
+++ b/src/crates/concat/locales/en.json
@@ -114,6 +114,7 @@
"clipInspector.smartEraser": "Smart eraser",
"clipInspector.smoothness": "Smoothness",
"clipInspector.softness": "Softness",
+ "clipInspector.soundLayerTreatsTheMix": "A sound layer treats everything you hear for as long as it runs. Trim it on the timeline to change what it covers.",
"clipInspector.source": "Source",
"clipInspector.stabilize": "Stabilize",
"clipInspector.stabilizeEased": "Zoomed to {0}%. Steadying every frame would take {1}%, so the shakiest moments are steadied less; raise Max zoom to steady them fully.",
diff --git a/src/crates/concat/locales/es.json b/src/crates/concat/locales/es.json
index 7d2d250d..503d6d5e 100644
--- a/src/crates/concat/locales/es.json
+++ b/src/crates/concat/locales/es.json
@@ -114,6 +114,7 @@
"clipInspector.smartEraser": "Borrador inteligente",
"clipInspector.smoothness": "Suavidad",
"clipInspector.softness": "Suavidad",
+ "clipInspector.soundLayerTreatsTheMix": "Una capa de sonido trata todo lo que se oye mientras dura. Recórtala en la línea de tiempo para cambiar lo que abarca.",
"clipInspector.source": "Source",
"clipInspector.stabilize": "Estabilizar",
"clipInspector.stabilizeEased": "Ampliado al {0}%. Estabilizar todos los fotogramas requeriría un {1}%, así que los momentos más movidos se estabilizan menos; sube el Zoom máximo para estabilizarlos por completo.",
diff --git a/src/crates/concat/locales/fa.json b/src/crates/concat/locales/fa.json
index 00f1f589..6d367e6d 100644
--- a/src/crates/concat/locales/fa.json
+++ b/src/crates/concat/locales/fa.json
@@ -114,6 +114,7 @@
"clipInspector.smartEraser": "پاک‌کن هوشمند",
"clipInspector.smoothness": "نرمی",
"clipInspector.softness": "نرمی",
+ "clipInspector.soundLayerTreatsTheMix": "لایهٔ صدا تا وقتی اجرا می‌شود روی هر چیزی که شنیده می‌شود اثر می‌گذارد. برای تغییر محدوده‌اش، آن را روی خط زمان کوتاه کنید.",
"clipInspector.source": "منبع",
"clipInspector.stabilize": "لرزش‌گیر",
"clipInspector.stabilizeEased": "تا {0}% بزرگ شد. ثابت کردن همهٔ فریم‌ها به {1}% نیاز دارد، پس لرزان‌ترین لحظه‌ها کمتر ثابت می‌شوند؛ برای ثابت کردن کامل، حداکثر بزرگنمایی را بیشتر کنید.",
diff --git a/src/crates/concat/locales/fr.json b/src/crates/concat/locales/fr.json
index ab21712f..9a033ecf 100644
--- a/src/crates/concat/locales/fr.json
+++ b/src/crates/concat/locales/fr.json
@@ -114,6 +114,7 @@
"clipInspector.smartEraser": "Gomme intelligente",
"clipInspector.smoothness": "Lissage",
"clipInspector.softness": "Douceur",
+ "clipInspector.soundLayerTreatsTheMix": "Un calque sonore traite tout ce qu’on entend tant qu’il dure. Raccourcissez-le sur la timeline pour changer ce qu’il couvre.",
"clipInspector.source": "Source",
"clipInspector.stabilize": "Stabiliser",
"clipInspector.stabilizeEased": "Agrandi à {0} %. Stabiliser chaque image demanderait {1} %, donc les moments les plus agités sont moins stabilisés ; augmentez Zoom max pour les stabiliser entièrement.",
diff --git a/src/crates/concat/locales/he.json b/src/crates/concat/locales/he.json
index d4b5aa96..dc8357fc 100644
--- a/src/crates/concat/locales/he.json
+++ b/src/crates/concat/locales/he.json
@@ -114,6 +114,7 @@
"clipInspector.smartEraser": "מחק חכם",
"clipInspector.smoothness": "חלקות",
"clipInspector.softness": "רכות",
+ "clipInspector.soundLayerTreatsTheMix": "שכבת צליל מעבדת את כל מה שנשמע כל עוד היא פועלת. קצצו אותה בציר הזמן כדי לשנות את מה שהיא מכסה.",
"clipInspector.source": "מקור",
"clipInspector.stabilize": "ייצוב",
"clipInspector.stabilizeEased": "הוגדל ל־{0}%. ייצוב כל פריים היה דורש {1}%, ולכן הרגעים הרועדים ביותר מיוצבים פחות; הגדילו את הזום המרבי כדי לייצב אותם לגמרי.",
diff --git a/src/crates/concat/locales/hi.json b/src/crates/concat/locales/hi.json
index 8411b8b2..369dbae1 100644
--- a/src/crates/concat/locales/hi.json
+++ b/src/crates/concat/locales/hi.json
@@ -114,6 +114,7 @@
"clipInspector.smartEraser": "स्मार्ट इरेज़र",
"clipInspector.smoothness": "स्मूदनेस",
"clipInspector.softness": "कोमलता",
+ "clipInspector.soundLayerTreatsTheMix": "साउंड लेयर जब तक चलती है, सुनाई देने वाली हर चीज़ पर असर करती है। यह कितना ढके, यह बदलने के लिए इसे टाइमलाइन पर ट्रिम करें।",
"clipInspector.source": "स्रोत",
"clipInspector.stabilize": "स्थिर करें",
"clipInspector.stabilizeEased": "{0}% तक ज़ूम किया गया। हर फ़्रेम स्थिर करने के लिए {1}% चाहिए, इसलिए सबसे ज़्यादा हिलते पल कम स्थिर किए गए हैं; उन्हें पूरी तरह स्थिर करने के लिए अधिकतम ज़ूम बढ़ाएँ।",
diff --git a/src/crates/concat/locales/hr.json b/src/crates/concat/locales/hr.json
index e7664f23..b50977da 100644
--- a/src/crates/concat/locales/hr.json
+++ b/src/crates/concat/locales/hr.json
@@ -114,6 +114,7 @@
"clipInspector.smartEraser": "Pametna gumica",
"clipInspector.smoothness": "Glatkoća",
"clipInspector.softness": "Mekoća",
+ "clipInspector.soundLayerTreatsTheMix": "Zvučni sloj obrađuje sve što se čuje dok traje. Skrati ga na vremenskoj crti da promijeniš što pokriva.",
"clipInspector.source": "Izvor",
"clipInspector.stabilize": "Stabiliziraj",
"clipInspector.stabilizeEased": "Uvećano na {0}%. Za stabilizaciju svake sličice trebalo bi {1}%, pa su najtrešniji trenuci manje stabilizirani; povećaj Maks. uvećanje da ih potpuno stabiliziraš.",
diff --git a/src/crates/concat/locales/id.json b/src/crates/concat/locales/id.json
index cd0b9017..0f0c0f08 100644
--- a/src/crates/concat/locales/id.json
+++ b/src/crates/concat/locales/id.json
@@ -114,6 +114,7 @@
"clipInspector.smartEraser": "Penghapus pintar",
"clipInspector.smoothness": "Kehalusan",
"clipInspector.softness": "Kelembutan",
+ "clipInspector.soundLayerTreatsTheMix": "Lapisan suara mengolah semua yang terdengar selama ia berjalan. Pangkas di linimasa untuk mengubah bagian yang dicakupnya.",
"clipInspector.source": "Sumber",
"clipInspector.stabilize": "Stabilkan",
"clipInspector.stabilizeEased": "Diperbesar ke {0}%. Menstabilkan setiap bingkai butuh {1}%, jadi momen yang paling berguncang distabilkan lebih sedikit; naikkan Zoom maks untuk menstabilkannya sepenuhnya.",
diff --git a/src/crates/concat/locales/it.json b/src/crates/concat/locales/it.json
index 6159234d..76696bf5 100644
--- a/src/crates/concat/locales/it.json
+++ b/src/crates/concat/locales/it.json
@@ -114,6 +114,7 @@
"clipInspector.smartEraser": "Gomma intelligente",
"clipInspector.smoothness": "Morbidezza",
"clipInspector.softness": "Morbidezza",
+ "clipInspector.soundLayerTreatsTheMix": "Un livello sonoro tratta tutto ciò che si sente finché dura. Rifilalo sulla timeline per cambiare ciò che copre.",
"clipInspector.source": "Source",
"clipInspector.stabilize": "Stabilizza",
"clipInspector.stabilizeEased": "Ingrandita al {0}%. Stabilizzare ogni fotogramma richiederebbe il {1}%, quindi i momenti più mossi sono stabilizzati meno; aumenta lo Zoom massimo per stabilizzarli del tutto.",
diff --git a/src/crates/concat/locales/ja.json b/src/crates/concat/locales/ja.json
index 3628ed43..768ff5ba 100644
--- a/src/crates/concat/locales/ja.json
+++ b/src/crates/concat/locales/ja.json
@@ -114,6 +114,7 @@
"clipInspector.smartEraser": "スマート消しゴム",
"clipInspector.smoothness": "なめらかさ",
"clipInspector.softness": "やわらかさ",
+ "clipInspector.soundLayerTreatsTheMix": "サウンドレイヤーは、再生されている間に聞こえるすべての音を処理します。範囲を変えるにはタイムラインでトリミングしてください。",
"clipInspector.source": "ソース",
"clipInspector.stabilize": "手ぶれ補正",
"clipInspector.stabilizeEased": "{0}% に拡大しています。すべてのフレームを安定させるには {1}% が必要なため、最も揺れる部分は補正を弱めています。完全に補正するには最大ズームを上げてください。",
diff --git a/src/crates/concat/locales/ko.json b/src/crates/concat/locales/ko.json
index 6394f078..0b38b884 100644
--- a/src/crates/concat/locales/ko.json
+++ b/src/crates/concat/locales/ko.json
@@ -114,6 +114,7 @@
"clipInspector.smartEraser": "스마트 지우개",
"clipInspector.smoothness": "부드러움",
"clipInspector.softness": "부드러움",
+ "clipInspector.soundLayerTreatsTheMix": "사운드 레이어는 재생되는 동안 들리는 모든 소리를 처리합니다. 적용 범위를 바꾸려면 타임라인에서 잘라 주세요.",
"clipInspector.source": "Source",
"clipInspector.stabilize": "흔들림 보정",
"clipInspector.stabilizeEased": "{0}%로 확대했습니다. 모든 프레임을 안정시키려면 {1}%가 필요해 가장 많이 흔들리는 순간은 덜 보정됩니다. 완전히 보정하려면 최대 확대를 높이세요.",
diff --git a/src/crates/concat/locales/nl.json b/src/crates/concat/locales/nl.json
index 06c99142..122d74b1 100644
--- a/src/crates/concat/locales/nl.json
+++ b/src/crates/concat/locales/nl.json
@@ -114,6 +114,7 @@
"clipInspector.smartEraser": "Slimme gum",
"clipInspector.smoothness": "Vloeiendheid",
"clipInspector.softness": "Zachtheid",
+ "clipInspector.soundLayerTreatsTheMix": "Een geluidslaag bewerkt alles wat je hoort zolang hij loopt. Trim hem op de tijdlijn om te veranderen wat hij beslaat.",
"clipInspector.source": "Bron",
"clipInspector.stabilize": "Stabiliseren",
"clipInspector.stabilizeEased": "Vergroot tot {0}%. Elk beeld stilhouden zou {1}% vragen, dus de meest schokkerige momenten worden minder gestabiliseerd; verhoog Max. zoom om ze volledig te stabiliseren.",
diff --git a/src/crates/concat/locales/pl.json b/src/crates/concat/locales/pl.json
index 2601475e..0b6753a8 100644
--- a/src/crates/concat/locales/pl.json
+++ b/src/crates/concat/locales/pl.json
@@ -114,6 +114,7 @@
"clipInspector.smartEraser": "Inteligentna gumka",
"clipInspector.smoothness": "Płynność",
"clipInspector.softness": "Miękkość",
+ "clipInspector.soundLayerTreatsTheMix": "Warstwa dźwięku przetwarza wszystko, co słychać, dopóki trwa. Przytnij ją na osi czasu, aby zmienić, co obejmuje.",
"clipInspector.source": "Źródło",
"clipInspector.stabilize": "Stabilizuj",
"clipInspector.stabilizeEased": "Powiększono do {0}%. Ustabilizowanie każdej klatki wymagałoby {1}%, więc najbardziej roztrzęsione momenty są stabilizowane słabiej; zwiększ Maks. powiększenie, aby ustabilizować je w pełni.",
diff --git a/src/crates/concat/locales/pt-BR.json b/src/crates/concat/locales/pt-BR.json
index 137a6690..ffc5e1a5 100644
--- a/src/crates/concat/locales/pt-BR.json
+++ b/src/crates/concat/locales/pt-BR.json
@@ -114,6 +114,7 @@
"clipInspector.smartEraser": "Borracha inteligente",
"clipInspector.smoothness": "Suavidade",
"clipInspector.softness": "Suavidade",
+ "clipInspector.soundLayerTreatsTheMix": "Uma camada de som trata tudo o que se ouve enquanto dura. Corte-a na linha do tempo para mudar o que ela cobre.",
"clipInspector.source": "Origem",
"clipInspector.stabilize": "Estabilizar",
"clipInspector.stabilizeEased": "Ampliado para {0}%. Estabilizar todos os quadros exigiria {1}%, então os momentos mais tremidos são menos estabilizados; aumente o Zoom máximo para estabilizá-los por completo.",
diff --git a/src/crates/concat/locales/ru.json b/src/crates/concat/locales/ru.json
index 30aaaf56..7094ddb3 100644
--- a/src/crates/concat/locales/ru.json
+++ b/src/crates/concat/locales/ru.json
@@ -114,6 +114,7 @@
"clipInspector.smartEraser": "Умный ластик",
"clipInspector.smoothness": "Плавность",
"clipInspector.softness": "Мягкость",
+ "clipInspector.soundLayerTreatsTheMix": "Звуковой слой обрабатывает всё, что слышно, пока он идёт. Обрежьте его на таймлайне, чтобы изменить, что он охватывает.",
"clipInspector.source": "Источник",
"clipInspector.stabilize": "Стабилизация",
"clipInspector.stabilizeEased": "Увеличено до {0}%. Чтобы стабилизировать каждый кадр, нужно {1}%, поэтому самые тряские моменты стабилизированы слабее; увеличьте Макс. увеличение, чтобы стабилизировать их полностью.",
diff --git a/src/crates/concat/locales/th.json b/src/crates/concat/locales/th.json
index 2088eddb..39b53616 100644
--- a/src/crates/concat/locales/th.json
+++ b/src/crates/concat/locales/th.json
@@ -114,6 +114,7 @@
"clipInspector.smartEraser": "ยางลบอัจฉริยะ",
"clipInspector.smoothness": "ความนุ่มนวล",
"clipInspector.softness": "ความนุ่ม",
+ "clipInspector.soundLayerTreatsTheMix": "เลเยอร์เสียงจะปรับทุกเสียงที่ได้ยินตลอดช่วงที่มันเล่น ตัดแต่งบนไทม์ไลน์เพื่อเปลี่ยนช่วงที่มันครอบคลุม",
"clipInspector.source": "แหล่งที่มา",
"clipInspector.stabilize": "กันสั่น",
"clipInspector.stabilizeEased": "ซูมเป็น {0}% การทำให้ทุกเฟรมนิ่งต้องใช้ {1}% ช่วงที่สั่นที่สุดจึงถูกกันสั่นน้อยลง เพิ่มซูมสูงสุดเพื่อกันสั่นได้เต็มที่",
diff --git a/src/crates/concat/locales/tr.json b/src/crates/concat/locales/tr.json
index 5d5e7c75..d085c970 100644
--- a/src/crates/concat/locales/tr.json
+++ b/src/crates/concat/locales/tr.json
@@ -114,6 +114,7 @@
"clipInspector.smartEraser": "Akıllı silgi",
"clipInspector.smoothness": "Yumuşaklık",
"clipInspector.softness": "Yumuşaklık",
+ "clipInspector.soundLayerTreatsTheMix": "Ses katmanı sürdüğü boyunca duyulan her şeyi işler. Kapsadığı yeri değiştirmek için zaman çizelgesinde kırpın.",
"clipInspector.source": "Source",
"clipInspector.stabilize": "Sabitle",
"clipInspector.stabilizeEased": "%{0} yakınlaştırıldı. Her kareyi sabitlemek %{1} gerektirirdi, bu yüzden en sarsıntılı anlar daha az sabitlenir; tamamen sabitlemek için En fazla yakınlaştırmayı artırın.",
diff --git a/src/crates/concat/locales/uk.json b/src/crates/concat/locales/uk.json
index 96490187..81012e12 100644
--- a/src/crates/concat/locales/uk.json
+++ b/src/crates/concat/locales/uk.json
@@ -114,6 +114,7 @@
"clipInspector.smartEraser": "Розумна гумка",
"clipInspector.smoothness": "Плавність",
"clipInspector.softness": "М'якість",
+ "clipInspector.soundLayerTreatsTheMix": "Звуковий шар обробляє все, що чути, поки він триває. Обріжте його на таймлайні, щоб змінити, що він охоплює.",
"clipInspector.source": "Джерело",
"clipInspector.stabilize": "Стабілізація",
"clipInspector.stabilizeEased": "Збільшено до {0}%. Щоб стабілізувати кожен кадр, потрібно {1}%, тож найтрясучіші моменти стабілізовано слабше; збільште Макс. збільшення, щоб стабілізувати їх повністю.",
diff --git a/src/crates/concat/locales/ur.json b/src/crates/concat/locales/ur.json
index 2d01bcba..a016083a 100644
--- a/src/crates/concat/locales/ur.json
+++ b/src/crates/concat/locales/ur.json
@@ -114,6 +114,7 @@
"clipInspector.smartEraser": "اسمارٹ ربڑ",
"clipInspector.smoothness": "نرمی",
"clipInspector.softness": "نرمی",
+ "clipInspector.soundLayerTreatsTheMix": "ساؤنڈ لیئر جب تک چلتی ہے، سنائی دینے والی ہر چیز پر اثر کرتی ہے۔ یہ کتنا حصہ ڈھانپے، یہ بدلنے کے لیے اسے ٹائم لائن پر ٹرم کریں۔",
"clipInspector.source": "ماخذ",
"clipInspector.stabilize": "مستحکم کریں",
"clipInspector.stabilizeEased": "{0}% تک زوم کیا گیا۔ ہر فریم کو مستحکم کرنے کے لیے {1}% درکار ہوتا، اس لیے سب سے زیادہ لرزتے لمحے کم مستحکم کیے گئے ہیں؛ انہیں پوری طرح مستحکم کرنے کے لیے زیادہ سے زیادہ زوم بڑھائیں۔",
diff --git a/src/crates/concat/locales/vi.json b/src/crates/concat/locales/vi.json
index 7b191195..01eea2bf 100644
--- a/src/crates/concat/locales/vi.json
+++ b/src/crates/concat/locales/vi.json
@@ -114,6 +114,7 @@
"clipInspector.smartEraser": "Cục tẩy thông minh",
"clipInspector.smoothness": "Độ mượt",
"clipInspector.softness": "Độ mềm",
+ "clipInspector.soundLayerTreatsTheMix": "Lớp âm thanh xử lý mọi thứ nghe được trong suốt thời gian nó chạy. Cắt nó trên dòng thời gian để thay đổi phần nó bao phủ.",
"clipInspector.source": "Nguồn",
"clipInspector.stabilize": "Chống rung",
"clipInspector.stabilizeEased": "Đã phóng to {0}%. Để giữ yên mọi khung hình cần {1}%, nên những lúc rung nhất được chống rung ít hơn; tăng Thu phóng tối đa để chống rung hoàn toàn.",
diff --git a/src/crates/concat/locales/zh-Hans.json b/src/crates/concat/locales/zh-Hans.json
index efdea998..9415ff2d 100644
--- a/src/crates/concat/locales/zh-Hans.json
+++ b/src/crates/concat/locales/zh-Hans.json
@@ -114,6 +114,7 @@
"clipInspector.smartEraser": "智能橡皮擦",
"clipInspector.smoothness": "平滑度",
"clipInspector.softness": "柔和度",
+ "clipInspector.soundLayerTreatsTheMix": "声音图层在播放期间会处理听到的所有声音。在时间线上修剪它即可改变覆盖范围。",
"clipInspector.source": "来源",
"clipInspector.stabilize": "防抖",
"clipInspector.stabilizeEased": "已放大到 {0}%。要让每一帧都稳定需要 {1}%,因此抖动最厉害的时刻防抖较弱;调高最大缩放即可完全稳定。",
diff --git a/src/crates/concat/locales/zh-TW.json b/src/crates/concat/locales/zh-TW.json
index d58bb9c9..cd415914 100644
--- a/src/crates/concat/locales/zh-TW.json
+++ b/src/crates/concat/locales/zh-TW.json
@@ -114,6 +114,7 @@
"clipInspector.smartEraser": "智慧橡皮擦",
"clipInspector.smoothness": "平滑度",
"clipInspector.softness": "柔和度",
+ "clipInspector.soundLayerTreatsTheMix": "聲音圖層在播放期間會處理聽到的所有聲音。在時間軸上修剪它即可改變涵蓋範圍。",
"clipInspector.source": "來源",
"clipInspector.stabilize": "防手震",
"clipInspector.stabilizeEased": "已放大到 {0}%。要讓每一格都穩定需要 {1}%,因此晃動最劇烈的時刻防手震較弱;調高最大縮放即可完全穩定。",
diff --git a/src/crates/concat/src/chips.rs b/src/crates/concat/src/chips.rs
index 35ab480b..b56fbe42 100644
--- a/src/crates/concat/src/chips.rs
+++ b/src/crates/concat/src/chips.rs
@@ -27,7 +27,9 @@ pub fn chip_glyph(kind: ClipKind) -> &'static str {
// lucide/type
ClipKind::Text => "M12 4v16 M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2 M9 20h6",
// lucide/audio-lines
- ClipKind::Filter => "M2 10v3 M6 6v11 M10 3v18 M14 8v7 M18 5v13 M22 10v3",
+ ClipKind::Filter | ClipKind::SoundLayer => {
+ "M2 10v3 M6 6v11 M10 3v18 M14 8v7 M18 5v13 M22 10v3"
+ }
// lucide/shapes
ClipKind::Shape => {
"M8.3 10a.7.7 0 0 1-.626-1.079L11.4 3a.7.7 0 0 1 1.198-.043L16.3 8.9a.7.7 0 0 1-.572 1.1Z \
diff --git a/src/crates/concat/src/lib.rs b/src/crates/concat/src/lib.rs
index 84ab0a0d..5dc9c591 100644
--- a/src/crates/concat/src/lib.rs
+++ b/src/crates/concat/src/lib.rs
@@ -2381,6 +2381,10 @@ fn start(project: Option<std::path::PathBuf>, smoke: bool) -> Result<(), slint::
ClipKind::Text => (theme.get_kind_text(), theme.get_kind_text_well()),
ClipKind::Filter => (theme.get_kind_filter(), theme.get_kind_filter_well()),
ClipKind::Shape => (theme.get_kind_shape(), theme.get_kind_shape_well()),
+ ClipKind::SoundLayer => (
+ theme.get_kind_sound_layer(),
+ theme.get_kind_sound_layer_well(),
+ ),
};
let wave = studio
.peaks
diff --git a/src/crates/concat/src/studio.rs b/src/crates/concat/src/studio.rs
index a30611e0..4069089a 100644
--- a/src/crates/concat/src/studio.rs
+++ b/src/crates/concat/src/studio.rs
@@ -1167,6 +1167,7 @@ fn kind_of(clip: &Clip) -> ClipKind {
model::ClipKind::Image => ClipKind::Image,
model::ClipKind::Text => ClipKind::Text,
model::ClipKind::Layer => ClipKind::Filter,
+ model::ClipKind::SoundLayer => ClipKind::SoundLayer,
model::ClipKind::Shape => ClipKind::Shape,
}
}
@@ -2634,9 +2635,10 @@ impl Studio {
// A title is its name strip alone; a layer has no
// picture at all; a shape's name says what it is.
// None needs a body's height.
- model::ClipKind::Text | model::ClipKind::Layer | model::ClipKind::Shape => {
- LANE_SMALL
- }
+ model::ClipKind::Text
+ | model::ClipKind::Layer
+ | model::ClipKind::SoundLayer
+ | model::ClipKind::Shape => LANE_SMALL,
})
.fold(0.0_f32, f32::max);
if tallest > 0.0 { tallest } else { LANE_MEDIUM }
@@ -3917,6 +3919,17 @@ impl Studio {
duration: LAYER_DURATION,
row: 0,
}),
+ // A sound effect dragged from the Effects page's sound shelf:
+ // a sound layer over a span, treating everything heard there.
+ // The package id rides in `media`, as a filter's does.
+ "audio-filter" => Some(DropPlan {
+ kind: ClipKind::SoundLayer,
+ label: label.to_owned(),
+ media: id.to_owned(),
+ start: 0.0,
+ duration: LAYER_DURATION,
+ row: 0,
+ }),
_ => None,
}
}
@@ -3982,13 +3995,14 @@ impl Studio {
&plan.media,
&plan.label,
)
- } else if plan.kind == ClipKind::Filter {
+ } else if matches!(plan.kind, ClipKind::Filter | ClipKind::SoundLayer) {
self.apply(Command::AddLayerClip {
track_id: Some(track_id),
start: f64::from(plan.start),
duration: Some(f64::from(plan.duration)),
effect_id: plan.media.clone(),
name: plan.label.clone(),
+ sound: plan.kind == ClipKind::SoundLayer,
})
} else if let Some(media_ids) = self.dragged_selection(&plan.media) {
// A card dragged out of a selection in the bin brings the whole
@@ -4034,13 +4048,14 @@ impl Studio {
&plan.media,
&plan.label,
)
- } else if plan.kind == ClipKind::Filter {
+ } else if matches!(plan.kind, ClipKind::Filter | ClipKind::SoundLayer) {
self.apply(Command::AddLayerClip {
track_id: None,
start,
duration: Some(f64::from(plan.duration)),
effect_id: plan.media.clone(),
name: plan.label.clone(),
+ sound: plan.kind == ClipKind::SoundLayer,
})
} else {
self.apply(Command::AddClipAtFirstFree {
@@ -8338,6 +8353,29 @@ impl Studio {
duration: Some(source.duration),
name: source.name.clone(),
}),
+ // A layer has no file to lay: it is laid as a layer, and the
+ // match then gives it the source's whole chain. It went down
+ // the file's path and was refused, so a layer could be neither
+ // copied nor duplicated.
+ model::ClipKind::Layer | model::ClipKind::SoundLayer => {
+ let sound = source.kind == model::ClipKind::SoundLayer;
+ let chain = if sound {
+ &source.filters
+ } else {
+ &source.video_effects
+ };
+ Some(Command::AddLayerClip {
+ track_id: Some(track_id.to_owned()),
+ start,
+ duration: Some(source.duration),
+ effect_id: chain
+ .first()
+ .map(|link| link.id.clone())
+ .unwrap_or_default(),
+ name: source.name.clone(),
+ sound,
+ })
+ }
_ => None,
};
if let Some(add) = drawn {
@@ -12581,45 +12619,10 @@ fn moved_any<'a>(moves: &[ClipMove], before: impl Fn(&str) -> Option<&'a Clip>)
})
}
-/// The clips a flattened edit makes audible, as playback takes them:
-/// through the exporter's own cut into pieces, so a curve or a reverse
-/// sounds in the window as it will in the file.
+/// The clips a flattened edit makes audible, as playback takes them; see
+/// `concat_host::playback::audible`.
pub(crate) fn audio_specs(clips: &[concat_export::ExportClip]) -> Vec<ClipSpec> {
- clips
- .iter()
- .filter(|clip| {
- !clip.muted
- && (clip.kind == concat_export::ClipKind::Audio
- || (clip.kind == concat_export::ClipKind::Video
- && clip.has_audio.unwrap_or(true)))
- })
- // Through the exporter's own cut into pieces, so a curve or a
- // reverse sounds in the window as it will in the file.
- .flat_map(concat_export::audio_pieces)
- .map(|piece| ClipSpec {
- path: piece.path.to_string_lossy().into_owned(),
- audio_stream: piece.stream.map(|index| index as u32),
- start: piece.start,
- duration: piece.duration,
- source_start: piece.source_start,
- volume: piece.volume as f32,
- volume_curve: piece
- .volume_curve
- .keys()
- .iter()
- .map(|key| concat_host::playback::GainKey {
- at: key.at,
- gain: key.value,
- ease: [key.ease.x1, key.ease.y1, key.ease.x2, key.ease.y2],
- })
- .collect(),
- fade_in: piece.fade_in,
- fade_out: piece.fade_out,
- speed: piece.speed,
- preserve_pitch: piece.preserve_pitch,
- chain: piece.filter_chain,
- })
- .collect()
+ concat_host::playback::audible(clips)
}
#[cfg(test)]
diff --git a/src/crates/concat/ui/inspector/clip-inspector.slint b/src/crates/concat/ui/inspector/clip-inspector.slint
index 06a3ec9b..f6d7dcda 100644
--- a/src/crates/concat/ui/inspector/clip-inspector.slint
+++ b/src/crates/concat/ui/inspector/clip-inspector.slint
@@ -2797,6 +2797,9 @@ export component AdjustPanel inherits VerticalLayout {
// beats a second that means it only on this one.
export component FilterPanel inherits VerticalLayout {
in property <SelectedClipData> selected;
+ /// What the help says the layer does: a picture layer's or a sound
+ /// layer's, the panel being the same for both.
+ in property <string> help: I18n.t("clipInspector.layerTreatsEverythingUnder");
callback set(field: ClipField, value: float);
callback commit();
@@ -2826,7 +2829,7 @@ export component FilterPanel inherits VerticalLayout {
collapsible: true;
summary: InspectorFmt.format(ParamFormat.fraction, root.strength);
HelpButton {
- text: I18n.t("clipInspector.layerTreatsEverythingUnder");
+ text: root.help;
}
}
diff --git a/src/crates/concat/ui/theme/dark.slint b/src/crates/concat/ui/theme/dark.slint
index 54c55e9d..11c7349a 100644
--- a/src/crates/concat/ui/theme/dark.slint
+++ b/src/crates/concat/ui/theme/dark.slint
@@ -194,6 +194,11 @@ export global Dark {
// and the colour the consumer editors already give their shapes.
out property <color> kind-shape: #d4a24b;
out property <color> kind-shape-well: #3a2d14;
+ // A sound layer wears teal: a filter's kin, as cool as one, and
+ // between the sound's green and the picture's blue, for a treatment
+ // laid over what is heard rather than one more thing heard.
+ out property <color> kind-sound-layer: #2bb3a8;
+ out property <color> kind-sound-layer-well: #10302d;
// timeline
//
diff --git a/src/crates/concat/ui/theme/light.slint b/src/crates/concat/ui/theme/light.slint
index 99a1bbab..1408a415 100644
--- a/src/crates/concat/ui/theme/light.slint
+++ b/src/crates/concat/ui/theme/light.slint
@@ -153,6 +153,8 @@ export global Light {
out property <color> kind-filter-well: #e9e6fd;
out property <color> kind-shape: #b8862e;
out property <color> kind-shape-well: #fbefd6;
+ out property <color> kind-sound-layer: #13857e;
+ out property <color> kind-sound-layer-well: #ddf3f1;
// timeline
//
diff --git a/src/crates/concat/ui/theme/theme.slint b/src/crates/concat/ui/theme/theme.slint
index 29ff68db..01c6e819 100644
--- a/src/crates/concat/ui/theme/theme.slint
+++ b/src/crates/concat/ui/theme/theme.slint
@@ -236,6 +236,8 @@ export global Theme {
out property <color> kind-filter-well: dark ? Dark.kind-filter-well : Light.kind-filter-well;
out property <color> kind-shape: dark ? Dark.kind-shape : Light.kind-shape;
out property <color> kind-shape-well: dark ? Dark.kind-shape-well : Light.kind-shape-well;
+ out property <color> kind-sound-layer: dark ? Dark.kind-sound-layer : Light.kind-sound-layer;
+ out property <color> kind-sound-layer-well: dark ? Dark.kind-sound-layer-well : Light.kind-sound-layer-well;
// timeline
out property <color> lane: dark ? Dark.lane : Light.lane;
diff --git a/src/crates/concat/ui/timeline/lanes.slint b/src/crates/concat/ui/timeline/lanes.slint
index 22b01d85..9a3bbf30 100644
--- a/src/crates/concat/ui/timeline/lanes.slint
+++ b/src/crates/concat/ui/timeline/lanes.slint
@@ -34,6 +34,7 @@ global Paint {
: kind == ClipKind.text ? Theme.kind-text
: kind == ClipKind.filter ? Theme.kind-filter
: kind == ClipKind.shape ? Theme.kind-shape
+ : kind == ClipKind.sound-layer ? Theme.kind-sound-layer
: Theme.kind-video;
}
public pure function well(kind: ClipKind) -> color {
@@ -42,6 +43,7 @@ global Paint {
: kind == ClipKind.text ? Theme.kind-text-well
: kind == ClipKind.filter ? Theme.kind-filter-well
: kind == ClipKind.shape ? Theme.kind-shape-well
+ : kind == ClipKind.sound-layer ? Theme.kind-sound-layer-well
: Theme.kind-video-well;
}
public pure function badge(kind: ClipKind) -> Glyph {
@@ -50,6 +52,7 @@ global Paint {
: kind == ClipKind.text ? Glyph.text-mark
: kind == ClipKind.filter ? Glyph.filter
: kind == ClipKind.shape ? Glyph.shapes
+ : kind == ClipKind.sound-layer ? Glyph.waveform
: Glyph.film;
}
}
@@ -175,9 +178,12 @@ component Clip inherits Rectangle {
/// the same words a second time in a taller clip. A filter layer is all
/// strip too - one bar, the look's mark before its name - since it has
/// no picture and no sound to show under a header. A shape is all strip
- /// for the title's reason: its name says what it is.
+ /// for the title's reason: its name says what it is. A sound layer is
+ /// a filter layer's bar, for the same reason: no sound of its own to
+ /// draw a wave of.
property <bool> all-strip: root.item.kind == ClipKind.text
|| root.item.kind == ClipKind.filter
+ || root.item.kind == ClipKind.sound-layer
|| root.item.kind == ClipKind.shape;
property <length> header-h: root.all-strip ? root.height : 17px;
/// An all-strip clip wears its kind's mark before its name, the way a
@@ -464,8 +470,9 @@ component Clip inherits Rectangle {
overflow: elide;
}
- // A filter layer's ramps run over its whole bar; see Ramps.
- if root.item.kind == ClipKind.filter: Ramps {
+ // A filter layer's ramps run over its whole bar, and a sound
+ // layer's; see Ramps.
+ if root.item.kind == ClipKind.filter || root.item.kind == ClipKind.sound-layer: Ramps {
x: 0;
y: 0;
width: parent.width;
diff --git a/src/crates/concat/ui/timeline/model.slint b/src/crates/concat/ui/timeline/model.slint
index be2f35e4..11950c10 100644
--- a/src/crates/concat/ui/timeline/model.slint
+++ b/src/crates/concat/ui/timeline/model.slint
@@ -13,8 +13,10 @@
/// and a filter has no file either — it is a preset dragged from the library's
/// Filters page that covers a span of time and treats whatever plays under it,
/// the way a filter bar does in the consumer editors. A shape is a figure
-/// from the Stickers page, drawn over the picture like a title is.
-export enum ClipKind { video, audio, image, text, filter, shape }
+/// from the Stickers page, drawn over the picture like a title is. A sound
+/// layer is a filter's sibling for the ear: an audio effect dragged from
+/// the Effects page's sound shelf, treating everything heard under its span.
+export enum ClipKind { video, audio, image, text, filter, shape, sound-layer }
/// What a press on a clip means. One tool since the razor went - a cut
/// is made at the playhead, by B or the tray - and the type stays for the
diff --git a/src/crates/concat/ui/workspace/config-pane.slint b/src/crates/concat/ui/workspace/config-pane.slint
index 613a918e..7128904d 100644
--- a/src/crates/concat/ui/workspace/config-pane.slint
+++ b/src/crates/concat/ui/workspace/config-pane.slint
@@ -244,6 +244,10 @@ export component ConfigPane inherits Rectangle {
/// panel it grades everything beneath it with, and its chain - are the
/// tab's sections, so an adjustment layer is graded the way a clip is.
property <bool> is-layer: root.selected.kind == ClipKind.filter;
+ /// A sound layer gets one tab, Audio, for the filter layer's reason:
+ /// its strength and ramps, then its chain and the sound library -
+ /// the Audio effects page a sound clip has, over everything heard.
+ property <bool> is-sound-layer: root.selected.kind == ClipKind.sound-layer;
/// Effects are laid on the timeline as layers now, so a clip's own
/// chain is not something to go looking for: its tab shows only on a
/// clip that already carries one - from an older project, a template,
@@ -252,6 +256,7 @@ export component ConfigPane inherits Rectangle {
property <[string]> tabs: root.selected.batch-volume ? ["Audio"]
: root.is-text ? (root.has-chain ? ["Text", "Effects"] : ["Text"])
: root.is-layer ? ["Filter"]
+ : root.is-sound-layer ? ["Audio"]
: root.is-shape ? ["Video"]
: root.is-image ? (root.has-chain ? ["Video", "Effects"] : ["Video"])
: root.is-audio ? ["Audio"]
@@ -262,6 +267,7 @@ export component ConfigPane inherits Rectangle {
: root.is-text ? (root.has-chain ? [I18n.t("common.text"), I18n.t("common.effects")]
: [I18n.t("common.text")])
: root.is-layer ? [I18n.t("configPane.filter")]
+ : root.is-sound-layer ? [I18n.t("common.audio")]
: root.is-shape ? [I18n.t("configPane.vectorImage")]
: root.is-image ? (root.has-chain ? [I18n.t("common.video"), I18n.t("common.effects")]
: [I18n.t("common.video")])
@@ -304,7 +310,9 @@ export component ConfigPane inherits Rectangle {
// and the Effects tab's "Effects", since `showing` picks the panel
// by this name alone.
: root.heading == "Audio"
- ? (root.selected.batch-volume ? ["Sound"] : ["Sound", "AudioEffects"])
+ ? (root.selected.batch-volume ? ["Sound"]
+ : root.is-sound-layer ? ["Layer", "AudioEffects"]
+ : ["Sound", "AudioEffects"])
: root.heading == "Effects" ? ["Effects"]
: root.heading == "Text" ? ["Text"]
: ["Layer", "Adjust", "Effects"];
@@ -314,7 +322,9 @@ export component ConfigPane inherits Rectangle {
property <[Glyph]> section-icons: root.heading == "Video"
? (root.is-shape ? [Glyph.move] : [Glyph.move, Glyph.wand, Glyph.sliders])
: root.heading == "Audio"
- ? (root.selected.batch-volume ? [Glyph.volume] : [Glyph.volume, Glyph.waveform])
+ ? (root.selected.batch-volume ? [Glyph.volume]
+ : root.is-sound-layer ? [Glyph.filter, Glyph.waveform]
+ : [Glyph.volume, Glyph.waveform])
: root.heading == "Effects" ? [Glyph.sparkle]
: root.heading == "Text" ? [Glyph.text-mark]
: [Glyph.filter, Glyph.sliders, Glyph.sparkle];
@@ -324,6 +334,7 @@ export component ConfigPane inherits Rectangle {
: [I18n.t("configPane.basic"), I18n.t("common.enhance"), I18n.t("common.adjust")])
: root.heading == "Audio"
? (root.selected.batch-volume ? [I18n.t("configPane.basic")]
+ : root.is-sound-layer ? [I18n.t("common.layer"), I18n.t("configPane.audioEffects")]
: [I18n.t("configPane.basic"), I18n.t("configPane.audioEffects")])
: root.heading == "Effects" ? [I18n.t("common.effects")]
: root.heading == "Text" ? [I18n.t("common.text")]
@@ -370,7 +381,7 @@ export component ConfigPane inherits Rectangle {
return;
}
if (root.jump-tab == "Video") { root.tab = 0; }
- else if (root.jump-tab == "Audio") { root.tab = root.is-audio ? 0 : 1; }
+ else if (root.jump-tab == "Audio") { root.tab = root.is-audio || root.is-sound-layer ? 0 : 1; }
else if (root.jump-tab == "Effects") { root.tab = root.tabs.length - 1; }
// Enhance sits second in the Video tab for a video and a still
// alike, and Audio effects second in the Audio tab.
@@ -725,6 +736,8 @@ export component ConfigPane inherits Rectangle {
if root.showing == "Layer": FilterPanel {
selected: root.selected;
+ help: root.is-sound-layer ? I18n.t("clipInspector.soundLayerTreatsTheMix")
+ : I18n.t("clipInspector.layerTreatsEverythingUnder");
set(field, value) => { root.clip-set(field, value); }
commit => { root.clip-commit(); }
}
diff --git a/src/crates/concat/ui/workspace/media-pane.slint b/src/crates/concat/ui/workspace/media-pane.slint
index ab19438b..f537b06f 100644
--- a/src/crates/concat/ui/workspace/media-pane.slint
+++ b/src/crates/concat/ui/workspace/media-pane.slint
@@ -2755,7 +2755,11 @@ export component MediaPane inherits Rectangle {
auditions: !root.audio-shelf;
auditioning: root.audio-shelf ? "" : root.audition;
auditioned(id) => { root.audition-filter(id); }
- payload-kind: root.audio-shelf ? "" : "filter";
+ // A sound effect dragged onto the lanes is a sound
+ // layer: it treats everything heard under it for as
+ // long as it runs. A click still puts it on the
+ // selected clip.
+ payload-kind: root.audio-shelf ? "audio-filter" : "filter";
applied(id, label) => {
if (root.audio-shelf) {
root.apply-audio(id);