Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/cli/src/selftest/playback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,7 @@ mod fixture {
timescale: 1.0,
name: None,
speed_audio_mode: None,
audio_muted: false,
}],
transitions: Vec::new(),
zoom_segments: Vec::new(),
Expand Down
5 changes: 5 additions & 0 deletions apps/desktop-gpui/src/editor_clips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3192,6 +3192,7 @@ fn full_timeline_for_segments(
end: duration,
name: None,
speed_audio_mode: None,
audio_muted: false,
})
})
.collect()
Expand Down Expand Up @@ -3768,6 +3769,7 @@ fn full_timeline_for_source_segments(
end: duration,
name: None,
speed_audio_mode: None,
audio_muted: false,
})
})
.collect()
Expand Down Expand Up @@ -3857,6 +3859,7 @@ fn source_timeline_segments_for_import(
end,
name: None,
speed_audio_mode: None,
audio_muted: segment.audio_muted,
});
}

Expand Down Expand Up @@ -4087,6 +4090,7 @@ pub(crate) fn append_cap_project_to_editor(
end: source_segment.end,
name: None,
speed_audio_mode: source_segment.speed_audio_mode,
audio_muted: source_segment.audio_muted,
});
}
}
Expand Down Expand Up @@ -4116,6 +4120,7 @@ mod tests {
end,
name: None,
speed_audio_mode: None,
audio_muted: false,
}
}

Expand Down
26 changes: 10 additions & 16 deletions apps/desktop-gpui/src/editor_edits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,7 @@ pub fn ensure_timeline(project: &mut ProjectConfiguration, clip_display_duration
end: *duration,
name: None,
speed_audio_mode: None,
audio_muted: false,
})
.collect(),
transitions: Vec::new(),
Expand Down Expand Up @@ -1847,28 +1848,22 @@ pub fn set_clip_segment_timescale(
}

pub fn clip_is_muted(segment: &TimelineSegment) -> bool {
if (segment.timescale - 1.0).abs() < f64::EPSILON {
let speed_mode_muted = if (segment.timescale - 1.0).abs() < f64::EPSILON {
segment.speed_audio_mode == Some(ClipSpeedAudioMode::Mute)
} else {
segment.speed_audio_mode.unwrap_or(ClipSpeedAudioMode::Mute) == ClipSpeedAudioMode::Mute
}
};
segment.audio_muted || speed_mode_muted
}

