Type AudioClip duration by clip kind; fix MIDI clips growing too fast
The MIDI-clip-end-grows-too-fast bug was a units confusion: AudioClip.duration is documented "seconds" but MIDI clips store their length in BEATS (they share the AudioClip struct with sampled clips). The timeline's effective_clip_duration read it as raw seconds, so at 120 BPM a MIDI clip rendered ~2x too long. The old backend-snapshot display had hidden this by forcing timeline_duration in beats. Root fix — make the domain explicit and unforgeable: - `duration` is now a private field. Reading it in the wrong unit is impossible because access goes through typed accessors: AudioClip::content_duration() -> ClipDuration (a Seconds|Beats enum tagged by clip_type) and set_content_duration(). serde still serializes the private field, so the .beam format is unchanged (bare number). - ClipDuration::to_seconds(tempo_map) for display/sizing; ::native() for code that already works in the clip's native domain (trim math shares it). - get_clip_duration + the timeline-endpoint calc go through to_seconds, so MIDI is converted correctly; effective_clip_duration delegates to get_clip_duration. - Recording mirrors (audio/MIDI progress + finalize) write via set_content_duration (debug-asserts the value's domain matches the clip type). Every former raw read/write of the field (core actions, timeline, piano roll, infopanel, asset library, recording handlers) now goes through the accessors. Whole workspace compiles; 299 core tests pass.
This commit is contained in:
Generated
+1
-1
@@ -3628,7 +3628,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "lightningbeam-editor"
|
||||
version = "1.0.7-alpha"
|
||||
version = "1.0.8-alpha"
|
||||
dependencies = [
|
||||
"beamdsp",
|
||||
"bytemuck",
|
||||
|
||||
@@ -67,15 +67,47 @@ at the requested target res. This fixes the 4K decode wall, the 8 MB upload, *an
|
||||
- Result: software exports are full-quality at any export res, and document resizes re-target decode.
|
||||
No hardware needed; this is the correctness fix for the codecs HW can't handle anyway.
|
||||
|
||||
### Stage 2 — hardware decode primitive (headless-testable here, like the 8 encode tests)
|
||||
- In `gpu-video-encoder` (rename → `gpu-video-codec`): `h264_vaapi`-style **decode** → VAAPI surface →
|
||||
export DMA-BUF → import as a wgpu texture. Hardware test: decode a known file, verify dims/contents.
|
||||
### Stage 2 — hardware decode primitive (DONE, commit 255e164)
|
||||
`decoder::VaapiDecoder` in `gpu-video-encoder`: decode → VAAPI surface → DRM-PRIME DMA-BUF →
|
||||
`dmabuf::import_raw` → wgpu textures. Round-trip test (encode gray → decode → readback Y≈128) passes.
|
||||
|
||||
### Stage 3 — wire hardware decode into `get_frame` (blind; user-verifies)
|
||||
- When the source codec/driver is HW-decodable, `get_frame` returns a **GPU texture** (native res)
|
||||
instead of `Arc<Vec<u8>>`; the compositor uses it directly (no `write_texture`), GPU-scaling to the
|
||||
target. For the zero-copy export the frame never leaves the GPU: **decode → composite → encode** on
|
||||
one device. Software path is the fallback for everything else.
|
||||
### The device-affinity problem (drives the whole rest of the design)
|
||||
wgpu textures can't cross devices, and a decoded frame is a wgpu texture imported from a DMA-BUF —
|
||||
which **requires a device with the DMA-BUF-import extensions** (`VK_EXT_image_drm_format_modifier`
|
||||
+ external-memory), built via wgpu-hal `device_from_raw` (the safe `DeviceDescriptor` can't add
|
||||
them). So a hardware-decoded frame is only usable by a compositor running on **such** a device.
|
||||
- **Export** composites on the encoder's custom device → already fine.
|
||||
- **Preview** composites on eframe's *normal* device → can't import DMA-BUFs → can't use HW frames.
|
||||
|
||||
Since **preview must HW-decode 4K** (software 4K decode ≈19 ms/frame), the resolution is a **single
|
||||
shared custom device** used by eframe + preview compositor + decoder + encoder. eframe 0.33 (local
|
||||
`egui-fork`) accepts it via `WgpuSetup::Existing { instance, adapter, device, queue }` — confirmed.
|
||||
The earlier "separate export device" becomes redundant once this lands.
|
||||
|
||||
### Stage 3a — windowed shared `DrmDevice`, injected into eframe (highest-risk; blind)
|
||||
Today `vk_device::create()` is **headless**. Make a windowed variant (or extend it) that is a
|
||||
**superset** device: DMA-BUF import ext **+** `VK_KHR_swapchain` (device) and the WSI surface
|
||||
instance extensions, **+** everything eframe/egui/vello need — `adapter.limits()` (already; Vello
|
||||
needs `max_storage_buffers_per_shader_stage` ≥ 5), `max_texture_dimension_2d` 8192, and the optional
|
||||
features main.rs requests (`SHADER_F16`, `TIMESTAMP_QUERY[_INSIDE_ENCODERS]`). Pick the adapter that
|
||||
is the **VAAPI GPU** (the render node must match libva's, or DMA-BUF sharing fails on multi-GPU).
|
||||
- main.rs: try to build the shared device; on success pass `WgpuSetup::Existing`, else fall back to
|
||||
the current `WgpuSetupCreateNew` (software decode only). Gate on Linux + VAAPI + a config/env
|
||||
override; **must be bulletproof** — this device now renders *every* frame of *every* session for
|
||||
Linux/VAAPI users, video or not. Milestone: editor runs normally on it with no video involved.
|
||||
|
||||
### Stage 3b — VideoManager hardware decode on the shared device (blind)
|
||||
- `VideoManager` holds a `VaapiDecoder` per HW-decodable clip (built on the shared device), plus the
|
||||
software `VideoDecoder` fallback. `get_frame` gains a GPU-returning variant: yields an imported NV12
|
||||
texture pair (native res) instead of `Arc<Vec<u8>>`. Probe HW support per source; non-VAAPI /
|
||||
unsupported codecs / non-Linux → software path (Stage 1, target-res).
|
||||
- Cache native GPU textures keyed by (clip, ts); revisit the byte budget (4K NV12 ≈ 12 MB each).
|
||||
|
||||
### Stage 3c — compositor consumes the GPU frame (blind; user-verifies)
|
||||
- The video-instance composite path takes an NV12 texture (or a small NV12→RGB GPU pass) and blits it
|
||||
to the target with the existing bilinear blit — **no `write_texture` upload**. GPU scales native→
|
||||
target (preview res or export res). Both preview and the zero-copy export become
|
||||
decode→composite(→encode) with no CPU frame. Software frames still upload as today.
|
||||
|
||||
## Critical files
|
||||
- `lightningbeam-core/src/video.rs` — `VideoDecoder` (per-request output size, scaler cache),
|
||||
@@ -86,13 +118,21 @@ at the requested target res. This fixes the 4K decode wall, the 8 MB upload, *an
|
||||
- `gpu-video-encoder/` (→ `gpu-video-codec`) — `dmabuf.rs`/`vk_device.rs` reused for the decode import.
|
||||
|
||||
## Risks
|
||||
- **Shared custom device is the editor's main device (BIGGEST risk)** — Stage 3a makes a hand-built
|
||||
wgpu-hal Vulkan device render every frame for Linux/VAAPI users. It must satisfy eframe + egui +
|
||||
vello + winit presentation across varied Intel/AMD/Mesa stacks, or the editor won't start. Mitigate
|
||||
with a strict try-and-fall-back-to-normal-device path + an env/config kill switch. Test broadly.
|
||||
- **Multi-GPU** — the shared render device must be the *same* GPU as libva's VAAPI device, or DMA-BUF
|
||||
import fails. Adapter selection must match the render node to the VAAPI node (laptops with iGPU +
|
||||
dGPU, PRIME).
|
||||
- **Codec coverage** — only some codecs are HW-decodable per GPU/driver; software must stay correct
|
||||
and well-tested. Selection must probe support per source, not assume.
|
||||
- **Cache memory** — native-res GPU textures (esp. 4K) are large; the frame cache budget needs revisiting.
|
||||
- **Colorspace/format** — VAAPI decode surfaces are NV12/tiled; the existing import handles NV12, but
|
||||
10-bit/HDR sources (P010) need format handling.
|
||||
- **Preview vs export sharing** — two live targets (preview res + export res) from the same source; the
|
||||
cache/scaler design must serve both without thrashing.
|
||||
and well-tested. Probe support per source, don't assume.
|
||||
- **Cache memory** — native-res GPU textures (esp. 4K NV12 ≈12 MB) are large; revisit the frame cache
|
||||
budget, and the two live targets (preview res + export res) shouldn't thrash.
|
||||
- **Colorspace/format** — VAAPI decode surfaces are NV12/tiled; import handles NV12, but 10-bit/HDR
|
||||
(P010) needs format handling. Decoded NV12 also needs the right BT.601/709 + range on the NV12→RGB
|
||||
read (mirror the encoder's color tags, [[gpu-video-decode]] color-range work).
|
||||
- **Non-Linux / no-VAAPI** — must cleanly run on the normal eframe device with software decode.
|
||||
|
||||
## Verification
|
||||
- Stage 0/1: visual — export above document res is now full-quality (not upscaled); profile shows
|
||||
|
||||
@@ -198,7 +198,7 @@ impl Action for AddClipInstanceAction {
|
||||
|
||||
// Calculate internal start/end from trim parameters
|
||||
let internal_start = self.clip_instance.trim_start;
|
||||
let internal_end = self.clip_instance.trim_end.unwrap_or(clip.duration);
|
||||
let internal_end = self.clip_instance.trim_end.unwrap_or(clip.content_duration().native());
|
||||
let external_start = self.clip_instance.timeline_start;
|
||||
|
||||
// Calculate external duration (for looping if timeline_duration is set).
|
||||
@@ -240,7 +240,7 @@ impl Action for AddClipInstanceAction {
|
||||
// `trim_*` / `clip.duration` are in SECONDS (audio content time),
|
||||
// while `timeline_*` and the backend's `duration` are in BEATS.
|
||||
let internal_start = self.clip_instance.trim_start;
|
||||
let internal_end = self.clip_instance.trim_end.unwrap_or(clip.duration);
|
||||
let internal_end = self.clip_instance.trim_end.unwrap_or(clip.content_duration().native());
|
||||
let start_time = self.clip_instance.timeline_start;
|
||||
// `effective_duration` is in BEATS. When `timeline_duration` is set
|
||||
// it already is; otherwise the clip occupies its natural content
|
||||
|
||||
@@ -129,7 +129,7 @@ impl LoopClipInstancesAction {
|
||||
};
|
||||
|
||||
let content_window = {
|
||||
let trim_end = instance.trim_end.unwrap_or(clip.duration);
|
||||
let trim_end = instance.trim_end.unwrap_or(clip.content_duration().native());
|
||||
(trim_end - instance.trim_start).max(0.0) // seconds
|
||||
};
|
||||
// Natural content length as a beats span at the clip's start (the
|
||||
|
||||
@@ -170,7 +170,7 @@ impl Action for RemoveClipInstancesAction {
|
||||
use daw_backend::command::{Query, QueryResponse};
|
||||
|
||||
let internal_start = instance.trim_start;
|
||||
let internal_end = instance.trim_end.unwrap_or(clip.duration);
|
||||
let internal_end = instance.trim_end.unwrap_or(clip.content_duration().native());
|
||||
let external_start = instance.timeline_start;
|
||||
// MIDI trims are beats-domain, so the fallback span is beats too.
|
||||
let external_duration = instance
|
||||
@@ -198,7 +198,7 @@ impl Action for RemoveClipInstancesAction {
|
||||
}
|
||||
AudioClipType::Sampled { audio_pool_index } => {
|
||||
let internal_start = instance.trim_start;
|
||||
let internal_end = instance.trim_end.unwrap_or(clip.duration);
|
||||
let internal_end = instance.trim_end.unwrap_or(clip.content_duration().native());
|
||||
let start_time = instance.timeline_start;
|
||||
// Fallback span is the content seconds converted to beats at the
|
||||
// clip's start (not the seconds span treated as beats).
|
||||
|
||||
@@ -377,7 +377,7 @@ impl Action for SplitClipInstanceAction {
|
||||
|
||||
// 1. Trim the original (left) instance
|
||||
let orig_internal_start = original_instance.trim_start;
|
||||
let orig_internal_end = original_instance.trim_end.unwrap_or(clip.duration);
|
||||
let orig_internal_end = original_instance.trim_end.unwrap_or(clip.content_duration().native());
|
||||
|
||||
// Look up the original backend instance ID
|
||||
if let Some(crate::action::BackendClipInstanceId::Midi(orig_backend_id)) =
|
||||
@@ -388,7 +388,7 @@ impl Action for SplitClipInstanceAction {
|
||||
|
||||
// 2. Add the new (right) instance
|
||||
let internal_start = new_instance.trim_start;
|
||||
let internal_end = new_instance.trim_end.unwrap_or(clip.duration);
|
||||
let internal_end = new_instance.trim_end.unwrap_or(clip.content_duration().native());
|
||||
let external_start = new_instance.timeline_start;
|
||||
// MIDI trims are beats-domain, so the fallback span is beats too.
|
||||
let external_duration = new_instance
|
||||
@@ -425,7 +425,7 @@ impl Action for SplitClipInstanceAction {
|
||||
AudioClipType::Sampled { audio_pool_index } => {
|
||||
// 1. Trim the original (left) instance
|
||||
let orig_internal_start = original_instance.trim_start;
|
||||
let orig_internal_end = original_instance.trim_end.unwrap_or(clip.duration);
|
||||
let orig_internal_end = original_instance.trim_end.unwrap_or(clip.content_duration().native());
|
||||
|
||||
// Look up the original backend instance ID
|
||||
if let Some(crate::action::BackendClipInstanceId::Audio(orig_backend_id)) =
|
||||
@@ -436,7 +436,7 @@ impl Action for SplitClipInstanceAction {
|
||||
|
||||
// 2. Add the new (right) instance
|
||||
let internal_start = new_instance.trim_start;
|
||||
let internal_end = new_instance.trim_end.unwrap_or(clip.duration);
|
||||
let internal_end = new_instance.trim_end.unwrap_or(clip.content_duration().native());
|
||||
let start_time = new_instance.timeline_start;
|
||||
// Fallback span is the content seconds converted to beats at the
|
||||
// clip's start (not the seconds span treated as beats).
|
||||
@@ -499,7 +499,7 @@ impl Action for SplitClipInstanceAction {
|
||||
if let Some(instance) = al.clip_instances.iter().find(|ci| ci.id == self.instance_id) {
|
||||
if let Some(clip) = document.get_audio_clip(&instance.clip_id) {
|
||||
let orig_internal_start = instance.trim_start;
|
||||
let orig_internal_end = self.original_trim_end.unwrap_or(clip.duration);
|
||||
let orig_internal_end = self.original_trim_end.unwrap_or(clip.content_duration().native());
|
||||
|
||||
// Restore based on clip type
|
||||
use crate::clip::AudioClipType;
|
||||
|
||||
@@ -424,7 +424,7 @@ impl Action for TrimClipInstancesAction {
|
||||
// Calculate new internal_start and internal_end for backend
|
||||
// Note: instance already has the new trim values after execute()
|
||||
let internal_start = instance.trim_start;
|
||||
let internal_end = instance.trim_end.unwrap_or(clip.duration);
|
||||
let internal_end = instance.trim_end.unwrap_or(clip.content_duration().native());
|
||||
|
||||
// Handle trim based on clip type
|
||||
match &clip.clip_type {
|
||||
@@ -517,8 +517,8 @@ impl Action for TrimClipInstancesAction {
|
||||
TrimType::TrimRight => instance.trim_start, // trim_start wasn't changed
|
||||
};
|
||||
let internal_end = match trim_type {
|
||||
TrimType::TrimLeft => instance.trim_end.unwrap_or(clip.duration), // trim_end wasn't changed
|
||||
TrimType::TrimRight => old.trim_value.unwrap_or(clip.duration),
|
||||
TrimType::TrimLeft => instance.trim_end.unwrap_or(clip.content_duration().native()), // trim_end wasn't changed
|
||||
TrimType::TrimRight => old.trim_value.unwrap_or(clip.content_duration().native()),
|
||||
};
|
||||
|
||||
// Handle trim based on clip type
|
||||
|
||||
@@ -468,6 +468,37 @@ pub enum AudioClipType {
|
||||
Recording,
|
||||
}
|
||||
|
||||
/// A clip's content duration, tagged by its native unit.
|
||||
///
|
||||
/// Sampled/recording audio and video measure content in wall-clock **seconds**; MIDI measures
|
||||
/// it in **beats** (tempo-independent musical length). Carrying the domain in the type means a
|
||||
/// duration can't be silently read in the wrong unit.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub enum ClipDuration {
|
||||
Seconds(Seconds),
|
||||
Beats(Beats),
|
||||
}
|
||||
|
||||
impl ClipDuration {
|
||||
/// Wall-clock seconds. Beats are converted as a length from beat 0 (exact under constant
|
||||
/// tempo; a reasonable approximation otherwise — durations are position-independent here).
|
||||
pub fn to_seconds(self, tempo_map: &daw_backend::TempoMap) -> Seconds {
|
||||
match self {
|
||||
ClipDuration::Seconds(s) => s,
|
||||
ClipDuration::Beats(b) => tempo_map.beats_to_seconds(b),
|
||||
}
|
||||
}
|
||||
|
||||
/// The raw magnitude in the clip's native unit. Use only in code that already works in that
|
||||
/// domain (e.g. trim math, whose values share the clip's native domain).
|
||||
pub fn native(self) -> f64 {
|
||||
match self {
|
||||
ClipDuration::Seconds(s) => s.seconds_to_f64(),
|
||||
ClipDuration::Beats(b) => b.beats_to_f64(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Audio clip
|
||||
///
|
||||
/// This is compatible with daw-backend's audio system:
|
||||
@@ -481,9 +512,13 @@ pub struct AudioClip {
|
||||
/// Clip name
|
||||
pub name: String,
|
||||
|
||||
/// Duration in seconds
|
||||
/// For sampled audio, this can be set to trim the audio shorter than the source file
|
||||
pub duration: f64,
|
||||
/// Raw content duration in the clip's **native domain** — SECONDS for sampled/recording
|
||||
/// audio, BEATS for MIDI (musical length, tempo-independent). Private on purpose: the domain
|
||||
/// depends on `clip_type`, so all access goes through [`AudioClip::content_duration`] /
|
||||
/// [`AudioClip::set_content_duration`], which keep it type-safe. Stored as a bare `f64`
|
||||
/// because the `.beam` format serializes it as a plain number (serde derives over private
|
||||
/// fields fine); a domain-tagged newtype would change the on-disk shape.
|
||||
duration: f64,
|
||||
|
||||
/// Audio clip type (sampled or MIDI)
|
||||
pub clip_type: AudioClipType,
|
||||
@@ -494,6 +529,31 @@ pub struct AudioClip {
|
||||
}
|
||||
|
||||
impl AudioClip {
|
||||
/// The clip's content duration, tagged with its native domain (seconds for sampled/recording,
|
||||
/// beats for MIDI). This is the only sanctioned way to read the raw `duration` field.
|
||||
pub fn content_duration(&self) -> ClipDuration {
|
||||
match self.clip_type {
|
||||
AudioClipType::Midi { .. } => ClipDuration::Beats(Beats(self.duration)),
|
||||
AudioClipType::Sampled { .. } | AudioClipType::Recording => {
|
||||
ClipDuration::Seconds(Seconds(self.duration))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the content duration. Debug-asserts the value's domain matches the clip type so a
|
||||
/// beats duration can't be stored on a seconds clip (or vice-versa).
|
||||
pub fn set_content_duration(&mut self, duration: ClipDuration) {
|
||||
debug_assert!(
|
||||
matches!(
|
||||
(&self.clip_type, duration),
|
||||
(AudioClipType::Midi { .. }, ClipDuration::Beats(_))
|
||||
| (AudioClipType::Sampled { .. } | AudioClipType::Recording, ClipDuration::Seconds(_))
|
||||
),
|
||||
"clip duration domain must match clip type",
|
||||
);
|
||||
self.duration = duration.native();
|
||||
}
|
||||
|
||||
/// Create a new sampled audio clip
|
||||
///
|
||||
/// # Arguments
|
||||
|
||||
@@ -472,8 +472,10 @@ impl Document {
|
||||
}
|
||||
crate::layer::AnyLayer::Audio(audio_layer) => {
|
||||
for instance in &audio_layer.clip_instances {
|
||||
if let Some(clip) = self.audio_clips.get(&instance.clip_id) {
|
||||
let end_time = calculate_instance_end(instance, clip.duration);
|
||||
// get_clip_duration yields seconds (converting MIDI's beats duration),
|
||||
// which is what the closure expects.
|
||||
if let Some(clip_duration) = self.get_clip_duration(&instance.clip_id) {
|
||||
let end_time = calculate_instance_end(instance, clip_duration.seconds_to_f64());
|
||||
max_end_time = max_end_time.max(end_time);
|
||||
}
|
||||
}
|
||||
@@ -516,8 +518,8 @@ impl Document {
|
||||
}
|
||||
crate::layer::AnyLayer::Audio(al) => {
|
||||
for inst in &al.clip_instances {
|
||||
if let Some(clip) = doc.audio_clips.get(&inst.clip_id) {
|
||||
*max_end = max_end.max(calc_end(inst, clip.duration));
|
||||
if let Some(clip_duration) = doc.get_clip_duration(&inst.clip_id) {
|
||||
*max_end = max_end.max(calc_end(inst, clip_duration.seconds_to_f64()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -908,7 +910,7 @@ impl Document {
|
||||
// Avoid deep recursion — use stored duration for nested vector clips
|
||||
Some(vc.content_duration(self.framerate, tempo_map))
|
||||
} else if let Some(ac) = self.audio_clips.get(id) {
|
||||
Some(ac.duration)
|
||||
Some(ac.content_duration().to_seconds(tempo_map).seconds_to_f64())
|
||||
} else if let Some(vc) = self.video_clips.get(id) {
|
||||
Some(vc.duration)
|
||||
} else if self.effect_definitions.contains_key(id) {
|
||||
@@ -921,15 +923,9 @@ impl Document {
|
||||
} else if let Some(clip) = self.video_clips.get(clip_id) {
|
||||
Some(Seconds(clip.duration))
|
||||
} else if let Some(clip) = self.audio_clips.get(clip_id) {
|
||||
// MIDI clips store `duration` in BEATS (they share the AudioClip struct with
|
||||
// sampled clips, whose duration is seconds). Convert to wall-clock seconds so
|
||||
// the content-window sizing works uniformly.
|
||||
match clip.clip_type {
|
||||
crate::clip::AudioClipType::Midi { .. } => {
|
||||
Some(self.tempo_map().beats_to_seconds(Beats(clip.duration)))
|
||||
}
|
||||
_ => Some(Seconds(clip.duration)),
|
||||
}
|
||||
// Interpret the clip's native-domain duration as wall-clock seconds (MIDI stores
|
||||
// beats, sampled stores seconds — content_duration keeps that straight).
|
||||
Some(clip.content_duration().to_seconds(self.tempo_map()))
|
||||
} else if self.effect_definitions.contains_key(clip_id) {
|
||||
// Effects have infinite internal duration - their timeline length
|
||||
// is controlled by ClipInstance.trim_end
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
use eframe::egui;
|
||||
use daw_backend::{Beats, Seconds};
|
||||
use lightningbeam_core::clip::ClipDuration;
|
||||
use lightningbeam_core::layer::{AnyLayer, AudioLayer};
|
||||
use lightningbeam_core::layout::{LayoutDefinition, LayoutNode};
|
||||
use lightningbeam_core::pane::PaneType;
|
||||
@@ -5879,7 +5880,7 @@ impl EditorApp {
|
||||
// Get audio clip duration for logging
|
||||
let duration = self.action_executor.document().audio_clips
|
||||
.get(&audio_clip_id)
|
||||
.map(|c| c.duration)
|
||||
.map(|c| c.content_duration().native())
|
||||
.unwrap_or(0.0);
|
||||
|
||||
println!("✅ Extracted audio from '{}' ({:.1}s, {}ch, {}Hz) - AudioClip ID: {}",
|
||||
@@ -6477,7 +6478,7 @@ impl eframe::App for EditorApp {
|
||||
if let Some(doc_clip_id) = doc_clip_id {
|
||||
if let Some(clip) = self.action_executor.document_mut().audio_clips.get_mut(&doc_clip_id) {
|
||||
if clip.is_recording() {
|
||||
clip.duration = duration.seconds_to_f64();
|
||||
clip.set_content_duration(ClipDuration::Seconds(duration));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6650,7 +6651,7 @@ impl eframe::App for EditorApp {
|
||||
}
|
||||
// Update the clip's duration so the timeline bar grows
|
||||
if let Some(clip) = self.action_executor.document_mut().audio_clips.get_mut(&doc_clip_id) {
|
||||
clip.duration = duration.beats_to_f64();
|
||||
clip.set_content_duration(ClipDuration::Beats(duration));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6686,7 +6687,7 @@ impl eframe::App for EditorApp {
|
||||
.map(|(id, _)| id);
|
||||
if let Some(doc_clip_id) = doc_clip_id {
|
||||
if let Some(clip) = self.action_executor.document_mut().audio_clips.get_mut(&doc_clip_id) {
|
||||
clip.duration = midi_clip_data.duration;
|
||||
clip.set_content_duration(ClipDuration::Beats(Beats(midi_clip_data.duration)));
|
||||
clip.name = format!("MIDI Recording {}", clip_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -932,7 +932,7 @@ impl AssetLibraryPane {
|
||||
name: clip.name.clone(),
|
||||
category: AssetCategory::Audio,
|
||||
drag_clip_type,
|
||||
duration: clip.duration,
|
||||
duration: clip.content_duration().native(),
|
||||
dimensions: None,
|
||||
extra_info,
|
||||
is_builtin: false,
|
||||
@@ -1136,7 +1136,7 @@ impl AssetLibraryPane {
|
||||
name: clip.name.clone(),
|
||||
category: AssetCategory::Audio,
|
||||
drag_clip_type,
|
||||
duration: clip.duration,
|
||||
duration: clip.content_duration().native(),
|
||||
dimensions: None,
|
||||
extra_info,
|
||||
is_builtin: false,
|
||||
@@ -1802,7 +1802,7 @@ impl AssetLibraryPane {
|
||||
AudioClipType::Midi { midi_clip_id } => {
|
||||
let note_color = egui::Color32::from_rgb(100, 200, 100);
|
||||
if let Some(events) = shared.midi_event_cache.get(midi_clip_id) {
|
||||
Some(generate_midi_thumbnail(events, clip.duration, bg_color, note_color))
|
||||
Some(generate_midi_thumbnail(events, clip.content_duration().native(), bg_color, note_color))
|
||||
} else {
|
||||
Some(generate_placeholder_thumbnail(AssetCategory::Audio, 200))
|
||||
}
|
||||
@@ -2358,7 +2358,7 @@ impl AssetLibraryPane {
|
||||
AudioClipType::Midi { midi_clip_id } => {
|
||||
let note_color = egui::Color32::from_rgb(100, 200, 100);
|
||||
if let Some(events) = shared.midi_event_cache.get(midi_clip_id) {
|
||||
Some(generate_midi_thumbnail(events, clip.duration, bg_color, note_color))
|
||||
Some(generate_midi_thumbnail(events, clip.content_duration().native(), bg_color, note_color))
|
||||
} else {
|
||||
Some(generate_placeholder_thumbnail(AssetCategory::Audio, 200))
|
||||
}
|
||||
@@ -2495,7 +2495,7 @@ impl AssetLibraryPane {
|
||||
AudioClipType::Midi { midi_clip_id } => {
|
||||
let note_color = egui::Color32::from_rgb(100, 200, 100);
|
||||
if let Some(events) = shared.midi_event_cache.get(midi_clip_id) {
|
||||
Some(generate_midi_thumbnail(events, clip.duration, bg_color, note_color))
|
||||
Some(generate_midi_thumbnail(events, clip.content_duration().native(), bg_color, note_color))
|
||||
} else {
|
||||
Some(generate_placeholder_thumbnail(AssetCategory::Audio, 200))
|
||||
}
|
||||
@@ -2858,7 +2858,7 @@ impl AssetLibraryPane {
|
||||
let note_color = egui::Color32::from_rgb(100, 200, 100);
|
||||
|
||||
if let Some(events) = shared.midi_event_cache.get(midi_clip_id) {
|
||||
Some(generate_midi_thumbnail(events, clip.duration, bg_color, note_color))
|
||||
Some(generate_midi_thumbnail(events, clip.content_duration().native(), bg_color, note_color))
|
||||
} else {
|
||||
Some(generate_placeholder_thumbnail(AssetCategory::Audio, 200))
|
||||
}
|
||||
|
||||
@@ -1808,7 +1808,7 @@ impl InfopanelPane {
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Duration:");
|
||||
ui.label(format!("{:.2}s", clip.duration));
|
||||
ui.label(format!("{:.2}s", clip.content_duration().to_seconds(document.tempo_map()).seconds_to_f64()));
|
||||
});
|
||||
} else {
|
||||
// Could be an image asset or effect — show ID
|
||||
|
||||
@@ -466,7 +466,7 @@ impl PianoRollPane {
|
||||
for instance in &audio_layer.clip_instances {
|
||||
if let Some(clip) = document.audio_clips.get(&instance.clip_id) {
|
||||
if let AudioClipType::Midi { midi_clip_id } = clip.clip_type {
|
||||
let duration = instance.effective_duration(Seconds(clip.duration), document.tempo_map());
|
||||
let duration = instance.effective_duration(clip.content_duration().to_seconds(document.tempo_map()), document.tempo_map());
|
||||
clip_data.push((midi_clip_id, instance.timeline_start.beats_to_f64(), instance.trim_start, duration.beats_to_f64(), instance.id));
|
||||
}
|
||||
}
|
||||
@@ -2459,7 +2459,7 @@ impl PianoRollPane {
|
||||
// length converted to beats at the clip's start.
|
||||
let duration = instance.timeline_duration.unwrap_or_else(|| {
|
||||
let tmap = document.tempo_map();
|
||||
tmap.seconds_to_beats(tmap.beats_to_seconds(instance.timeline_start) + Seconds(clip.duration)) - instance.timeline_start
|
||||
tmap.seconds_to_beats(tmap.beats_to_seconds(instance.timeline_start) + clip.content_duration().to_seconds(tmap)) - instance.timeline_start
|
||||
});
|
||||
// Get sample rate from raw_audio_cache
|
||||
if let Some((_samples, sr, _ch)) = shared.raw_audio_cache.get(&audio_pool_index) {
|
||||
|
||||
@@ -209,7 +209,9 @@ fn effective_clip_duration(
|
||||
document.get_clip_duration(&clip_instance.clip_id)
|
||||
}
|
||||
}
|
||||
AnyLayer::Audio(_) => document.get_audio_clip(&clip_instance.clip_id).map(|c| Seconds(c.duration)),
|
||||
// Delegate to get_clip_duration so MIDI clips (whose `duration` is stored in beats,
|
||||
// not seconds) are converted correctly rather than read as raw seconds.
|
||||
AnyLayer::Audio(_) => document.get_clip_duration(&clip_instance.clip_id),
|
||||
AnyLayer::Video(_) => document.get_video_clip(&clip_instance.clip_id).map(|c| Seconds(c.duration)),
|
||||
AnyLayer::Effect(_) => Some(Seconds(lightningbeam_core::effect::EFFECT_DURATION)),
|
||||
AnyLayer::Group(_) => None,
|
||||
@@ -3082,7 +3084,7 @@ impl TimelinePane {
|
||||
};
|
||||
let audio_file_duration = total_frames as f64 / eff_sr as f64;
|
||||
|
||||
let clip_dur = Seconds(audio_clip.duration);
|
||||
let clip_dur = audio_clip.content_duration().to_seconds(document.tempo_map());
|
||||
let mut ci_start = ci.effective_start();
|
||||
if is_move_drag && selection.contains_clip_instance(&ci.id) {
|
||||
ci_start = self.moved_start(ci_start, document.tempo_map(), &document.time_signature, document.framerate);
|
||||
@@ -4699,7 +4701,7 @@ impl TimelinePane {
|
||||
if selection.contains_clip_instance(&clip_instance.id) {
|
||||
let clip_duration = match layer {
|
||||
lightningbeam_core::layer::AnyLayer::Audio(_) => {
|
||||
document.get_audio_clip(&clip_instance.clip_id).map(|c| c.duration)
|
||||
document.get_audio_clip(&clip_instance.clip_id).map(|c| c.content_duration().native())
|
||||
}
|
||||
_ => continue,
|
||||
};
|
||||
@@ -4773,7 +4775,7 @@ impl TimelinePane {
|
||||
if selection.contains_clip_instance(&clip_instance.id) {
|
||||
let clip_duration = match layer {
|
||||
lightningbeam_core::layer::AnyLayer::Audio(_) => {
|
||||
document.get_audio_clip(&clip_instance.clip_id).map(|c| c.duration)
|
||||
document.get_audio_clip(&clip_instance.clip_id).map(|c| c.content_duration().native())
|
||||
}
|
||||
_ => continue,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user