pub fn set_clip_muted(timeline: &mut TimelineConfiguration, index: usize, muted: bool) -> bool {
let Some(segment) = timeline.segments.get_mut(index) else {
return false;
};
let next = if muted {
Some(ClipSpeedAudioMode::Mute)
} else if (segment.timescale - 1.0).abs() < f64::EPSILON {
None
} else {
Some(ClipSpeedAudioMode::MaintainPitch)
};
if segment.speed_audio_mode == next {
if segment.audio_muted == muted {
return false;
}
segment.speed_audio_mode = next;
segment.audio_muted = muted;
true
}

Expand Down Expand Up @@ -2775,18 +2770,17 @@ mod tests {
}

#[test]
fn muting_a_1x_clip_sets_speed_audio_mode() {
fn muting_a_1x_clip_sets_audio_muted() {
let mut project = zoom_fixture();
let timeline = project.timeline.as_mut().unwrap();
assert!(!clip_is_muted(&timeline.segments[0]));
assert!(set_clip_muted(timeline, 0, true));
assert!(clip_is_muted(&timeline.segments[0]));
assert_eq!(
timeline.segments[0].speed_audio_mode,
Some(ClipSpeedAudioMode::Mute)
);
assert!(timeline.segments[0].audio_muted);
assert_eq!(timeline.segments[0].speed_audio_mode, None);
assert!(set_clip_muted(timeline, 0, false));
assert!(!clip_is_muted(&timeline.segments[0]));
assert!(!timeline.segments[0].audio_muted);
assert_eq!(timeline.segments[0].speed_audio_mode, None);
}

Expand Down
91 changes: 50 additions & 41 deletions apps/desktop-gpui/src/editor_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ pub fn preflight(path: &std::path::Path) -> Result<ProjectSummary, String> {
end: segment.duration(),
name: None,
speed_audio_mode: None,
audio_muted: false,
})
.collect(),
// `TimelineConfiguration` has no `Default`, so the eight other
Expand Down Expand Up @@ -6115,7 +6116,7 @@ impl EditorWindow {
.as_ref()
.and_then(|timeline| timeline.segments.get(menu.index))?;
let timescale = segment.timescale;
let muted = edits::clip_is_muted(segment);
let muted = segment.audio_muted;
let audio_mode = segment.speed_audio_mode.unwrap_or_default();
let speeds = [0.25, 0.5, 1.0, 1.5, 2.0, 4.0, 8.0];
let audio_modes = [
Expand Down Expand Up @@ -6203,7 +6204,52 @@ impl EditorWindow {
}))
})),
)
.child(if normal_speed {
.when(!normal_speed, |popover| {
popover.child(
div()
.flex()
.flex_row()
.items_center()
.gap(px(4.))
.rounded(px(8.))
.bg(Hsla::from(theme.gray_2))
.p(px(4.))
.children(audio_modes.into_iter().map(|(mode, label)| {
let selected = audio_mode == mode;
div()
.id(SharedString::from(format!(
"clip-speed-audio-{label}"
)))
.rounded(px(6.))
.px(px(8.))
.py(px(4.))
.text_size(px(12.))
.cursor_pointer()
.bg(if selected {
Hsla::from(theme.gray_4)
} else {
gpui::transparent_black()
})
.text_color(Hsla::from(if selected {
theme.gray_12
} else {
theme.gray_10
}))
.hover(|this| {
this.text_color(Hsla::from(theme.gray_12))
})
.child(label)
.on_click(cx.listener(
move |this, _, window, cx| {
this.set_clip_speed_audio_mode(
index, mode, window, cx,
);
},
))
})),
)
})
.child(
div()
.flex()
.flex_row()
Expand Down Expand Up @@ -6235,45 +6281,8 @@ impl EditorWindow {
.on_click(cx.listener(move |this, _, window, cx| {
this.set_clip_muted(index, !muted, window, cx);
})),
)
.into_any_element()
} else {
div()
.flex()
.flex_row()
.items_center()
.gap(px(4.))
.rounded(px(8.))
.bg(Hsla::from(theme.gray_2))
.p(px(4.))
.children(audio_modes.into_iter().map(|(mode, label)| {
let selected = audio_mode == mode
|| (mode == ClipSpeedAudioMode::Mute && muted);
div()
.id(SharedString::from(format!("clip-speed-audio-{label}")))
.rounded(px(6.))
.px(px(8.))
.py(px(4.))
.text_size(px(12.))
.cursor_pointer()
.bg(if selected {
Hsla::from(theme.gray_4)
} else {
gpui::transparent_black()
})
.text_color(Hsla::from(if selected {
theme.gray_12
} else {
theme.gray_10
}))
.hover(|this| this.text_color(Hsla::from(theme.gray_12)))
.child(label)
.on_click(cx.listener(move |this, _, window, cx| {
this.set_clip_speed_audio_mode(index, mode, window, cx);
}))
}))
.into_any_element()
}),
),
),
)
.into_any_element(),
)
Expand Down
1 change: 1 addition & 0 deletions apps/desktop-gpui/src/transcription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2288,6 +2288,7 @@ pub fn apply_caption_result(
end: recording_duration,
name: None,
speed_audio_mode: None,
audio_muted: false,
}],
transitions: Vec::new(),
zoom_segments: Vec::new(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ async fn load_recording(
timescale: 1.0,
name: None,
speed_audio_mode: None,
audio_muted: false,
}]
}
StudioRecordingMeta::MultipleSegments { inner } => inner
Expand All @@ -152,6 +153,7 @@ async fn load_recording(
timescale: 1.0,
name: None,
speed_audio_mode: None,
audio_muted: false,
})
})
.collect(),
Expand Down
Loading