Massive tempo refactor - make beats canonical time rep and allow them to be non constant
This commit is contained in:
@@ -79,8 +79,6 @@ impl Action for AddClipInstanceAction {
|
||||
if let Some(valid_start) = adjusted_start {
|
||||
// Update instance to use the valid position
|
||||
self.clip_instance.timeline_start = valid_start;
|
||||
let (bpm, fps) = (document.bpm, document.framerate);
|
||||
self.clip_instance.sync_from_seconds(bpm, fps);
|
||||
} else {
|
||||
// No valid position found - reject the operation
|
||||
return Err("Cannot add clip: no valid position found on layer (layer is full)".to_string());
|
||||
@@ -210,10 +208,10 @@ impl Action for AddClipInstanceAction {
|
||||
let instance = daw_backend::MidiClipInstance::new(
|
||||
0, // Instance ID will be assigned by backend
|
||||
*midi_clip_id,
|
||||
internal_start,
|
||||
internal_end,
|
||||
external_start,
|
||||
external_duration,
|
||||
daw_backend::Beats(internal_start),
|
||||
daw_backend::Beats(internal_end),
|
||||
daw_backend::Beats(external_start),
|
||||
daw_backend::Beats(external_duration),
|
||||
);
|
||||
|
||||
// Send query to add instance and get instance ID
|
||||
|
||||
@@ -1,248 +1,49 @@
|
||||
//! Change BPM action
|
||||
//! Change BPM / Tempo action
|
||||
//!
|
||||
//! Atomically changes the document BPM and rescales all clip instance positions and
|
||||
//! MIDI event timestamps so that beat positions are preserved (Measures mode behaviour).
|
||||
//! Atomically swaps the document `TempoMap`, sending the new map to the engine.
|
||||
//! All clip and note positions are stored in **beats** so no position rescaling
|
||||
//! is required — only the TempoMap entry changes.
|
||||
|
||||
use crate::action::{Action, BackendContext};
|
||||
use crate::clip::ClipInstance;
|
||||
use crate::document::Document;
|
||||
use crate::layer::AnyLayer;
|
||||
use std::collections::HashMap;
|
||||
use uuid::Uuid;
|
||||
use crate::tempo_map::TempoMap;
|
||||
|
||||
/// Snapshot of all timing fields on a `ClipInstance`
|
||||
/// Action that changes the global BPM by replacing the tempo map.
|
||||
#[derive(Clone)]
|
||||
struct TimingFields {
|
||||
timeline_start: f64,
|
||||
timeline_start_beats: f64,
|
||||
timeline_start_frames: f64,
|
||||
trim_start: f64,
|
||||
trim_start_beats: f64,
|
||||
trim_start_frames: f64,
|
||||
trim_end: Option<f64>,
|
||||
trim_end_beats: Option<f64>,
|
||||
trim_end_frames: Option<f64>,
|
||||
timeline_duration: Option<f64>,
|
||||
timeline_duration_beats: Option<f64>,
|
||||
timeline_duration_frames: Option<f64>,
|
||||
}
|
||||
|
||||
impl TimingFields {
|
||||
fn from_instance(ci: &ClipInstance) -> Self {
|
||||
Self {
|
||||
timeline_start: ci.timeline_start,
|
||||
timeline_start_beats: ci.timeline_start_beats,
|
||||
timeline_start_frames: ci.timeline_start_frames,
|
||||
trim_start: ci.trim_start,
|
||||
trim_start_beats: ci.trim_start_beats,
|
||||
trim_start_frames: ci.trim_start_frames,
|
||||
trim_end: ci.trim_end,
|
||||
trim_end_beats: ci.trim_end_beats,
|
||||
trim_end_frames: ci.trim_end_frames,
|
||||
timeline_duration: ci.timeline_duration,
|
||||
timeline_duration_beats: ci.timeline_duration_beats,
|
||||
timeline_duration_frames: ci.timeline_duration_frames,
|
||||
}
|
||||
}
|
||||
|
||||
fn apply_to(&self, ci: &mut ClipInstance) {
|
||||
ci.timeline_start = self.timeline_start;
|
||||
ci.timeline_start_beats = self.timeline_start_beats;
|
||||
ci.timeline_start_frames = self.timeline_start_frames;
|
||||
ci.trim_start = self.trim_start;
|
||||
ci.trim_start_beats = self.trim_start_beats;
|
||||
ci.trim_start_frames = self.trim_start_frames;
|
||||
ci.trim_end = self.trim_end;
|
||||
ci.trim_end_beats = self.trim_end_beats;
|
||||
ci.trim_end_frames = self.trim_end_frames;
|
||||
ci.timeline_duration = self.timeline_duration;
|
||||
ci.timeline_duration_beats = self.timeline_duration_beats;
|
||||
ci.timeline_duration_frames = self.timeline_duration_frames;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct ClipTimingSnapshot {
|
||||
layer_id: Uuid,
|
||||
instance_id: Uuid,
|
||||
old_fields: TimingFields,
|
||||
new_fields: TimingFields,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct MidiClipSnapshot {
|
||||
layer_id: Uuid,
|
||||
midi_clip_id: u32,
|
||||
clip_id: Uuid,
|
||||
old_clip_duration: f64,
|
||||
new_clip_duration: f64,
|
||||
old_events: Vec<daw_backend::audio::midi::MidiEvent>,
|
||||
new_events: Vec<daw_backend::audio::midi::MidiEvent>,
|
||||
}
|
||||
|
||||
/// Action that atomically changes BPM and rescales all clip/note positions to preserve beats
|
||||
pub struct ChangeBpmAction {
|
||||
old_bpm: f64,
|
||||
new_bpm: f64,
|
||||
old_map: TempoMap,
|
||||
new_map: TempoMap,
|
||||
time_sig: (u32, u32),
|
||||
clip_snapshots: Vec<ClipTimingSnapshot>,
|
||||
midi_snapshots: Vec<MidiClipSnapshot>,
|
||||
}
|
||||
|
||||
impl ChangeBpmAction {
|
||||
/// Build the action, computing new positions for all clip instances and MIDI events.
|
||||
///
|
||||
/// `midi_event_cache` maps backend MIDI clip ID → current event list.
|
||||
pub fn new(
|
||||
old_bpm: f64,
|
||||
new_bpm: f64,
|
||||
document: &Document,
|
||||
midi_event_cache: &HashMap<u32, Vec<daw_backend::audio::midi::MidiEvent>>,
|
||||
) -> Self {
|
||||
let fps = document.framerate;
|
||||
let time_sig = (
|
||||
document.time_signature.numerator,
|
||||
document.time_signature.denominator,
|
||||
);
|
||||
|
||||
let mut clip_snapshots: Vec<ClipTimingSnapshot> = Vec::new();
|
||||
let mut midi_snapshots: Vec<MidiClipSnapshot> = Vec::new();
|
||||
|
||||
// Collect MIDI clip IDs we've already snapshotted (avoid duplicates)
|
||||
let mut seen_midi_clips: std::collections::HashSet<u32> = std::collections::HashSet::new();
|
||||
|
||||
for layer in document.all_layers() {
|
||||
let layer_id = layer.id();
|
||||
|
||||
let clip_instances: &[ClipInstance] = match layer {
|
||||
AnyLayer::Vector(vl) => &vl.clip_instances,
|
||||
AnyLayer::Audio(al) => &al.clip_instances,
|
||||
AnyLayer::Video(vl) => &vl.clip_instances,
|
||||
AnyLayer::Effect(el) => &el.clip_instances,
|
||||
AnyLayer::Group(_) | AnyLayer::Raster(_) => continue,
|
||||
};
|
||||
|
||||
for ci in clip_instances {
|
||||
let old_fields = TimingFields::from_instance(ci);
|
||||
|
||||
// Compute new fields: beats are canonical, recompute seconds + frames.
|
||||
// Guard: if timeline_start_beats was never populated (clips added without
|
||||
// sync_from_seconds), derive beats from seconds before applying.
|
||||
let mut new_ci = ci.clone();
|
||||
if new_ci.timeline_start_beats == 0.0 && new_ci.timeline_start.abs() > 1e-9 {
|
||||
new_ci.sync_from_seconds(old_bpm, fps);
|
||||
}
|
||||
new_ci.apply_beats(new_bpm, fps);
|
||||
let new_fields = TimingFields::from_instance(&new_ci);
|
||||
|
||||
clip_snapshots.push(ClipTimingSnapshot {
|
||||
layer_id,
|
||||
instance_id: ci.id,
|
||||
old_fields,
|
||||
new_fields,
|
||||
});
|
||||
|
||||
// If this is a MIDI clip on an audio layer, collect MIDI events + rescale duration.
|
||||
// Always snapshot the clip (even if empty) so clip.duration is rescaled.
|
||||
if let AnyLayer::Audio(_) = layer {
|
||||
if let Some(audio_clip) = document.get_audio_clip(&ci.clip_id) {
|
||||
use crate::clip::AudioClipType;
|
||||
if let AudioClipType::Midi { midi_clip_id } = &audio_clip.clip_type {
|
||||
let midi_id = *midi_clip_id;
|
||||
if !seen_midi_clips.contains(&midi_id) {
|
||||
seen_midi_clips.insert(midi_id);
|
||||
|
||||
let old_clip_duration = audio_clip.duration;
|
||||
let new_clip_duration = old_clip_duration * old_bpm / new_bpm;
|
||||
|
||||
// Use cached events if present; empty vec for clips with no events yet.
|
||||
let old_events = midi_event_cache.get(&midi_id).cloned().unwrap_or_default();
|
||||
let new_events: Vec<_> = old_events.iter().map(|ev| {
|
||||
let mut e = ev.clone();
|
||||
// Ensure beats are populated before using them as canonical.
|
||||
// Events created before triple-rep (e.g. from recording)
|
||||
// have timestamp_beats == 0.0 — sync from seconds first.
|
||||
if e.timestamp_beats == 0.0 && e.timestamp.abs() > 1e-9 {
|
||||
e.sync_from_seconds(old_bpm, fps);
|
||||
}
|
||||
e.apply_beats(new_bpm, fps);
|
||||
e
|
||||
}).collect();
|
||||
|
||||
midi_snapshots.push(MidiClipSnapshot {
|
||||
layer_id,
|
||||
midi_clip_id: midi_id,
|
||||
clip_id: ci.clip_id,
|
||||
old_clip_duration,
|
||||
new_clip_duration,
|
||||
old_events,
|
||||
new_events,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Self {
|
||||
old_bpm,
|
||||
new_bpm,
|
||||
time_sig,
|
||||
clip_snapshots,
|
||||
midi_snapshots,
|
||||
}
|
||||
/// Build the action from the current document state and a desired new BPM.
|
||||
pub fn new(new_bpm: f64, document: &Document) -> Self {
|
||||
let old_map = document.tempo_map().clone();
|
||||
let mut new_map = old_map.clone();
|
||||
new_map.set_global_bpm(new_bpm);
|
||||
let time_sig = (document.time_signature.numerator, document.time_signature.denominator);
|
||||
Self { old_map, new_map, time_sig }
|
||||
}
|
||||
|
||||
/// Return the new MIDI event lists for each affected clip (for immediate cache update).
|
||||
pub fn new_midi_events(&self) -> impl Iterator<Item = (u32, &Vec<daw_backend::audio::midi::MidiEvent>)> {
|
||||
self.midi_snapshots.iter().map(|s| (s.midi_clip_id, &s.new_events))
|
||||
/// Build from explicit old/new maps (used when the map already changed in-place,
|
||||
/// e.g., after live drag preview; the caller provides start and end states).
|
||||
pub fn from_maps(old_map: TempoMap, new_map: TempoMap, time_sig: (u32, u32)) -> Self {
|
||||
Self { old_map, new_map, time_sig }
|
||||
}
|
||||
|
||||
fn apply_clips(document: &mut Document, snapshots: &[ClipTimingSnapshot], use_new: bool) {
|
||||
for snap in snapshots {
|
||||
let fields = if use_new { &snap.new_fields } else { &snap.old_fields };
|
||||
|
||||
let layer = match document.get_layer_mut(&snap.layer_id) {
|
||||
Some(l) => l,
|
||||
None => continue,
|
||||
};
|
||||
|
||||
let clip_instances = match layer {
|
||||
AnyLayer::Vector(vl) => &mut vl.clip_instances,
|
||||
AnyLayer::Audio(al) => &mut al.clip_instances,
|
||||
AnyLayer::Video(vl) => &mut vl.clip_instances,
|
||||
AnyLayer::Effect(el) => &mut el.clip_instances,
|
||||
AnyLayer::Group(_) | AnyLayer::Raster(_) => continue,
|
||||
};
|
||||
|
||||
if let Some(ci) = clip_instances.iter_mut().find(|ci| ci.id == snap.instance_id) {
|
||||
fields.apply_to(ci);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn apply_midi_durations(document: &mut Document, snapshots: &[MidiClipSnapshot], use_new: bool) {
|
||||
for snap in snapshots {
|
||||
if let Some(clip) = document.get_audio_clip_mut(&snap.clip_id) {
|
||||
clip.duration = if use_new { snap.new_clip_duration } else { snap.old_clip_duration };
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn new_bpm(&self) -> f64 { self.new_map.global_bpm() }
|
||||
pub fn old_bpm(&self) -> f64 { self.old_map.global_bpm() }
|
||||
}
|
||||
|
||||
impl Action for ChangeBpmAction {
|
||||
fn execute(&mut self, document: &mut Document) -> Result<(), String> {
|
||||
document.bpm = self.new_bpm;
|
||||
Self::apply_clips(document, &self.clip_snapshots, true);
|
||||
Self::apply_midi_durations(document, &self.midi_snapshots, true);
|
||||
*document.tempo_map_mut() = self.new_map.clone();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn rollback(&mut self, document: &mut Document) -> Result<(), String> {
|
||||
document.bpm = self.old_bpm;
|
||||
Self::apply_clips(document, &self.clip_snapshots, false);
|
||||
Self::apply_midi_durations(document, &self.midi_snapshots, false);
|
||||
*document.tempo_map_mut() = self.old_map.clone();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -253,111 +54,26 @@ impl Action for ChangeBpmAction {
|
||||
fn execute_backend(
|
||||
&mut self,
|
||||
backend: &mut BackendContext,
|
||||
document: &Document,
|
||||
_document: &Document,
|
||||
) -> Result<(), String> {
|
||||
let controller = match backend.audio_controller.as_mut() {
|
||||
Some(c) => c,
|
||||
None => return Ok(()),
|
||||
};
|
||||
|
||||
// Update tempo
|
||||
controller.set_tempo(self.new_bpm as f32, self.time_sig);
|
||||
|
||||
// Update MIDI clip events and positions
|
||||
for snap in &self.midi_snapshots {
|
||||
let track_id = match backend.layer_to_track_map.get(&snap.layer_id) {
|
||||
Some(&id) => id,
|
||||
None => continue,
|
||||
};
|
||||
controller.update_midi_clip_events(track_id, snap.midi_clip_id, snap.new_events.clone());
|
||||
}
|
||||
|
||||
// Move clip instances in the backend
|
||||
for snap in &self.clip_snapshots {
|
||||
let track_id = match backend.layer_to_track_map.get(&snap.layer_id) {
|
||||
Some(&id) => id,
|
||||
None => continue,
|
||||
};
|
||||
let backend_id = backend.clip_instance_to_backend_map.get(&snap.instance_id);
|
||||
match backend_id {
|
||||
Some(crate::action::BackendClipInstanceId::Audio(audio_id)) => {
|
||||
controller.move_clip(track_id, *audio_id, snap.new_fields.timeline_start);
|
||||
}
|
||||
Some(crate::action::BackendClipInstanceId::Midi(midi_id)) => {
|
||||
controller.move_clip(track_id, *midi_id, snap.new_fields.timeline_start);
|
||||
}
|
||||
None => {} // Vector/video clips — no backend move needed
|
||||
}
|
||||
}
|
||||
|
||||
// Sync beat/frame representations, rescale MIDI clip durations, and rescale
|
||||
// automation keyframe times in the backend
|
||||
let fps = document.framerate;
|
||||
let midi_durations: Vec<(u32, f64)> = self.midi_snapshots.iter()
|
||||
.map(|s| (s.midi_clip_id, s.new_clip_duration))
|
||||
.collect();
|
||||
controller.apply_bpm_change(self.old_bpm, self.new_bpm, fps, midi_durations);
|
||||
|
||||
controller.set_tempo(self.new_map.global_bpm() as f32, self.time_sig);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn rollback_backend(
|
||||
&mut self,
|
||||
backend: &mut BackendContext,
|
||||
document: &Document,
|
||||
_document: &Document,
|
||||
) -> Result<(), String> {
|
||||
let controller = match backend.audio_controller.as_mut() {
|
||||
Some(c) => c,
|
||||
None => return Ok(()),
|
||||
};
|
||||
|
||||
controller.set_tempo(self.old_bpm as f32, self.time_sig);
|
||||
|
||||
for snap in &self.midi_snapshots {
|
||||
let track_id = match backend.layer_to_track_map.get(&snap.layer_id) {
|
||||
Some(&id) => id,
|
||||
None => continue,
|
||||
};
|
||||
controller.update_midi_clip_events(track_id, snap.midi_clip_id, snap.old_events.clone());
|
||||
}
|
||||
|
||||
for snap in &self.clip_snapshots {
|
||||
let track_id = match backend.layer_to_track_map.get(&snap.layer_id) {
|
||||
Some(&id) => id,
|
||||
None => continue,
|
||||
};
|
||||
let backend_id = backend.clip_instance_to_backend_map.get(&snap.instance_id);
|
||||
match backend_id {
|
||||
Some(crate::action::BackendClipInstanceId::Audio(audio_id)) => {
|
||||
controller.move_clip(track_id, *audio_id, snap.old_fields.timeline_start);
|
||||
}
|
||||
Some(crate::action::BackendClipInstanceId::Midi(midi_id)) => {
|
||||
controller.move_clip(track_id, *midi_id, snap.old_fields.timeline_start);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
|
||||
// Sync beat/frame representations, restore MIDI clip durations, and restore
|
||||
// automation keyframe times in the backend
|
||||
let fps = document.framerate;
|
||||
let midi_durations: Vec<(u32, f64)> = self.midi_snapshots.iter()
|
||||
.map(|s| (s.midi_clip_id, s.old_clip_duration))
|
||||
.collect();
|
||||
controller.apply_bpm_change(self.new_bpm, self.old_bpm, fps, midi_durations);
|
||||
|
||||
controller.set_tempo(self.old_map.global_bpm() as f32, self.time_sig);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn all_midi_events_after_execute(&self) -> Vec<(u32, Vec<daw_backend::audio::midi::MidiEvent>)> {
|
||||
self.midi_snapshots.iter()
|
||||
.map(|s| (s.midi_clip_id, s.new_events.clone()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn all_midi_events_after_rollback(&self) -> Vec<(u32, Vec<daw_backend::audio::midi::MidiEvent>)> {
|
||||
self.midi_snapshots.iter()
|
||||
.map(|s| (s.midi_clip_id, s.old_events.clone()))
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,156 +1,33 @@
|
||||
//! Change FPS action
|
||||
//!
|
||||
//! Atomically changes the document framerate and rescales all clip instance positions
|
||||
//! so that frame positions are preserved (Frames mode behaviour).
|
||||
//! Atomically changes the document framerate.
|
||||
//! All clip positions are stored in **beats** so no position rescaling is
|
||||
//! required — only the framerate field changes.
|
||||
|
||||
use crate::action::{Action, BackendContext};
|
||||
use crate::clip::ClipInstance;
|
||||
use crate::document::Document;
|
||||
use crate::layer::AnyLayer;
|
||||
use uuid::Uuid;
|
||||
|
||||
/// Snapshot of all timing fields on a `ClipInstance`
|
||||
#[derive(Clone)]
|
||||
struct TimingFields {
|
||||
timeline_start: f64,
|
||||
timeline_start_beats: f64,
|
||||
timeline_start_frames: f64,
|
||||
trim_start: f64,
|
||||
trim_start_beats: f64,
|
||||
trim_start_frames: f64,
|
||||
trim_end: Option<f64>,
|
||||
trim_end_beats: Option<f64>,
|
||||
trim_end_frames: Option<f64>,
|
||||
timeline_duration: Option<f64>,
|
||||
timeline_duration_beats: Option<f64>,
|
||||
timeline_duration_frames: Option<f64>,
|
||||
}
|
||||
|
||||
impl TimingFields {
|
||||
fn from_instance(ci: &ClipInstance) -> Self {
|
||||
Self {
|
||||
timeline_start: ci.timeline_start,
|
||||
timeline_start_beats: ci.timeline_start_beats,
|
||||
timeline_start_frames: ci.timeline_start_frames,
|
||||
trim_start: ci.trim_start,
|
||||
trim_start_beats: ci.trim_start_beats,
|
||||
trim_start_frames: ci.trim_start_frames,
|
||||
trim_end: ci.trim_end,
|
||||
trim_end_beats: ci.trim_end_beats,
|
||||
trim_end_frames: ci.trim_end_frames,
|
||||
timeline_duration: ci.timeline_duration,
|
||||
timeline_duration_beats: ci.timeline_duration_beats,
|
||||
timeline_duration_frames: ci.timeline_duration_frames,
|
||||
}
|
||||
}
|
||||
|
||||
fn apply_to(&self, ci: &mut ClipInstance) {
|
||||
ci.timeline_start = self.timeline_start;
|
||||
ci.timeline_start_beats = self.timeline_start_beats;
|
||||
ci.timeline_start_frames = self.timeline_start_frames;
|
||||
ci.trim_start = self.trim_start;
|
||||
ci.trim_start_beats = self.trim_start_beats;
|
||||
ci.trim_start_frames = self.trim_start_frames;
|
||||
ci.trim_end = self.trim_end;
|
||||
ci.trim_end_beats = self.trim_end_beats;
|
||||
ci.trim_end_frames = self.trim_end_frames;
|
||||
ci.timeline_duration = self.timeline_duration;
|
||||
ci.timeline_duration_beats = self.timeline_duration_beats;
|
||||
ci.timeline_duration_frames = self.timeline_duration_frames;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct ClipTimingSnapshot {
|
||||
layer_id: Uuid,
|
||||
instance_id: Uuid,
|
||||
old_fields: TimingFields,
|
||||
new_fields: TimingFields,
|
||||
}
|
||||
|
||||
/// Action that atomically changes framerate and rescales all clip positions to preserve frames
|
||||
/// Action that changes the document framerate.
|
||||
pub struct ChangeFpsAction {
|
||||
old_fps: f64,
|
||||
new_fps: f64,
|
||||
clip_snapshots: Vec<ClipTimingSnapshot>,
|
||||
}
|
||||
|
||||
impl ChangeFpsAction {
|
||||
/// Build the action, computing new positions for all clip instances.
|
||||
pub fn new(old_fps: f64, new_fps: f64, document: &Document) -> Self {
|
||||
let bpm = document.bpm;
|
||||
|
||||
let mut clip_snapshots: Vec<ClipTimingSnapshot> = Vec::new();
|
||||
|
||||
for layer in document.all_layers() {
|
||||
let layer_id = layer.id();
|
||||
|
||||
let clip_instances: &[ClipInstance] = match layer {
|
||||
AnyLayer::Vector(vl) => &vl.clip_instances,
|
||||
AnyLayer::Audio(al) => &al.clip_instances,
|
||||
AnyLayer::Video(vl) => &vl.clip_instances,
|
||||
AnyLayer::Effect(el) => &el.clip_instances,
|
||||
AnyLayer::Group(_) | AnyLayer::Raster(_) => continue,
|
||||
};
|
||||
|
||||
for ci in clip_instances {
|
||||
let old_fields = TimingFields::from_instance(ci);
|
||||
|
||||
// Compute new fields: frames are canonical, recompute seconds + beats
|
||||
let mut new_ci = ci.clone();
|
||||
new_ci.apply_frames(new_fps, bpm);
|
||||
let new_fields = TimingFields::from_instance(&new_ci);
|
||||
|
||||
clip_snapshots.push(ClipTimingSnapshot {
|
||||
layer_id,
|
||||
instance_id: ci.id,
|
||||
old_fields,
|
||||
new_fields,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Self {
|
||||
old_fps,
|
||||
new_fps,
|
||||
clip_snapshots,
|
||||
}
|
||||
}
|
||||
|
||||
fn apply_clips(document: &mut Document, snapshots: &[ClipTimingSnapshot], use_new: bool) {
|
||||
for snap in snapshots {
|
||||
let fields = if use_new { &snap.new_fields } else { &snap.old_fields };
|
||||
|
||||
let layer = match document.get_layer_mut(&snap.layer_id) {
|
||||
Some(l) => l,
|
||||
None => continue,
|
||||
};
|
||||
|
||||
let clip_instances = match layer {
|
||||
AnyLayer::Vector(vl) => &mut vl.clip_instances,
|
||||
AnyLayer::Audio(al) => &mut al.clip_instances,
|
||||
AnyLayer::Video(vl) => &mut vl.clip_instances,
|
||||
AnyLayer::Effect(el) => &mut el.clip_instances,
|
||||
AnyLayer::Group(_) | AnyLayer::Raster(_) => continue,
|
||||
};
|
||||
|
||||
if let Some(ci) = clip_instances.iter_mut().find(|ci| ci.id == snap.instance_id) {
|
||||
fields.apply_to(ci);
|
||||
}
|
||||
}
|
||||
/// Build the action from old and new framerates.
|
||||
pub fn new(old_fps: f64, new_fps: f64, _document: &Document) -> Self {
|
||||
Self { old_fps, new_fps }
|
||||
}
|
||||
}
|
||||
|
||||
impl Action for ChangeFpsAction {
|
||||
fn execute(&mut self, document: &mut Document) -> Result<(), String> {
|
||||
document.framerate = self.new_fps;
|
||||
Self::apply_clips(document, &self.clip_snapshots, true);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn rollback(&mut self, document: &mut Document) -> Result<(), String> {
|
||||
document.framerate = self.old_fps;
|
||||
Self::apply_clips(document, &self.clip_snapshots, false);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -160,68 +37,18 @@ impl Action for ChangeFpsAction {
|
||||
|
||||
fn execute_backend(
|
||||
&mut self,
|
||||
backend: &mut BackendContext,
|
||||
_backend: &mut BackendContext,
|
||||
_document: &Document,
|
||||
) -> Result<(), String> {
|
||||
// FPS change does not affect audio timing — only move clips that changed position
|
||||
let controller = match backend.audio_controller.as_mut() {
|
||||
Some(c) => c,
|
||||
None => return Ok(()),
|
||||
};
|
||||
|
||||
for snap in &self.clip_snapshots {
|
||||
if (snap.new_fields.timeline_start - snap.old_fields.timeline_start).abs() < 1e-9 {
|
||||
continue; // No movement, skip
|
||||
}
|
||||
let track_id = match backend.layer_to_track_map.get(&snap.layer_id) {
|
||||
Some(&id) => id,
|
||||
None => continue,
|
||||
};
|
||||
let backend_id = backend.clip_instance_to_backend_map.get(&snap.instance_id);
|
||||
match backend_id {
|
||||
Some(crate::action::BackendClipInstanceId::Audio(audio_id)) => {
|
||||
controller.move_clip(track_id, *audio_id, snap.new_fields.timeline_start);
|
||||
}
|
||||
Some(crate::action::BackendClipInstanceId::Midi(midi_id)) => {
|
||||
controller.move_clip(track_id, *midi_id, snap.new_fields.timeline_start);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
|
||||
// FPS does not affect audio scheduling — nothing to do in the backend.
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn rollback_backend(
|
||||
&mut self,
|
||||
backend: &mut BackendContext,
|
||||
_backend: &mut BackendContext,
|
||||
_document: &Document,
|
||||
) -> Result<(), String> {
|
||||
let controller = match backend.audio_controller.as_mut() {
|
||||
Some(c) => c,
|
||||
None => return Ok(()),
|
||||
};
|
||||
|
||||
for snap in &self.clip_snapshots {
|
||||
if (snap.new_fields.timeline_start - snap.old_fields.timeline_start).abs() < 1e-9 {
|
||||
continue;
|
||||
}
|
||||
let track_id = match backend.layer_to_track_map.get(&snap.layer_id) {
|
||||
Some(&id) => id,
|
||||
None => continue,
|
||||
};
|
||||
let backend_id = backend.clip_instance_to_backend_map.get(&snap.instance_id);
|
||||
match backend_id {
|
||||
Some(crate::action::BackendClipInstanceId::Audio(audio_id)) => {
|
||||
controller.move_clip(track_id, *audio_id, snap.old_fields.timeline_start);
|
||||
}
|
||||
Some(crate::action::BackendClipInstanceId::Midi(midi_id)) => {
|
||||
controller.move_clip(track_id, *midi_id, snap.old_fields.timeline_start);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,9 +119,6 @@ impl Action for MoveClipInstancesAction {
|
||||
// Store adjusted moves for rollback
|
||||
self.layer_moves = adjusted_moves.clone();
|
||||
|
||||
let bpm = document.bpm;
|
||||
let fps = document.framerate;
|
||||
|
||||
// Apply all adjusted moves
|
||||
for (layer_id, moves) in &adjusted_moves {
|
||||
let layer = document.get_layer_mut(layer_id)
|
||||
@@ -142,7 +139,6 @@ impl Action for MoveClipInstancesAction {
|
||||
if let Some(clip_instance) = clip_instances.iter_mut().find(|ci| ci.id == *clip_id)
|
||||
{
|
||||
clip_instance.timeline_start = *new;
|
||||
clip_instance.sync_from_seconds(bpm, fps);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -151,8 +147,6 @@ impl Action for MoveClipInstancesAction {
|
||||
}
|
||||
|
||||
fn rollback(&mut self, document: &mut Document) -> Result<(), String> {
|
||||
let bpm = document.bpm;
|
||||
let fps = document.framerate;
|
||||
for (layer_id, moves) in &self.layer_moves {
|
||||
let layer = document.get_layer_mut(layer_id)
|
||||
.ok_or_else(|| format!("Layer {} not found", layer_id))?;
|
||||
@@ -172,7 +166,6 @@ impl Action for MoveClipInstancesAction {
|
||||
if let Some(clip_instance) = clip_instances.iter_mut().find(|ci| ci.id == *clip_id)
|
||||
{
|
||||
clip_instance.timeline_start = *old;
|
||||
clip_instance.sync_from_seconds(bpm, fps);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,10 +177,10 @@ impl Action for RemoveClipInstancesAction {
|
||||
let midi_instance = daw_backend::MidiClipInstance::new(
|
||||
0,
|
||||
*midi_clip_id,
|
||||
internal_start,
|
||||
internal_end,
|
||||
external_start,
|
||||
external_duration,
|
||||
daw_backend::Beats(internal_start),
|
||||
daw_backend::Beats(internal_end),
|
||||
daw_backend::Beats(external_start),
|
||||
daw_backend::Beats(external_duration),
|
||||
);
|
||||
|
||||
let query = Query::AddMidiClipInstanceSync(track_id, midi_instance);
|
||||
|
||||
@@ -126,8 +126,8 @@ impl Action for SplitClipInstanceAction {
|
||||
.get_clip_duration(&instance.clip_id)
|
||||
.ok_or_else(|| format!("Clip {} not found", instance.clip_id))?;
|
||||
|
||||
// Calculate the effective duration and timeline end
|
||||
let effective_duration = instance.effective_duration(clip_duration);
|
||||
// Calculate the effective duration and timeline end (both in beats)
|
||||
let effective_duration = instance.effective_duration(clip_duration, document.tempo_map());
|
||||
let timeline_end = instance.timeline_start + effective_duration;
|
||||
|
||||
// Validate: split_time must be strictly within the clip's timeline span
|
||||
@@ -179,7 +179,6 @@ impl Action for SplitClipInstanceAction {
|
||||
}
|
||||
|
||||
self.new_instance_id = Some(right_instance.id);
|
||||
right_instance.sync_from_seconds(document.bpm, document.framerate);
|
||||
|
||||
// Now modify the original (left) instance and add the new (right) instance
|
||||
let layer_mut = document
|
||||
@@ -239,21 +238,6 @@ impl Action for SplitClipInstanceAction {
|
||||
}
|
||||
}
|
||||
|
||||
// Sync derived fields on the left (original) instance
|
||||
let (bpm, fps) = (document.bpm, document.framerate);
|
||||
if let Some(layer) = document.get_layer_mut(&self.layer_id) {
|
||||
let cis: &mut Vec<crate::clip::ClipInstance> = match layer {
|
||||
AnyLayer::Vector(vl) => &mut vl.clip_instances,
|
||||
AnyLayer::Audio(al) => &mut al.clip_instances,
|
||||
AnyLayer::Video(vl) => &mut vl.clip_instances,
|
||||
AnyLayer::Effect(el) => &mut el.clip_instances,
|
||||
_ => return { self.executed = true; Ok(()) },
|
||||
};
|
||||
if let Some(inst) = cis.iter_mut().find(|ci| ci.id == self.instance_id) {
|
||||
inst.sync_from_seconds(bpm, fps);
|
||||
}
|
||||
}
|
||||
|
||||
self.executed = true;
|
||||
Ok(())
|
||||
}
|
||||
@@ -406,10 +390,10 @@ impl Action for SplitClipInstanceAction {
|
||||
let instance = daw_backend::MidiClipInstance::new(
|
||||
0,
|
||||
*midi_clip_id,
|
||||
internal_start,
|
||||
internal_end,
|
||||
external_start,
|
||||
external_duration,
|
||||
daw_backend::Beats(internal_start),
|
||||
daw_backend::Beats(internal_end),
|
||||
daw_backend::Beats(external_start),
|
||||
daw_backend::Beats(external_duration),
|
||||
);
|
||||
|
||||
let query = Query::AddMidiClipInstanceSync(*backend_track_id, instance);
|
||||
|
||||
@@ -101,7 +101,7 @@ impl Action for TrimClipInstancesAction {
|
||||
AnyLayer::Effect(el) => &el.clip_instances,
|
||||
AnyLayer::Group(_) => &[],
|
||||
AnyLayer::Raster(_) => &[],
|
||||
};
|
||||
};
|
||||
|
||||
if let Some(instance) = clip_instances.iter().find(|ci| ci.id == *member_instance_id) {
|
||||
let member_old_trim = instance.trim_start;
|
||||
@@ -138,7 +138,7 @@ impl Action for TrimClipInstancesAction {
|
||||
AnyLayer::Effect(el) => &el.clip_instances,
|
||||
AnyLayer::Group(_) => &[],
|
||||
AnyLayer::Raster(_) => &[],
|
||||
};
|
||||
};
|
||||
|
||||
if let Some(instance) = clip_instances.iter().find(|ci| ci.id == *member_instance_id) {
|
||||
let member_old_trim_end = instance.trim_end;
|
||||
@@ -182,7 +182,7 @@ impl Action for TrimClipInstancesAction {
|
||||
AnyLayer::Effect(el) => &el.clip_instances,
|
||||
AnyLayer::Group(_) => &[],
|
||||
AnyLayer::Raster(_) => &[],
|
||||
};
|
||||
};
|
||||
|
||||
let instance = clip_instances.iter()
|
||||
.find(|ci| &ci.id == instance_id)
|
||||
@@ -260,9 +260,6 @@ impl Action for TrimClipInstancesAction {
|
||||
// Store clamped trims for rollback
|
||||
self.layer_trims = clamped_trims.clone();
|
||||
|
||||
let bpm = document.bpm;
|
||||
let fps = document.framerate;
|
||||
|
||||
// Apply all clamped trims
|
||||
for (layer_id, trims) in &clamped_trims {
|
||||
let layer = match document.get_layer_mut(layer_id) {
|
||||
@@ -297,7 +294,6 @@ impl Action for TrimClipInstancesAction {
|
||||
clip_instance.trim_end = new.trim_value;
|
||||
}
|
||||
}
|
||||
clip_instance.sync_from_seconds(bpm, fps);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -305,8 +301,6 @@ impl Action for TrimClipInstancesAction {
|
||||
}
|
||||
|
||||
fn rollback(&mut self, document: &mut Document) -> Result<(), String> {
|
||||
let bpm = document.bpm;
|
||||
let fps = document.framerate;
|
||||
for (layer_id, trims) in &self.layer_trims {
|
||||
let layer = match document.get_layer_mut(layer_id) {
|
||||
Some(l) => l,
|
||||
@@ -340,7 +334,6 @@ impl Action for TrimClipInstancesAction {
|
||||
clip_instance.trim_end = old.trim_value;
|
||||
}
|
||||
}
|
||||
clip_instance.sync_from_seconds(bpm, fps);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! Beat/measure ↔ seconds conversion utilities
|
||||
|
||||
use crate::document::TimeSignature;
|
||||
use crate::tempo_map::TempoMap;
|
||||
|
||||
/// Position expressed as measure, beat, tick
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
@@ -11,9 +12,8 @@ pub struct MeasurePosition {
|
||||
}
|
||||
|
||||
/// Convert a time in seconds to a measure position
|
||||
pub fn time_to_measure(time: f64, bpm: f64, time_sig: &TimeSignature) -> MeasurePosition {
|
||||
let beats_per_second = bpm / 60.0;
|
||||
let total_beats = (time * beats_per_second).max(0.0);
|
||||
pub fn time_to_measure(time: f64, tempo_map: &TempoMap, time_sig: &TimeSignature) -> MeasurePosition {
|
||||
let total_beats = tempo_map.inverse_transform(time).max(0.0);
|
||||
let beats_per_measure = time_sig.numerator as f64;
|
||||
|
||||
let measure = (total_beats / beats_per_measure).floor() as u32 + 1;
|
||||
@@ -24,21 +24,20 @@ pub fn time_to_measure(time: f64, bpm: f64, time_sig: &TimeSignature) -> Measure
|
||||
}
|
||||
|
||||
/// Convert a measure position to seconds
|
||||
pub fn measure_to_time(pos: MeasurePosition, bpm: f64, time_sig: &TimeSignature) -> f64 {
|
||||
pub fn measure_to_time(pos: MeasurePosition, tempo_map: &TempoMap, time_sig: &TimeSignature) -> f64 {
|
||||
let beats_per_measure = time_sig.numerator as f64;
|
||||
let total_beats = (pos.measure as f64 - 1.0) * beats_per_measure
|
||||
+ (pos.beat as f64 - 1.0)
|
||||
+ (pos.tick as f64 / 1000.0);
|
||||
let beats_per_second = bpm / 60.0;
|
||||
total_beats / beats_per_second
|
||||
tempo_map.transform(total_beats)
|
||||
}
|
||||
|
||||
/// Get the duration of one beat in seconds
|
||||
pub fn beat_duration(bpm: f64) -> f64 {
|
||||
60.0 / bpm
|
||||
/// Get the duration of one beat in seconds at the given beat position
|
||||
pub fn beat_duration(beat: f64, tempo_map: &TempoMap) -> f64 {
|
||||
60.0 / tempo_map.bpm_at(daw_backend::Beats(beat))
|
||||
}
|
||||
|
||||
/// Get the duration of one measure in seconds
|
||||
pub fn measure_duration(bpm: f64, time_sig: &TimeSignature) -> f64 {
|
||||
beat_duration(bpm) * time_sig.numerator as f64
|
||||
/// Get the duration of one measure in seconds at the given beat position
|
||||
pub fn measure_duration(beat: f64, tempo_map: &TempoMap, time_sig: &TimeSignature) -> f64 {
|
||||
beat_duration(beat, tempo_map) * time_sig.numerator as f64
|
||||
}
|
||||
|
||||
@@ -98,15 +98,20 @@ impl VectorClip {
|
||||
///
|
||||
/// The `clip_duration_fn` resolves referenced clip durations for non-vector layers.
|
||||
/// Falls back to the stored `duration` field if no content exists.
|
||||
pub fn content_duration(&self, framerate: f64) -> f64 {
|
||||
self.content_duration_with(framerate, |_| None)
|
||||
pub fn content_duration(&self, framerate: f64, tempo_map: &crate::tempo_map::TempoMap) -> f64 {
|
||||
self.content_duration_with(framerate, tempo_map, |_| None)
|
||||
}
|
||||
|
||||
/// Like `content_duration`, but with a closure that resolves clip durations
|
||||
/// for audio/video/effect clip instances inside this movie clip.
|
||||
pub fn content_duration_with(&self, framerate: f64, clip_duration_fn: impl Fn(&Uuid) -> Option<f64>) -> f64 {
|
||||
///
|
||||
/// `clip_duration_fn` returns clip content duration **in seconds**.
|
||||
/// Result is in **seconds**.
|
||||
pub fn content_duration_with(&self, framerate: f64, tempo_map: &crate::tempo_map::TempoMap, clip_duration_fn: impl Fn(&Uuid) -> Option<f64>) -> f64 {
|
||||
let frame_duration = 1.0 / framerate;
|
||||
let mut last_time: Option<f64> = None;
|
||||
// Work in beats, convert to seconds at the end.
|
||||
let mut last_beats: Option<f64> = None;
|
||||
let mut last_secs: Option<f64> = None;
|
||||
|
||||
for layer_node in self.layers.iter() {
|
||||
// Check clip instances on ALL layer types (vector, audio, video, effect)
|
||||
@@ -119,33 +124,38 @@ impl VectorClip {
|
||||
AnyLayer::Raster(_) => &[],
|
||||
};
|
||||
for ci in clip_instances {
|
||||
let end = if let Some(td) = ci.timeline_duration {
|
||||
ci.timeline_start + td
|
||||
// Compute end position of this clip instance in beats
|
||||
let end_beats = if let Some(td_beats) = ci.timeline_duration {
|
||||
ci.timeline_start + td_beats
|
||||
} else if let Some(te) = ci.trim_end {
|
||||
ci.timeline_start + (te - ci.trim_start).max(0.0)
|
||||
} else if let Some(clip_dur) = clip_duration_fn(&ci.clip_id) {
|
||||
ci.timeline_start + (clip_dur - ci.trim_start).max(0.0)
|
||||
let secs = (te - ci.trim_start).max(0.0);
|
||||
ci.timeline_start + tempo_map.inverse_transform(tempo_map.transform(ci.timeline_start) + secs) - ci.timeline_start
|
||||
} else if let Some(clip_dur_secs) = clip_duration_fn(&ci.clip_id) {
|
||||
let secs = (clip_dur_secs - ci.trim_start).max(0.0);
|
||||
ci.timeline_start + tempo_map.inverse_transform(tempo_map.transform(ci.timeline_start) + secs) - ci.timeline_start
|
||||
} else {
|
||||
continue;
|
||||
};
|
||||
last_time = Some(match last_time {
|
||||
Some(t) => t.max(end),
|
||||
None => end,
|
||||
});
|
||||
last_beats = Some(last_beats.map_or(end_beats, |t: f64| t.max(end_beats)));
|
||||
}
|
||||
|
||||
// Also check vector layer keyframes
|
||||
// Vector layer keyframes are in seconds
|
||||
if let AnyLayer::Vector(vector_layer) = &layer_node.data {
|
||||
if let Some(last_kf) = vector_layer.keyframes.last() {
|
||||
last_time = Some(match last_time {
|
||||
Some(t) => t.max(last_kf.time),
|
||||
None => last_kf.time,
|
||||
});
|
||||
last_secs = Some(last_secs.map_or(last_kf.time, |t: f64| t.max(last_kf.time)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
match last_time {
|
||||
let from_clips = last_beats.map(|b| tempo_map.transform(b));
|
||||
let combined = match (from_clips, last_secs) {
|
||||
(Some(a), Some(b)) => Some(a.max(b)),
|
||||
(Some(a), None) => Some(a),
|
||||
(None, Some(b)) => Some(b),
|
||||
(None, None) => None,
|
||||
};
|
||||
|
||||
match combined {
|
||||
Some(t) => t + frame_duration,
|
||||
None => self.duration,
|
||||
}
|
||||
@@ -186,9 +196,10 @@ impl VectorClip {
|
||||
|
||||
// Handle nested clip instances recursively
|
||||
for clip_instance in &vector_layer.clip_instances {
|
||||
// Convert parent clip time to nested clip local time
|
||||
// Apply timeline offset and playback speed, then add trim offset
|
||||
let nested_clip_time = ((clip_time - clip_instance.timeline_start) * clip_instance.playback_speed) + clip_instance.trim_start;
|
||||
// Convert parent clip time (seconds) to nested clip local time (seconds).
|
||||
// timeline_start is in beats; convert to seconds using document BPM.
|
||||
let start_secs = document.tempo_map().transform(clip_instance.timeline_start);
|
||||
let nested_clip_time = ((clip_time - start_secs) * clip_instance.playback_speed) + clip_instance.trim_start;
|
||||
|
||||
// Look up the nested clip definition
|
||||
let nested_bounds = if let Some(nested_clip) = document.get_vector_clip(&clip_instance.clip_id) {
|
||||
@@ -485,12 +496,12 @@ impl AudioClip {
|
||||
pub fn new_midi(
|
||||
name: impl Into<String>,
|
||||
midi_clip_id: u32,
|
||||
duration: f64,
|
||||
duration: daw_backend::Beats,
|
||||
) -> Self {
|
||||
Self {
|
||||
id: Uuid::new_v4(),
|
||||
name: name.into(),
|
||||
duration,
|
||||
duration: duration.beats_to_f64(),
|
||||
clip_type: AudioClipType::Midi { midi_clip_id },
|
||||
folder_id: None,
|
||||
}
|
||||
@@ -589,6 +600,12 @@ impl AnyClip {
|
||||
/// - Timeline placement (when this instance appears on the parent layer's timeline)
|
||||
/// - Trimming (trim_start, trim_end within the clip's internal content)
|
||||
/// - Playback speed (time remapping)
|
||||
///
|
||||
/// ## Coordinate systems
|
||||
/// - `timeline_start` / `timeline_duration` are in **beats** (quarter-note beats).
|
||||
/// Use [`crate::tempo_map::TempoMap::beats_to_seconds`] to convert to seconds.
|
||||
/// - `trim_start` / `trim_end` are in **seconds** (audio/video file seek offsets;
|
||||
/// not affected by BPM changes).
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct ClipInstance {
|
||||
/// Unique identifier for this instance
|
||||
@@ -606,52 +623,25 @@ pub struct ClipInstance {
|
||||
/// Optional name for this instance
|
||||
pub name: Option<String>,
|
||||
|
||||
/// When this instance starts on the timeline (in seconds, relative to parent layer)
|
||||
/// This is the external positioning - where the instance appears on the timeline
|
||||
/// Default: 0.0 (start at beginning of layer)
|
||||
/// When this instance starts on the timeline, in **beats**.
|
||||
/// Default: 0.0
|
||||
pub timeline_start: f64,
|
||||
/// timeline_start in beats (quarter-note beats); derived from timeline_start
|
||||
#[serde(default)]
|
||||
pub timeline_start_beats: f64,
|
||||
/// timeline_start in frames; derived from timeline_start
|
||||
#[serde(default)]
|
||||
pub timeline_start_frames: f64,
|
||||
|
||||
/// How long this instance appears on the timeline (in seconds)
|
||||
/// If timeline_duration > (trim_end - trim_start), the trimmed content will loop
|
||||
/// How long this instance appears on the timeline, in **beats**.
|
||||
/// If set and longer than the trimmed content, the content will loop.
|
||||
/// Default: None (use trimmed clip duration, no looping)
|
||||
pub timeline_duration: Option<f64>,
|
||||
/// timeline_duration in beats; derived from timeline_duration
|
||||
#[serde(default)]
|
||||
pub timeline_duration_beats: Option<f64>,
|
||||
/// timeline_duration in frames; derived from timeline_duration
|
||||
#[serde(default)]
|
||||
pub timeline_duration_frames: Option<f64>,
|
||||
|
||||
/// Trim start: offset into the clip's internal content (in seconds)
|
||||
/// Allows trimming the beginning of the clip
|
||||
/// - For audio: offset into the audio file
|
||||
/// - For video: offset into the video file
|
||||
/// - For vector: offset into the animation timeline
|
||||
/// Default: 0.0 (start at beginning of clip)
|
||||
/// Trim start: offset into the clip's internal content, in **seconds**.
|
||||
/// - For audio: byte-offset into the audio file
|
||||
/// - For video: seek position in the video file
|
||||
/// - For vector: time offset into the animation
|
||||
/// Default: 0.0
|
||||
pub trim_start: f64,
|
||||
/// trim_start in beats; derived from trim_start
|
||||
#[serde(default)]
|
||||
pub trim_start_beats: f64,
|
||||
/// trim_start in frames; derived from trim_start
|
||||
#[serde(default)]
|
||||
pub trim_start_frames: f64,
|
||||
|
||||
/// Trim end: offset into the clip's internal content (in seconds)
|
||||
/// Allows trimming the end of the clip
|
||||
/// Trim end: offset into the clip's internal content, in **seconds**.
|
||||
/// Default: None (use full clip duration)
|
||||
pub trim_end: Option<f64>,
|
||||
/// trim_end in beats; derived from trim_end
|
||||
#[serde(default)]
|
||||
pub trim_end_beats: Option<f64>,
|
||||
/// trim_end in frames; derived from trim_end
|
||||
#[serde(default)]
|
||||
pub trim_end_frames: Option<f64>,
|
||||
|
||||
/// Playback speed multiplier
|
||||
/// 1.0 = normal speed, 0.5 = half speed, 2.0 = double speed
|
||||
@@ -663,7 +653,7 @@ pub struct ClipInstance {
|
||||
/// Default: 1.0
|
||||
pub gain: f32,
|
||||
|
||||
/// How far (in seconds) the looped content extends before timeline_start.
|
||||
/// How far (in beats) the looped content extends before timeline_start.
|
||||
/// When set, loop iterations are drawn/played before the content start.
|
||||
/// Default: None (no pre-loop)
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
@@ -720,17 +710,9 @@ impl ClipInstance {
|
||||
opacity: 1.0,
|
||||
name: None,
|
||||
timeline_start: 0.0,
|
||||
timeline_start_beats: 0.0,
|
||||
timeline_start_frames: 0.0,
|
||||
timeline_duration: None,
|
||||
timeline_duration_beats: None,
|
||||
timeline_duration_frames: None,
|
||||
trim_start: 0.0,
|
||||
trim_start_beats: 0.0,
|
||||
trim_start_frames: 0.0,
|
||||
trim_end: None,
|
||||
trim_end_beats: None,
|
||||
trim_end_frames: None,
|
||||
playback_speed: 1.0,
|
||||
gain: 1.0,
|
||||
loop_before: None,
|
||||
@@ -746,71 +728,15 @@ impl ClipInstance {
|
||||
opacity: 1.0,
|
||||
name: None,
|
||||
timeline_start: 0.0,
|
||||
timeline_start_beats: 0.0,
|
||||
timeline_start_frames: 0.0,
|
||||
timeline_duration: None,
|
||||
timeline_duration_beats: None,
|
||||
timeline_duration_frames: None,
|
||||
trim_start: 0.0,
|
||||
trim_start_beats: 0.0,
|
||||
trim_start_frames: 0.0,
|
||||
trim_end: None,
|
||||
trim_end_beats: None,
|
||||
trim_end_frames: None,
|
||||
playback_speed: 1.0,
|
||||
gain: 1.0,
|
||||
loop_before: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Sync beats and frames from the seconds fields (call after any seconds-based write).
|
||||
pub fn sync_from_seconds(&mut self, bpm: f64, fps: f64) {
|
||||
self.timeline_start_beats = self.timeline_start * bpm / 60.0;
|
||||
self.timeline_start_frames = self.timeline_start * fps;
|
||||
self.trim_start_beats = self.trim_start * bpm / 60.0;
|
||||
self.trim_start_frames = self.trim_start * fps;
|
||||
self.trim_end_beats = self.trim_end.map(|v| v * bpm / 60.0);
|
||||
self.trim_end_frames = self.trim_end.map(|v| v * fps);
|
||||
self.timeline_duration_beats = self.timeline_duration.map(|v| v * bpm / 60.0);
|
||||
self.timeline_duration_frames = self.timeline_duration.map(|v| v * fps);
|
||||
}
|
||||
|
||||
/// Recompute seconds and frames from beats (call when BPM changes in Measures mode).
|
||||
pub fn apply_beats(&mut self, bpm: f64, fps: f64) {
|
||||
self.timeline_start = self.timeline_start_beats * 60.0 / bpm;
|
||||
self.timeline_start_frames = self.timeline_start * fps;
|
||||
self.trim_start = self.trim_start_beats * 60.0 / bpm;
|
||||
self.trim_start_frames = self.trim_start * fps;
|
||||
if let Some(b) = self.trim_end_beats {
|
||||
let s = b * 60.0 / bpm;
|
||||
self.trim_end = Some(s);
|
||||
self.trim_end_frames = Some(s * fps);
|
||||
}
|
||||
if let Some(b) = self.timeline_duration_beats {
|
||||
let s = b * 60.0 / bpm;
|
||||
self.timeline_duration = Some(s);
|
||||
self.timeline_duration_frames = Some(s * fps);
|
||||
}
|
||||
}
|
||||
|
||||
/// Recompute seconds and beats from frames (call when FPS changes in Frames mode).
|
||||
pub fn apply_frames(&mut self, fps: f64, bpm: f64) {
|
||||
self.timeline_start = self.timeline_start_frames / fps;
|
||||
self.timeline_start_beats = self.timeline_start * bpm / 60.0;
|
||||
self.trim_start = self.trim_start_frames / fps;
|
||||
self.trim_start_beats = self.trim_start * bpm / 60.0;
|
||||
if let Some(f) = self.trim_end_frames {
|
||||
let s = f / fps;
|
||||
self.trim_end = Some(s);
|
||||
self.trim_end_beats = Some(s * bpm / 60.0);
|
||||
}
|
||||
if let Some(f) = self.timeline_duration_frames {
|
||||
let s = f / fps;
|
||||
self.timeline_duration = Some(s);
|
||||
self.timeline_duration_beats = Some(s * bpm / 60.0);
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the transform
|
||||
pub fn with_transform(mut self, transform: Transform) -> Self {
|
||||
self.transform = transform;
|
||||
@@ -861,83 +787,83 @@ impl ClipInstance {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set explicit timeline duration by setting trim_end
|
||||
///
|
||||
/// For effect instances, this effectively sets the duration since
|
||||
/// effects have infinite internal duration (trim_start defaults to 0).
|
||||
pub fn with_timeline_duration(mut self, duration: f64) -> Self {
|
||||
self.trim_end = Some(self.trim_start + duration);
|
||||
/// Set explicit timeline duration (in beats) by directly setting `timeline_duration`.
|
||||
pub fn with_timeline_duration(mut self, duration_beats: f64) -> Self {
|
||||
self.timeline_duration = Some(duration_beats);
|
||||
self
|
||||
}
|
||||
|
||||
/// Get the effective duration of this instance (accounting for trimming and looping)
|
||||
/// If timeline_duration is set, returns that (enabling content looping)
|
||||
/// Otherwise returns the trimmed content duration
|
||||
pub fn effective_duration(&self, clip_duration: f64) -> f64 {
|
||||
// If timeline_duration is explicitly set, use that (for looping)
|
||||
if let Some(timeline_dur) = self.timeline_duration {
|
||||
return timeline_dur;
|
||||
}
|
||||
|
||||
// Otherwise, return the trimmed content duration
|
||||
let end = self.trim_end.unwrap_or(clip_duration);
|
||||
/// Content window size in seconds: `trim_end - trim_start`.
|
||||
/// Used for internal looping calculations.
|
||||
pub fn content_window_secs(&self, clip_duration_secs: f64) -> f64 {
|
||||
let end = self.trim_end.unwrap_or(clip_duration_secs);
|
||||
(end - self.trim_start).max(0.0)
|
||||
}
|
||||
|
||||
/// Get the effective start position on the timeline, accounting for loop_before.
|
||||
/// This is the left edge of the clip's visual extent.
|
||||
/// How long this instance appears on the timeline, in **beats**.
|
||||
///
|
||||
/// If `timeline_duration` is set, returns that (enabling content looping).
|
||||
/// Otherwise converts the content window from seconds to beats using the tempo map.
|
||||
pub fn effective_duration_beats(&self, clip_duration_secs: f64, tempo_map: &crate::tempo_map::TempoMap) -> f64 {
|
||||
if let Some(td) = self.timeline_duration {
|
||||
return td;
|
||||
}
|
||||
let window_secs = self.content_window_secs(clip_duration_secs);
|
||||
let start_secs = tempo_map.transform(self.timeline_start);
|
||||
tempo_map.inverse_transform(start_secs + window_secs) - self.timeline_start
|
||||
}
|
||||
|
||||
/// Left edge of the clip's visual extent on the timeline, in **beats**.
|
||||
pub fn effective_start(&self) -> f64 {
|
||||
self.timeline_start - self.loop_before.unwrap_or(0.0)
|
||||
}
|
||||
|
||||
/// Get the total visual duration including both loop_before and effective_duration.
|
||||
pub fn total_duration(&self, clip_duration: f64) -> f64 {
|
||||
self.loop_before.unwrap_or(0.0) + self.effective_duration(clip_duration)
|
||||
/// Total visual duration (loop_before + effective_duration), in **beats**.
|
||||
pub fn total_duration(&self, clip_duration_secs: f64, tempo_map: &crate::tempo_map::TempoMap) -> f64 {
|
||||
self.loop_before.unwrap_or(0.0) + self.effective_duration_beats(clip_duration_secs, tempo_map)
|
||||
}
|
||||
|
||||
/// Remap timeline time to clip content time
|
||||
/// Map a playback time (in **seconds**) to clip-local content time (in **seconds**).
|
||||
///
|
||||
/// Takes a global timeline time and returns the corresponding time within this
|
||||
/// clip's content, accounting for:
|
||||
/// - Instance position (timeline_start)
|
||||
/// - Playback speed
|
||||
/// - Trimming (trim_start, trim_end)
|
||||
/// - Looping (if timeline_duration > content window)
|
||||
///
|
||||
/// Returns None if the clip instance is not active at the given timeline time.
|
||||
pub fn remap_time(&self, timeline_time: f64, clip_duration: f64) -> Option<f64> {
|
||||
// Check if clip instance is active at this time
|
||||
let instance_end = self.timeline_start + self.effective_duration(clip_duration);
|
||||
if timeline_time < self.timeline_start || timeline_time >= instance_end {
|
||||
/// Returns `None` if the clip instance is not active at `time_secs`.
|
||||
pub fn remap_time_secs(&self, time_secs: f64, clip_duration_secs: f64, tempo_map: &crate::tempo_map::TempoMap) -> Option<f64> {
|
||||
let start_secs = tempo_map.transform(self.timeline_start);
|
||||
let dur_beats = self.effective_duration_beats(clip_duration_secs, tempo_map);
|
||||
let end_secs = tempo_map.transform(self.timeline_start + dur_beats);
|
||||
|
||||
if time_secs < start_secs || time_secs >= end_secs {
|
||||
return None;
|
||||
}
|
||||
|
||||
// Calculate relative time within the instance (0.0 = start of instance)
|
||||
let relative_time = timeline_time - self.timeline_start;
|
||||
let relative_secs = time_secs - start_secs;
|
||||
let content_time = relative_secs * self.playback_speed;
|
||||
let content_window = self.content_window_secs(clip_duration_secs);
|
||||
|
||||
// Account for playback speed
|
||||
let content_time = relative_time * self.playback_speed;
|
||||
|
||||
// Get the content window size (the portion of clip we're sampling)
|
||||
let trim_end = self.trim_end.unwrap_or(clip_duration);
|
||||
let content_window = (trim_end - self.trim_start).max(0.0);
|
||||
|
||||
// If content_window is zero, can't sample anything
|
||||
if content_window == 0.0 {
|
||||
return Some(self.trim_start);
|
||||
}
|
||||
|
||||
// Apply looping if content exceeds the window
|
||||
let looped_time = if content_time > content_window {
|
||||
content_time % content_window
|
||||
} else {
|
||||
content_time
|
||||
};
|
||||
|
||||
// Add trim_start offset to get final clip time
|
||||
Some(self.trim_start + looped_time)
|
||||
}
|
||||
|
||||
/// Alias for `remap_time_secs`.
|
||||
#[inline]
|
||||
pub fn remap_time(&self, time_secs: f64, clip_duration_secs: f64, tempo_map: &crate::tempo_map::TempoMap) -> Option<f64> {
|
||||
self.remap_time_secs(time_secs, clip_duration_secs, tempo_map)
|
||||
}
|
||||
|
||||
/// Alias for `effective_duration_beats`.
|
||||
#[inline]
|
||||
pub fn effective_duration(&self, clip_duration_secs: f64, tempo_map: &crate::tempo_map::TempoMap) -> f64 {
|
||||
self.effective_duration_beats(clip_duration_secs, tempo_map)
|
||||
}
|
||||
|
||||
/// Convert to affine transform
|
||||
pub fn to_affine(&self) -> vello::kurbo::Affine {
|
||||
self.transform.to_affine()
|
||||
|
||||
@@ -6,10 +6,11 @@
|
||||
use crate::asset_folder::AssetFolderTree;
|
||||
use crate::clip::{AudioClip, ClipInstance, ImageAsset, VideoClip, VectorClip};
|
||||
use crate::effect::EffectDefinition;
|
||||
use crate::layer::AnyLayer;
|
||||
use crate::layer::{AnyLayer, GroupLayer};
|
||||
use crate::script::ScriptDefinition;
|
||||
use crate::layout::LayoutNode;
|
||||
use crate::shape::ShapeColor;
|
||||
use crate::tempo_map::TempoMap;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use uuid::Uuid;
|
||||
@@ -131,6 +132,8 @@ impl Default for TimeSignature {
|
||||
}
|
||||
}
|
||||
|
||||
// Keep for backward serde compat (old files may have a `bpm` field); no longer used.
|
||||
#[allow(dead_code)]
|
||||
fn default_bpm() -> f64 { 120.0 }
|
||||
|
||||
/// How time is displayed in the timeline
|
||||
@@ -173,14 +176,16 @@ pub struct Document {
|
||||
/// Framerate (frames per second)
|
||||
pub framerate: f64,
|
||||
|
||||
/// Tempo in beats per minute
|
||||
#[serde(default = "default_bpm")]
|
||||
pub bpm: f64,
|
||||
|
||||
/// Time signature
|
||||
#[serde(default)]
|
||||
pub time_signature: TimeSignature,
|
||||
|
||||
/// Master track (master bus + tempo automation lane).
|
||||
/// Stored separately from the root layer tree; shown in timeline when
|
||||
/// `show_master_track` is enabled in the editor state.
|
||||
#[serde(default)]
|
||||
pub master_layer: GroupLayer,
|
||||
|
||||
/// Duration in seconds
|
||||
pub duration: f64,
|
||||
|
||||
@@ -266,8 +271,12 @@ impl Default for Document {
|
||||
width: 1920.0,
|
||||
height: 1080.0,
|
||||
framerate: 60.0,
|
||||
bpm: 120.0,
|
||||
time_signature: TimeSignature::default(),
|
||||
master_layer: {
|
||||
let mut ml = GroupLayer::new_master(120.0);
|
||||
ml.layer.id = uuid::Uuid::new_v4();
|
||||
ml
|
||||
},
|
||||
duration: 10.0,
|
||||
root: GraphicsObject::default(),
|
||||
vector_clips: HashMap::new(),
|
||||
@@ -311,6 +320,28 @@ impl Document {
|
||||
}
|
||||
}
|
||||
|
||||
/// Reference to the document's tempo map (stored on the master layer).
|
||||
pub fn tempo_map(&self) -> &TempoMap {
|
||||
self.master_layer.tempo_map.as_ref()
|
||||
.expect("master_layer always has a tempo_map")
|
||||
}
|
||||
|
||||
/// Mutable reference to the document's tempo map.
|
||||
pub fn tempo_map_mut(&mut self) -> &mut TempoMap {
|
||||
self.master_layer.tempo_map.as_mut()
|
||||
.expect("master_layer always has a tempo_map")
|
||||
}
|
||||
|
||||
/// Convenience accessor for the global BPM (first entry of the tempo map).
|
||||
pub fn bpm(&self) -> f64 {
|
||||
self.tempo_map().global_bpm()
|
||||
}
|
||||
|
||||
/// Set the global BPM. Rebuilds the tempo map's seconds cache.
|
||||
pub fn set_bpm(&mut self, bpm: f64) {
|
||||
self.tempo_map_mut().set_global_bpm(bpm);
|
||||
}
|
||||
|
||||
/// Rebuild the layer→clip reverse lookup map from all vector clips.
|
||||
/// Call after deserialization or bulk clip modifications.
|
||||
pub fn rebuild_layer_to_clip_map(&mut self) {
|
||||
@@ -619,56 +650,6 @@ impl Document {
|
||||
layers
|
||||
}
|
||||
|
||||
/// Migrate old documents: compute beats/frames from seconds for any ClipInstance whose
|
||||
/// derived fields are still zero (i.e., documents saved before triple-representation).
|
||||
/// Call once after loading a document.
|
||||
pub fn sync_all_clip_positions(&mut self) {
|
||||
let bpm = self.bpm;
|
||||
let fps = self.framerate;
|
||||
|
||||
fn sync_list(list: &mut [crate::layer::AnyLayer], bpm: f64, fps: f64) {
|
||||
for layer in list.iter_mut() {
|
||||
match layer {
|
||||
crate::layer::AnyLayer::Vector(vl) => {
|
||||
for ci in &mut vl.clip_instances {
|
||||
if ci.timeline_start_beats == 0.0 { ci.sync_from_seconds(bpm, fps); }
|
||||
}
|
||||
}
|
||||
crate::layer::AnyLayer::Audio(al) => {
|
||||
for ci in &mut al.clip_instances {
|
||||
if ci.timeline_start_beats == 0.0 { ci.sync_from_seconds(bpm, fps); }
|
||||
}
|
||||
}
|
||||
crate::layer::AnyLayer::Video(vl) => {
|
||||
for ci in &mut vl.clip_instances {
|
||||
if ci.timeline_start_beats == 0.0 { ci.sync_from_seconds(bpm, fps); }
|
||||
}
|
||||
}
|
||||
crate::layer::AnyLayer::Effect(el) => {
|
||||
for ci in &mut el.clip_instances {
|
||||
if ci.timeline_start_beats == 0.0 { ci.sync_from_seconds(bpm, fps); }
|
||||
}
|
||||
}
|
||||
crate::layer::AnyLayer::Group(g) => {
|
||||
sync_list(&mut g.children, bpm, fps);
|
||||
}
|
||||
crate::layer::AnyLayer::Raster(_) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sync_list(&mut self.root.children, bpm, fps);
|
||||
for clip in self.vector_clips.values_mut() {
|
||||
for node in &mut clip.layers.roots {
|
||||
if let crate::layer::AnyLayer::Vector(vl) = &mut node.data {
|
||||
for ci in &mut vl.clip_instances {
|
||||
if ci.timeline_start_beats == 0.0 { ci.sync_from_seconds(bpm, fps); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// === CLIP LIBRARY METHODS ===
|
||||
|
||||
/// Add a vector clip to the library
|
||||
@@ -866,11 +847,12 @@ impl Document {
|
||||
if clip.is_group {
|
||||
Some(clip.duration)
|
||||
} else {
|
||||
Some(clip.content_duration_with(self.framerate, |id| {
|
||||
let tempo_map = self.tempo_map();
|
||||
Some(clip.content_duration_with(self.framerate, tempo_map, |id| {
|
||||
// Resolve nested clip durations (audio, video, other vector clips)
|
||||
if let Some(vc) = self.vector_clips.get(id) {
|
||||
// Avoid deep recursion — use stored duration for nested vector clips
|
||||
Some(vc.content_duration(self.framerate))
|
||||
Some(vc.content_duration(self.framerate, tempo_map))
|
||||
} else if let Some(ac) = self.audio_clips.get(id) {
|
||||
Some(ac.duration)
|
||||
} else if let Some(vc) = self.video_clips.get(id) {
|
||||
@@ -961,7 +943,7 @@ impl Document {
|
||||
};
|
||||
|
||||
let instance_start = instance.effective_start();
|
||||
let instance_end = instance.timeline_start + instance.effective_duration(clip_duration);
|
||||
let instance_end = instance.timeline_start + instance.effective_duration(clip_duration, self.tempo_map());
|
||||
|
||||
// Check overlap: start_a < end_b AND start_b < end_a
|
||||
if start_time < instance_end && instance_start < end_time {
|
||||
@@ -1019,7 +1001,7 @@ impl Document {
|
||||
|
||||
if let Some(clip_dur) = self.get_clip_duration(&instance.clip_id) {
|
||||
let inst_start = instance.effective_start();
|
||||
let inst_end = instance.timeline_start + instance.effective_duration(clip_dur);
|
||||
let inst_end = instance.timeline_start + instance.effective_duration(clip_dur, self.tempo_map());
|
||||
occupied_ranges.push((inst_start, inst_end, instance.id));
|
||||
}
|
||||
}
|
||||
@@ -1114,7 +1096,7 @@ impl Document {
|
||||
}
|
||||
if let Some(dur) = self.get_clip_duration(&inst.clip_id) {
|
||||
let start = inst.effective_start();
|
||||
let end = inst.timeline_start + inst.effective_duration(dur);
|
||||
let end = inst.timeline_start + inst.effective_duration(dur, self.tempo_map());
|
||||
non_group.push((start, end));
|
||||
}
|
||||
}
|
||||
@@ -1184,7 +1166,7 @@ impl Document {
|
||||
|
||||
// Calculate other clip's extent (accounting for loop_before)
|
||||
if let Some(clip_duration) = self.get_clip_duration(&other.clip_id) {
|
||||
let other_end = other.timeline_start + other.effective_duration(clip_duration);
|
||||
let other_end = other.timeline_start + other.effective_duration(clip_duration, self.tempo_map());
|
||||
|
||||
// If this clip is to the left and closer than current nearest
|
||||
if other_end <= current_timeline_start && other_end > nearest_end {
|
||||
@@ -1280,7 +1262,7 @@ impl Document {
|
||||
}
|
||||
|
||||
if let Some(clip_duration) = self.get_clip_duration(&other.clip_id) {
|
||||
let other_end = other.timeline_start + other.effective_duration(clip_duration);
|
||||
let other_end = other.timeline_start + other.effective_duration(clip_duration, self.tempo_map());
|
||||
|
||||
if other_end <= current_effective_start && other_end > nearest_end {
|
||||
nearest_end = other_end;
|
||||
|
||||
@@ -142,16 +142,18 @@ impl EffectLayer {
|
||||
self.clip_instances.iter_mut().find(|e| &e.id == id)
|
||||
}
|
||||
|
||||
/// Get all clip instances (effects) that are active at a given time
|
||||
/// Get all clip instances (effects) that are active at a given time.
|
||||
///
|
||||
/// Uses `EFFECT_DURATION` to calculate effective duration for each instance.
|
||||
pub fn active_clip_instances_at(&self, time: f64) -> Vec<&ClipInstance> {
|
||||
/// `time_secs` is the playback time in seconds; `bpm` is used to convert
|
||||
/// `timeline_start` (beats) to seconds for comparison.
|
||||
pub fn active_clip_instances_at(&self, time_secs: f64, tempo_map: &crate::tempo_map::TempoMap) -> Vec<&ClipInstance> {
|
||||
use crate::effect::EFFECT_DURATION;
|
||||
let time_beats = tempo_map.inverse_transform(time_secs);
|
||||
self.clip_instances
|
||||
.iter()
|
||||
.filter(|e| {
|
||||
let end = e.timeline_start + e.effective_duration(EFFECT_DURATION);
|
||||
time >= e.timeline_start && time < end
|
||||
let end = e.timeline_start + e.effective_duration(EFFECT_DURATION, tempo_map);
|
||||
time_beats >= e.timeline_start && time_beats < end
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
@@ -239,13 +241,13 @@ mod tests {
|
||||
layer.add_clip_instance(effect2);
|
||||
|
||||
// At time 2: only effect1 active
|
||||
assert_eq!(layer.active_clip_instances_at(2.0).len(), 1);
|
||||
assert_eq!(layer.active_clip_instances_at(2.0, 60.0).len(), 1);
|
||||
|
||||
// At time 4: both effects active
|
||||
assert_eq!(layer.active_clip_instances_at(4.0).len(), 2);
|
||||
assert_eq!(layer.active_clip_instances_at(4.0, 60.0).len(), 2);
|
||||
|
||||
// At time 7: only effect2 active
|
||||
assert_eq!(layer.active_clip_instances_at(7.0).len(), 1);
|
||||
assert_eq!(layer.active_clip_instances_at(7.0, 60.0).len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -76,6 +76,9 @@ pub struct AudioExportSettings {
|
||||
|
||||
/// End time in seconds
|
||||
pub end_time: f64,
|
||||
|
||||
/// Project BPM (for beat-position scheduling during export)
|
||||
pub bpm: f64,
|
||||
}
|
||||
|
||||
impl Default for AudioExportSettings {
|
||||
@@ -88,6 +91,7 @@ impl Default for AudioExportSettings {
|
||||
bitrate_kbps: 320,
|
||||
start_time: 0.0,
|
||||
end_time: 60.0,
|
||||
bpm: 120.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -491,6 +491,8 @@ pub fn load_beam(path: &Path) -> Result<LoadedProject, String> {
|
||||
// 5. Extract document and audio backend state
|
||||
let step5_start = std::time::Instant::now();
|
||||
let mut document = beam_project.ui_state;
|
||||
// Rebuild derived seconds cache on all TempoMap entries after deserialization.
|
||||
document.tempo_map_mut().rebuild_seconds();
|
||||
let mut audio_project = beam_project.audio_backend.project;
|
||||
let audio_pool_entries = beam_project.audio_backend.audio_pool_entries;
|
||||
let layer_to_track_map = beam_project.audio_backend.layer_to_track_map;
|
||||
|
||||
@@ -256,15 +256,20 @@ pub fn hit_test_clip_instances(
|
||||
parent_transform: Affine,
|
||||
timeline_time: f64,
|
||||
) -> Option<Uuid> {
|
||||
let tempo_map = document.tempo_map();
|
||||
for clip_instance in clip_instances.iter().rev() {
|
||||
// Check time bounds: skip clip instances not active at this time
|
||||
// timeline_start/instance_end are in beats; convert timeline_time (seconds) to beats.
|
||||
let clip_duration = document.get_clip_duration(&clip_instance.clip_id).unwrap_or(0.0);
|
||||
let instance_end = clip_instance.timeline_start + clip_instance.effective_duration(clip_duration);
|
||||
if timeline_time < clip_instance.timeline_start || timeline_time >= instance_end {
|
||||
let instance_end = clip_instance.timeline_start + clip_instance.effective_duration(clip_duration, tempo_map);
|
||||
let timeline_beats = tempo_map.inverse_transform(timeline_time);
|
||||
if timeline_beats < clip_instance.timeline_start || timeline_beats >= instance_end {
|
||||
continue;
|
||||
}
|
||||
|
||||
let clip_time = ((timeline_time - clip_instance.timeline_start) * clip_instance.playback_speed) + clip_instance.trim_start;
|
||||
// clip_time is in seconds; offset from clip start (in seconds) + trim_start (seconds)
|
||||
let start_secs = tempo_map.transform(clip_instance.timeline_start);
|
||||
let clip_time = ((timeline_time - start_secs) * clip_instance.playback_speed) + clip_instance.trim_start;
|
||||
|
||||
let content_bounds = if let Some(vector_clip) = document.get_vector_clip(&clip_instance.clip_id) {
|
||||
vector_clip.calculate_content_bounds(document, clip_time)
|
||||
@@ -294,16 +299,20 @@ pub fn hit_test_clip_instances_in_rect(
|
||||
timeline_time: f64,
|
||||
) -> Vec<Uuid> {
|
||||
let mut hits = Vec::new();
|
||||
let tempo_map = document.tempo_map();
|
||||
|
||||
for clip_instance in clip_instances {
|
||||
// Check time bounds: skip clip instances not active at this time
|
||||
// timeline_start/instance_end are in beats; convert timeline_time (seconds) to beats.
|
||||
let clip_duration = document.get_clip_duration(&clip_instance.clip_id).unwrap_or(0.0);
|
||||
let instance_end = clip_instance.timeline_start + clip_instance.effective_duration(clip_duration);
|
||||
if timeline_time < clip_instance.timeline_start || timeline_time >= instance_end {
|
||||
let instance_end = clip_instance.timeline_start + clip_instance.effective_duration(clip_duration, tempo_map);
|
||||
let timeline_beats = tempo_map.inverse_transform(timeline_time);
|
||||
if timeline_beats < clip_instance.timeline_start || timeline_beats >= instance_end {
|
||||
continue;
|
||||
}
|
||||
|
||||
let clip_time = ((timeline_time - clip_instance.timeline_start) * clip_instance.playback_speed) + clip_instance.trim_start;
|
||||
let start_secs = tempo_map.transform(clip_instance.timeline_start);
|
||||
let clip_time = ((timeline_time - start_secs) * clip_instance.playback_speed) + clip_instance.trim_start;
|
||||
|
||||
let content_bounds = if let Some(vector_clip) = document.get_vector_clip(&clip_instance.clip_id) {
|
||||
vector_clip.calculate_content_bounds(document, clip_time)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
//! Layers organize objects and shapes, and contain animation data.
|
||||
|
||||
use crate::animation::AnimationData;
|
||||
use crate::tempo_map::TempoMap;
|
||||
use crate::clip::ClipInstance;
|
||||
use crate::vector_graph::VectorGraph;
|
||||
use crate::effect_layer::EffectLayer;
|
||||
@@ -720,6 +721,12 @@ pub struct GroupLayer {
|
||||
/// Whether the group is expanded in the timeline
|
||||
#[serde(default = "default_true")]
|
||||
pub expanded: bool,
|
||||
|
||||
/// Optional tempo map for this group. When `Some`, the group's children use
|
||||
/// this tempo map for beat-to-parent-time conversion. The master group always
|
||||
/// has `Some`; regular groups default to `None` (inherit parent tempo).
|
||||
#[serde(default)]
|
||||
pub tempo_map: Option<TempoMap>,
|
||||
}
|
||||
|
||||
fn default_true() -> bool {
|
||||
@@ -746,6 +753,12 @@ impl LayerTrait for GroupLayer {
|
||||
fn set_locked(&mut self, locked: bool) { self.layer.locked = locked; }
|
||||
}
|
||||
|
||||
impl Default for GroupLayer {
|
||||
fn default() -> Self {
|
||||
Self::new("Group")
|
||||
}
|
||||
}
|
||||
|
||||
impl GroupLayer {
|
||||
/// Create a new group layer
|
||||
pub fn new(name: impl Into<String>) -> Self {
|
||||
@@ -753,6 +766,21 @@ impl GroupLayer {
|
||||
layer: Layer::new(LayerType::Group, name),
|
||||
children: Vec::new(),
|
||||
expanded: true,
|
||||
tempo_map: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a master group layer with a constant tempo.
|
||||
pub fn new_master(bpm: f64) -> Self {
|
||||
Self {
|
||||
layer: Layer::with_id(
|
||||
uuid::Uuid::nil(), // replaced by Document::new
|
||||
LayerType::Group,
|
||||
"Master",
|
||||
),
|
||||
children: Vec::new(),
|
||||
expanded: true,
|
||||
tempo_map: Some(TempoMap::constant(bpm)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -773,7 +801,7 @@ impl GroupLayer {
|
||||
AnyLayer::Effect(l) => &l.clip_instances,
|
||||
AnyLayer::Group(_) => &[], // no nested groups
|
||||
AnyLayer::Raster(_) => &[], // raster layers have no clip instances
|
||||
};
|
||||
};
|
||||
for ci in instances {
|
||||
result.push((child_id, ci));
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Shared data structures and types
|
||||
|
||||
pub mod beat_time;
|
||||
pub mod tempo_map;
|
||||
pub mod gpu;
|
||||
pub mod layout;
|
||||
pub mod pane;
|
||||
|
||||
@@ -391,9 +391,10 @@ pub fn render_layer_isolated(
|
||||
let mut video_mgr = video_manager.lock().unwrap();
|
||||
let mut instances = Vec::new();
|
||||
|
||||
let tempo_map = document.tempo_map();
|
||||
for clip_instance in &video_layer.clip_instances {
|
||||
let Some(video_clip) = document.video_clips.get(&clip_instance.clip_id) else { continue };
|
||||
let Some(clip_time) = clip_instance.remap_time(time, video_clip.duration) else { continue };
|
||||
let Some(clip_time) = clip_instance.remap_time(time, video_clip.duration, tempo_map) else { continue };
|
||||
let Some(frame) = video_mgr.get_frame(&clip_instance.clip_id, clip_time) else { continue };
|
||||
|
||||
// Evaluate animated transform properties.
|
||||
@@ -458,8 +459,9 @@ pub fn render_layer_isolated(
|
||||
AnyLayer::Effect(effect_layer) => {
|
||||
// Effect layers are processed during compositing, not rendered to scene
|
||||
// Return early with a dedicated effect layer type
|
||||
let tempo_map = document.tempo_map();
|
||||
let active_effects: Vec<ClipInstance> = effect_layer
|
||||
.active_clip_instances_at(time)
|
||||
.active_clip_instances_at(time, tempo_map)
|
||||
.into_iter()
|
||||
.cloned()
|
||||
.collect();
|
||||
@@ -728,16 +730,19 @@ fn render_clip_instance(
|
||||
};
|
||||
|
||||
// Remap timeline time to clip's internal time
|
||||
let tempo_map = document.tempo_map();
|
||||
let clip_time = if vector_clip.is_group {
|
||||
// Groups are static — visible from timeline_start to the next keyframe boundary
|
||||
let end = group_end_time.unwrap_or(clip_instance.timeline_start);
|
||||
if time < clip_instance.timeline_start || time >= end {
|
||||
// Groups are static — visible from timeline_start to the next keyframe boundary.
|
||||
// timeline_start is in beats; group_end_time is in seconds (render time).
|
||||
let start_secs = tempo_map.transform(clip_instance.timeline_start);
|
||||
let end = group_end_time.unwrap_or(start_secs);
|
||||
if time < start_secs || time >= end {
|
||||
return;
|
||||
}
|
||||
0.0
|
||||
} else {
|
||||
let clip_dur = document.get_clip_duration(&vector_clip.id).unwrap_or(vector_clip.duration);
|
||||
let Some(t) = clip_instance.remap_time(time, clip_dur) else {
|
||||
let Some(t) = clip_instance.remap_time(time, clip_dur, tempo_map) else {
|
||||
return; // Clip instance not active at this time
|
||||
};
|
||||
t
|
||||
@@ -889,7 +894,8 @@ fn render_video_layer(
|
||||
};
|
||||
|
||||
// Remap timeline time to clip's internal time
|
||||
let Some(clip_time) = clip_instance.remap_time(time, video_clip.duration) else {
|
||||
let tempo_map = document.tempo_map();
|
||||
let Some(clip_time) = clip_instance.remap_time(time, video_clip.duration, tempo_map) else {
|
||||
continue; // Clip instance not active at this time
|
||||
};
|
||||
|
||||
@@ -1553,13 +1559,15 @@ fn render_clip_instance_cpu(
|
||||
) {
|
||||
let Some(vector_clip) = document.vector_clips.get(&clip_instance.clip_id) else { return };
|
||||
|
||||
let tempo_map = document.tempo_map();
|
||||
let clip_time = if vector_clip.is_group {
|
||||
let end = group_end_time.unwrap_or(clip_instance.timeline_start);
|
||||
if time < clip_instance.timeline_start || time >= end { return; }
|
||||
let start_secs = tempo_map.transform(clip_instance.timeline_start);
|
||||
let end = group_end_time.unwrap_or(start_secs);
|
||||
if time < start_secs || time >= end { return; }
|
||||
0.0
|
||||
} else {
|
||||
let clip_dur = document.get_clip_duration(&vector_clip.id).unwrap_or(vector_clip.duration);
|
||||
let Some(t) = clip_instance.remap_time(time, clip_dur) else { return };
|
||||
let Some(t) = clip_instance.remap_time(time, clip_dur, tempo_map) else { return };
|
||||
t
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
pub use daw_backend::tempo_map::{TempoEntry, TempoMap};
|
||||
@@ -69,8 +69,9 @@ fn export_audio_daw_backend<P: AsRef<Path>>(
|
||||
channels: settings.channels,
|
||||
bit_depth: settings.bit_depth,
|
||||
mp3_bitrate: 320, // Not used for WAV/FLAC
|
||||
start_time: settings.start_time,
|
||||
end_time: settings.end_time,
|
||||
start_time: daw_backend::Seconds(settings.start_time),
|
||||
end_time: daw_backend::Seconds(settings.end_time),
|
||||
tempo_map: daw_backend::TempoMap::constant(settings.bpm),
|
||||
};
|
||||
|
||||
// Use the existing DAW backend export function
|
||||
@@ -105,8 +106,9 @@ fn export_audio_ffmpeg_mp3<P: AsRef<Path>>(
|
||||
channels: settings.channels,
|
||||
bit_depth: 16, // Unused
|
||||
mp3_bitrate: settings.bitrate_kbps,
|
||||
start_time: settings.start_time,
|
||||
end_time: settings.end_time,
|
||||
start_time: daw_backend::Seconds(settings.start_time),
|
||||
end_time: daw_backend::Seconds(settings.end_time),
|
||||
tempo_map: daw_backend::TempoMap::constant(settings.bpm),
|
||||
};
|
||||
|
||||
// Step 1: Render audio to memory
|
||||
@@ -294,8 +296,9 @@ fn export_audio_ffmpeg_aac<P: AsRef<Path>>(
|
||||
channels: settings.channels,
|
||||
bit_depth: 16, // Unused
|
||||
mp3_bitrate: settings.bitrate_kbps,
|
||||
start_time: settings.start_time,
|
||||
end_time: settings.end_time,
|
||||
start_time: daw_backend::Seconds(settings.start_time),
|
||||
end_time: daw_backend::Seconds(settings.end_time),
|
||||
tempo_map: daw_backend::TempoMap::constant(settings.bpm),
|
||||
};
|
||||
|
||||
// Step 1: Render audio to memory
|
||||
|
||||
@@ -696,8 +696,9 @@ impl ExportOrchestrator {
|
||||
channels: settings.channels,
|
||||
bit_depth: settings.bit_depth,
|
||||
mp3_bitrate: settings.bitrate_kbps,
|
||||
start_time: settings.start_time,
|
||||
end_time: settings.end_time,
|
||||
start_time: daw_backend::Seconds(settings.start_time),
|
||||
end_time: daw_backend::Seconds(settings.end_time),
|
||||
tempo_map: daw_backend::TempoMap::constant(settings.bpm),
|
||||
};
|
||||
|
||||
// Use DAW backend export for all formats
|
||||
|
||||
@@ -882,7 +882,7 @@ fn composite_document_to_hdr(
|
||||
let effect_inst = lightningbeam_core::effect::EffectInstance::new(
|
||||
effect_def,
|
||||
effect_instance.timeline_start,
|
||||
effect_instance.timeline_start + effect_instance.effective_duration(lightningbeam_core::effect::EFFECT_DURATION),
|
||||
effect_instance.timeline_start + effect_instance.effective_duration(lightningbeam_core::effect::EFFECT_DURATION, document.tempo_map()),
|
||||
);
|
||||
let effect_output_handle = gpu_resources.buffer_pool.acquire(device, hdr_spec);
|
||||
if let Some(effect_output_view) = gpu_resources.buffer_pool.get_view(effect_output_handle) {
|
||||
|
||||
@@ -1844,7 +1844,7 @@ impl EditorApp {
|
||||
let mut result = Vec::new();
|
||||
for instance in clip_instances {
|
||||
if let Some(clip_duration) = document.get_clip_duration(&instance.clip_id) {
|
||||
let effective_duration = instance.effective_duration(clip_duration);
|
||||
let effective_duration = instance.effective_duration(clip_duration, document.tempo_map());
|
||||
let timeline_end = instance.timeline_start + effective_duration;
|
||||
|
||||
const EPSILON: f64 = 0.001;
|
||||
@@ -2698,7 +2698,7 @@ impl EditorApp {
|
||||
let mut duplicate = original.clone();
|
||||
duplicate.id = uuid::Uuid::new_v4();
|
||||
let clip_duration = document.get_clip_duration(&original.clip_id).unwrap_or(1.0);
|
||||
let effective_duration = original.effective_duration(clip_duration);
|
||||
let effective_duration = original.effective_duration(clip_duration, document.tempo_map());
|
||||
duplicate.timeline_start = original.timeline_start + effective_duration;
|
||||
if let Some((new_clip_def_id, _)) = midi_clip_replacements.get(&original.clip_id) {
|
||||
duplicate.clip_id = *new_clip_def_id;
|
||||
@@ -3771,7 +3771,7 @@ impl EditorApp {
|
||||
// Sync BPM/time signature to metronome
|
||||
let doc = self.action_executor.document();
|
||||
controller.set_tempo(
|
||||
doc.bpm as f32,
|
||||
doc.bpm() as f32,
|
||||
(doc.time_signature.numerator, doc.time_signature.denominator),
|
||||
);
|
||||
}
|
||||
@@ -3834,9 +3834,6 @@ impl EditorApp {
|
||||
|
||||
// Rebuild MIDI event cache for all MIDI clips (needed for timeline/piano roll rendering)
|
||||
let step8_start = std::time::Instant::now();
|
||||
// Migrate old documents: compute beats/frames derived fields
|
||||
self.action_executor.document_mut().sync_all_clip_positions();
|
||||
|
||||
self.midi_event_cache.clear();
|
||||
let midi_clip_ids: Vec<u32> = self.action_executor.document()
|
||||
.audio_clips.values()
|
||||
@@ -3859,19 +3856,6 @@ impl EditorApp {
|
||||
}
|
||||
eprintln!("📊 [APPLY] Step 8: Rebuilt MIDI event cache for {} clips in {:.2}ms", midi_fetched, step8_start.elapsed().as_secs_f64() * 1000.0);
|
||||
|
||||
// Sync beats/frames derived fields on MIDI events (migration for old documents)
|
||||
{
|
||||
let bpm = self.action_executor.document().bpm;
|
||||
let fps = self.action_executor.document().framerate;
|
||||
for events in self.midi_event_cache.values_mut() {
|
||||
for ev in events.iter_mut() {
|
||||
if ev.timestamp_beats == 0.0 && ev.timestamp.abs() > 1e-9 {
|
||||
ev.sync_from_seconds(bpm, fps);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Reset playback state
|
||||
self.playback_time = 0.0;
|
||||
self.is_playing = false;
|
||||
@@ -4002,15 +3986,11 @@ impl EditorApp {
|
||||
/// Rebuild a MIDI event cache entry from backend note format.
|
||||
/// Called after undo/redo to keep the cache consistent with the backend.
|
||||
fn rebuild_midi_cache_entry(&mut self, clip_id: u32, notes: &[(f64, u8, u8, f64)]) {
|
||||
let bpm = self.action_executor.document().bpm;
|
||||
let fps = self.action_executor.document().framerate;
|
||||
let mut events: Vec<daw_backend::audio::midi::MidiEvent> = Vec::with_capacity(notes.len() * 2);
|
||||
for &(start_time, note, velocity, duration) in notes {
|
||||
let mut on = daw_backend::audio::midi::MidiEvent::note_on(start_time, 0, note, velocity);
|
||||
on.sync_from_seconds(bpm, fps);
|
||||
let on = daw_backend::audio::midi::MidiEvent::note_on(daw_backend::Beats(start_time), 0, note, velocity);
|
||||
events.push(on);
|
||||
let mut off = daw_backend::audio::midi::MidiEvent::note_off(start_time + duration, 0, note, 0);
|
||||
off.sync_from_seconds(bpm, fps);
|
||||
let off = daw_backend::audio::midi::MidiEvent::note_off(daw_backend::Beats(start_time + duration), 0, note, 0);
|
||||
events.push(off);
|
||||
}
|
||||
events.sort_by(|a, b| a.timestamp.partial_cmp(&b.timestamp).unwrap());
|
||||
@@ -4048,14 +4028,14 @@ impl EditorApp {
|
||||
let frontend_clip_id = self.action_executor.document_mut().add_audio_clip(clip);
|
||||
|
||||
println!("Imported MIDI '{}' ({:.1}s, {} total events) - Frontend ID: {}, Backend ID: {}",
|
||||
name, duration, event_count, frontend_clip_id, backend_clip_id);
|
||||
name, duration.beats_to_f64(), event_count, frontend_clip_id, backend_clip_id);
|
||||
|
||||
Some(ImportedAssetInfo {
|
||||
clip_id: frontend_clip_id,
|
||||
clip_type: panes::DragClipType::AudioMidi,
|
||||
name,
|
||||
dimensions: None,
|
||||
duration,
|
||||
duration: duration.beats_to_f64(),
|
||||
linked_audio_clip_id: None,
|
||||
})
|
||||
} else {
|
||||
@@ -5032,7 +5012,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;
|
||||
clip.duration = duration.seconds_to_f64();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5202,24 +5182,18 @@ 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;
|
||||
clip.duration = duration.beats_to_f64();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update midi_event_cache with notes captured so far
|
||||
// (inlined to avoid conflicting &mut self borrow)
|
||||
// Update midi_event_cache with notes captured so far.
|
||||
// Notes from get_notes_with_active() are already in beats.
|
||||
{
|
||||
let bpm = self.action_executor.document().bpm;
|
||||
let fps = self.action_executor.document().framerate;
|
||||
let mut events: Vec<daw_backend::audio::midi::MidiEvent> = Vec::with_capacity(notes.len() * 2);
|
||||
for &(start_time, note, velocity, dur) in ¬es {
|
||||
let mut on = daw_backend::audio::midi::MidiEvent::note_on(start_time, 0, note, velocity);
|
||||
on.sync_from_seconds(bpm, fps);
|
||||
events.push(on);
|
||||
let mut off = daw_backend::audio::midi::MidiEvent::note_off(start_time + dur, 0, note, 0);
|
||||
off.sync_from_seconds(bpm, fps);
|
||||
events.push(off);
|
||||
for &(start_beats, note, velocity, dur_beats) in ¬es {
|
||||
events.push(daw_backend::audio::midi::MidiEvent::note_on(start_beats, 0, note, velocity));
|
||||
events.push(daw_backend::audio::midi::MidiEvent::note_off(start_beats + dur_beats, 0, note, 0));
|
||||
}
|
||||
events.sort_by(|a, b| a.timestamp.partial_cmp(&b.timestamp).unwrap());
|
||||
self.midi_event_cache.insert(clip_id, events);
|
||||
@@ -5236,13 +5210,7 @@ impl eframe::App for EditorApp {
|
||||
match controller.query_midi_clip(track_id, clip_id) {
|
||||
Ok(midi_clip_data) => {
|
||||
drop(controller);
|
||||
let bpm = self.action_executor.document().bpm;
|
||||
let fps = self.action_executor.document().framerate;
|
||||
let mut final_events = midi_clip_data.events.clone();
|
||||
for ev in &mut final_events {
|
||||
ev.sync_from_seconds(bpm, fps);
|
||||
}
|
||||
self.midi_event_cache.insert(clip_id, final_events);
|
||||
self.midi_event_cache.insert(clip_id, midi_clip_data.events.clone());
|
||||
|
||||
// Update document clip with final duration and name
|
||||
let doc_clip_id = self.action_executor.document()
|
||||
|
||||
@@ -391,10 +391,10 @@ fn generate_midi_thumbnail(
|
||||
|
||||
// Draw note events
|
||||
for event in events {
|
||||
if !event.is_note_on() || event.timestamp > preview_duration {
|
||||
if !event.is_note_on() || event.timestamp.beats_to_f64() > preview_duration {
|
||||
continue;
|
||||
}
|
||||
let (timestamp, note_number) = (event.timestamp, event.data1);
|
||||
let (timestamp, note_number) = (event.timestamp.beats_to_f64(), event.data1);
|
||||
|
||||
let x = ((timestamp / preview_duration) * size as f64) as usize;
|
||||
|
||||
|
||||
@@ -1147,7 +1147,7 @@ impl InfopanelPane {
|
||||
|
||||
let clip_dur = document.get_clip_duration(&ci.clip_id)
|
||||
.unwrap_or_else(|| ci.trim_end.unwrap_or(1.0) - ci.trim_start);
|
||||
let total_dur = ci.total_duration(clip_dur);
|
||||
let total_dur = ci.total_duration(clip_dur, document.tempo_map());
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Duration:");
|
||||
ui.label(format!("{:.2}s", total_dur));
|
||||
@@ -1215,10 +1215,10 @@ impl InfopanelPane {
|
||||
let mut pending: std::collections::HashMap<u8, (f64, u8)> = std::collections::HashMap::new();
|
||||
for event in events {
|
||||
if event.is_note_on() {
|
||||
pending.insert(event.data1, (event.timestamp, event.data2));
|
||||
pending.insert(event.data1, (event.timestamp.beats_to_f64(), event.data2));
|
||||
} else if event.is_note_off() {
|
||||
if let Some((start, v)) = pending.remove(&event.data1) {
|
||||
notes.push((start, event.data1, v, event.timestamp - start));
|
||||
notes.push((start, event.data1, v, event.timestamp.beats_to_f64() - start));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,10 +255,10 @@ impl PianoRollPane {
|
||||
for event in events {
|
||||
let channel = event.status & 0x0F;
|
||||
if event.is_note_on() {
|
||||
active.insert(event.data1, (event.timestamp, event.data2, channel));
|
||||
active.insert(event.data1, (event.timestamp.beats_to_f64(), event.data2, channel));
|
||||
} else if event.is_note_off() {
|
||||
if let Some((start, vel, ch)) = active.remove(&event.data1) {
|
||||
let duration = (event.timestamp - start).max(MIN_NOTE_DURATION);
|
||||
let duration = (event.timestamp.beats_to_f64() - start).max(MIN_NOTE_DURATION);
|
||||
notes.push(ResolvedNote {
|
||||
note: event.data1,
|
||||
channel: ch,
|
||||
@@ -292,13 +292,13 @@ impl PianoRollPane {
|
||||
|
||||
// ── Ruler interval calculation ───────────────────────────────────────
|
||||
|
||||
fn ruler_interval(&self, bpm: f64, time_sig: &lightningbeam_core::document::TimeSignature) -> f64 {
|
||||
fn ruler_interval(&self, tempo_map: &daw_backend::TempoMap, time_sig: &lightningbeam_core::document::TimeSignature) -> f64 {
|
||||
let min_pixel_gap = 80.0;
|
||||
let min_seconds = (min_pixel_gap / self.pixels_per_second) as f64;
|
||||
|
||||
// Use beat-aligned intervals
|
||||
let beat_dur = lightningbeam_core::beat_time::beat_duration(bpm);
|
||||
let measure_dur = lightningbeam_core::beat_time::measure_duration(bpm, time_sig);
|
||||
let beat_dur = lightningbeam_core::beat_time::beat_duration(0.0, tempo_map);
|
||||
let measure_dur = lightningbeam_core::beat_time::measure_duration(0.0, tempo_map, time_sig);
|
||||
let beat_intervals = [
|
||||
beat_dur / 4.0, beat_dur / 2.0, beat_dur, beat_dur * 2.0,
|
||||
measure_dur, measure_dur * 2.0, measure_dur * 4.0,
|
||||
@@ -315,8 +315,8 @@ impl PianoRollPane {
|
||||
|
||||
} // end impl PianoRollPane (snap helpers follow as free functions)
|
||||
|
||||
fn snap_to_value(t: f64, snap: SnapValue, bpm: f64) -> f64 {
|
||||
let beat = 60.0 / bpm;
|
||||
fn snap_to_value(t: f64, snap: SnapValue, tempo_map: &daw_backend::TempoMap) -> f64 {
|
||||
let beat = lightningbeam_core::beat_time::beat_duration(0.0, tempo_map);
|
||||
match snap {
|
||||
SnapValue::None => t,
|
||||
SnapValue::Whole => round_to_grid(t, beat * 4.0),
|
||||
@@ -347,7 +347,7 @@ fn snap_swing(t: f64, cell: f64, ratio: f64) -> f64 {
|
||||
*cands.iter().min_by(|&&a, &&b| (a - t).abs().partial_cmp(&(b - t).abs()).unwrap()).unwrap()
|
||||
}
|
||||
|
||||
fn detect_snap(notes: &[&ResolvedNote], bpm: f64) -> SnapValue {
|
||||
fn detect_snap(notes: &[&ResolvedNote], tempo_map: &daw_backend::TempoMap) -> SnapValue {
|
||||
const EPS: f64 = 0.002;
|
||||
if notes.is_empty() { return SnapValue::None; }
|
||||
let order = [
|
||||
@@ -359,7 +359,7 @@ fn detect_snap(notes: &[&ResolvedNote], bpm: f64) -> SnapValue {
|
||||
SnapValue::SixteenthTriplet, SnapValue::ThirtySecondTriplet,
|
||||
];
|
||||
for &sv in &order {
|
||||
if notes.iter().all(|n| (snap_to_value(n.start_time, sv, bpm) - n.start_time).abs() < EPS) {
|
||||
if notes.iter().all(|n| (snap_to_value(n.start_time, sv, tempo_map) - n.start_time).abs() < EPS) {
|
||||
return sv;
|
||||
}
|
||||
}
|
||||
@@ -425,7 +425,7 @@ impl PianoRollPane {
|
||||
let clip_doc_id = clip_doc_id; // doc-side AudioClip uuid
|
||||
let duration = mc.external_duration;
|
||||
let instance_uuid = Uuid::nil(); // no doc-side instance uuid yet
|
||||
clip_data.push((mc.clip_id, mc.external_start, mc.internal_start, duration, instance_uuid));
|
||||
clip_data.push((mc.clip_id, mc.external_start.beats_to_f64(), mc.internal_start.beats_to_f64(), duration.beats_to_f64(), instance_uuid));
|
||||
let _ = clip_doc_id; // used above for the if-let pattern
|
||||
}
|
||||
}
|
||||
@@ -435,7 +435,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(clip.duration);
|
||||
let duration = instance.effective_duration(clip.duration, document.tempo_map());
|
||||
clip_data.push((midi_clip_id, instance.timeline_start, instance.trim_start, duration, instance.id));
|
||||
}
|
||||
}
|
||||
@@ -456,8 +456,8 @@ impl PianoRollPane {
|
||||
self.snap_user_changed = false;
|
||||
if self.snap_value != SnapValue::None && !self.selected_note_indices.is_empty() {
|
||||
if let Some(clip_id) = self.selected_clip_id {
|
||||
let bpm = shared.action_executor.document().bpm;
|
||||
self.quantize_selected_notes(clip_id, bpm, shared);
|
||||
let tempo_map = shared.action_executor.document().tempo_map().clone();
|
||||
self.quantize_selected_notes(clip_id, &tempo_map, shared);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -484,11 +484,11 @@ impl PianoRollPane {
|
||||
|
||||
// Render grid (clipped to grid area)
|
||||
let grid_painter = ui.painter_at(grid_rect);
|
||||
let (grid_bpm, grid_time_sig) = {
|
||||
let (grid_tempo_map, grid_time_sig) = {
|
||||
let doc = shared.action_executor.document();
|
||||
(doc.bpm, doc.time_signature.clone())
|
||||
(doc.tempo_map().clone(), doc.time_signature.clone())
|
||||
};
|
||||
self.render_grid(&grid_painter, grid_rect, grid_bpm, &grid_time_sig);
|
||||
self.render_grid(&grid_painter, grid_rect, &grid_tempo_map, &grid_time_sig);
|
||||
|
||||
// Render clip boundaries and notes
|
||||
for &(midi_clip_id, timeline_start, trim_start, duration, _instance_id) in &clip_data {
|
||||
@@ -621,7 +621,7 @@ impl PianoRollPane {
|
||||
}
|
||||
|
||||
fn render_grid(&self, painter: &egui::Painter, grid_rect: Rect,
|
||||
bpm: f64, time_sig: &lightningbeam_core::document::TimeSignature) {
|
||||
tempo_map: &daw_backend::TempoMap, time_sig: &lightningbeam_core::document::TimeSignature) {
|
||||
// Horizontal lines (note separators)
|
||||
for note in MIN_NOTE..=MAX_NOTE {
|
||||
let y = self.note_to_y(note, grid_rect);
|
||||
@@ -648,9 +648,9 @@ impl PianoRollPane {
|
||||
}
|
||||
|
||||
// Vertical lines (beat-aligned time grid)
|
||||
let interval = self.ruler_interval(bpm, time_sig);
|
||||
let beat_dur = lightningbeam_core::beat_time::beat_duration(bpm);
|
||||
let measure_dur = lightningbeam_core::beat_time::measure_duration(bpm, time_sig);
|
||||
let interval = self.ruler_interval(tempo_map, time_sig);
|
||||
let beat_dur = lightningbeam_core::beat_time::beat_duration(0.0, tempo_map);
|
||||
let measure_dur = lightningbeam_core::beat_time::measure_duration(0.0, tempo_map, time_sig);
|
||||
|
||||
let start = (self.viewport_start_time / interval).floor() as i64;
|
||||
let end_time = self.viewport_start_time + (grid_rect.width() / self.pixels_per_second) as f64;
|
||||
@@ -675,7 +675,7 @@ impl PianoRollPane {
|
||||
|
||||
// Labels at measure boundaries
|
||||
if is_measure && x > grid_rect.min.x + 20.0 {
|
||||
let pos = lightningbeam_core::beat_time::time_to_measure(time, bpm, time_sig);
|
||||
let pos = lightningbeam_core::beat_time::time_to_measure(time, tempo_map, time_sig);
|
||||
painter.text(
|
||||
pos2(x + 2.0, grid_rect.min.y + 2.0),
|
||||
Align2::LEFT_TOP,
|
||||
@@ -685,7 +685,7 @@ impl PianoRollPane {
|
||||
);
|
||||
} else if is_beat && !is_measure && x > grid_rect.min.x + 20.0
|
||||
&& beat_dur as f32 * self.pixels_per_second > 40.0 {
|
||||
let pos = lightningbeam_core::beat_time::time_to_measure(time, bpm, time_sig);
|
||||
let pos = lightningbeam_core::beat_time::time_to_measure(time, tempo_map, time_sig);
|
||||
painter.text(
|
||||
pos2(x + 2.0, grid_rect.min.y + 2.0),
|
||||
Align2::LEFT_TOP,
|
||||
@@ -708,8 +708,8 @@ impl PianoRollPane {
|
||||
) -> f32 {
|
||||
let mut peak = 0.0f32;
|
||||
for ev in events {
|
||||
if ev.timestamp > note_end + 0.01 { break; }
|
||||
if ev.timestamp >= note_start - 0.01
|
||||
if ev.timestamp.beats_to_f64() > note_end + 0.01 { break; }
|
||||
if ev.timestamp.beats_to_f64() >= note_start - 0.01
|
||||
&& (ev.status & 0xF0) == 0xE0
|
||||
&& (ev.status & 0x0F) == channel
|
||||
{
|
||||
@@ -770,7 +770,7 @@ impl PianoRollPane {
|
||||
};
|
||||
let timestamp = note_start + t * note_duration;
|
||||
let (lsb, msb) = encode_bend(normalized);
|
||||
events.push(MidiEvent::new(timestamp, 0xE0 | channel, lsb, msb));
|
||||
events.push(MidiEvent::new(daw_backend::Beats(timestamp), 0xE0 | channel, lsb, msb));
|
||||
}
|
||||
events
|
||||
}
|
||||
@@ -794,11 +794,11 @@ impl PianoRollPane {
|
||||
let ch = ev.status & 0x0F;
|
||||
let msg = ev.status & 0xF0;
|
||||
if msg == 0x90 && ev.data2 > 0 {
|
||||
active.insert((ev.data1, ch), ev.timestamp);
|
||||
active.insert((ev.data1, ch), ev.timestamp.beats_to_f64());
|
||||
} else if msg == 0x80 || (msg == 0x90 && ev.data2 == 0) {
|
||||
if let Some(start) = active.remove(&(ev.data1, ch)) {
|
||||
// Overlaps target range and is NOT the note we're assigning
|
||||
if start < note_end && ev.timestamp > note_start
|
||||
if start < note_end && ev.timestamp.beats_to_f64() > note_start
|
||||
&& !(ev.data1 == note_pitch && ch == current_channel)
|
||||
{
|
||||
used[ch as usize] = true;
|
||||
@@ -828,9 +828,9 @@ impl PianoRollPane {
|
||||
fn find_cc1_for_note(events: &[daw_backend::audio::midi::MidiEvent], note_start: f64, note_end: f64, channel: u8) -> u8 {
|
||||
let mut cc1 = 0u8;
|
||||
for ev in events {
|
||||
if ev.timestamp > note_end { break; }
|
||||
if ev.timestamp.beats_to_f64() > note_end { break; }
|
||||
if (ev.status & 0xF0) == 0xB0 && (ev.status & 0x0F) == channel && ev.data1 == 1 {
|
||||
if ev.timestamp <= note_start {
|
||||
if ev.timestamp.beats_to_f64() <= note_start {
|
||||
cc1 = ev.data2;
|
||||
}
|
||||
}
|
||||
@@ -950,7 +950,7 @@ impl PianoRollPane {
|
||||
let ts = note.start_time + t as f64 * note.duration;
|
||||
let mut existing_norm = 0.0f32;
|
||||
for ev in events {
|
||||
if ev.timestamp > ts { break; }
|
||||
if ev.timestamp.beats_to_f64() > ts { break; }
|
||||
if (ev.status & 0xF0) == 0xE0 && (ev.status & 0x0F) == drag_ch {
|
||||
let raw = ((ev.data2 as i16) << 7) | (ev.data1 as i16);
|
||||
existing_norm = (raw - 8192) as f32 / 8192.0;
|
||||
@@ -991,7 +991,7 @@ impl PianoRollPane {
|
||||
// Find last pitch bend event at or before ts
|
||||
let mut bend_norm = 0.0f32;
|
||||
for ev in events {
|
||||
if ev.timestamp > ts { break; }
|
||||
if ev.timestamp.beats_to_f64() > ts { break; }
|
||||
if (ev.status & 0xF0) == 0xE0 && (ev.status & 0x0F) == note.channel {
|
||||
let raw = ((ev.data2 as i16) << 7) | (ev.data1 as i16);
|
||||
bend_norm = (raw - 8192) as f32 / 8192.0;
|
||||
@@ -1037,9 +1037,9 @@ impl PianoRollPane {
|
||||
}
|
||||
|
||||
fn render_dot_grid(&self, painter: &egui::Painter, grid_rect: Rect,
|
||||
bpm: f64, time_sig: &lightningbeam_core::document::TimeSignature) {
|
||||
tempo_map: &daw_backend::TempoMap, time_sig: &lightningbeam_core::document::TimeSignature) {
|
||||
// Collect visible time grid positions
|
||||
let interval = self.ruler_interval(bpm, time_sig);
|
||||
let interval = self.ruler_interval(tempo_map, time_sig);
|
||||
let start = (self.viewport_start_time / interval).floor() as i64;
|
||||
let end_time = self.viewport_start_time + (grid_rect.width() / self.pixels_per_second) as f64;
|
||||
let end = (end_time / interval).ceil() as i64;
|
||||
@@ -1374,10 +1374,10 @@ impl PianoRollPane {
|
||||
if let Some(selected_clip) = clip_data.iter().find(|c| Some(c.0) == self.selected_clip_id) {
|
||||
let clip_start = selected_clip.1;
|
||||
let trim_start = selected_clip.2;
|
||||
let bpm = shared.action_executor.document().bpm;
|
||||
let tempo_map = shared.action_executor.document().tempo_map();
|
||||
let clip_local_time = snap_to_value(
|
||||
(time - clip_start).max(0.0) + trim_start,
|
||||
self.snap_value, bpm,
|
||||
self.snap_value, tempo_map,
|
||||
);
|
||||
self.creating_note = Some(TempNote {
|
||||
note,
|
||||
@@ -1395,8 +1395,8 @@ impl PianoRollPane {
|
||||
self.selection_rect = Some((pos, pos));
|
||||
self.drag_mode = Some(DragMode::SelectRect);
|
||||
|
||||
let bpm = shared.action_executor.document().bpm;
|
||||
let seek_time = snap_to_value(time.max(0.0), self.snap_value, bpm);
|
||||
let tempo_map = shared.action_executor.document().tempo_map();
|
||||
let seek_time = snap_to_value(time.max(0.0), self.snap_value, tempo_map);
|
||||
*shared.playback_time = seek_time;
|
||||
if let Some(ctrl) = shared.audio_controller.as_ref() {
|
||||
if let Ok(mut c) = ctrl.lock() { c.seek(seek_time); }
|
||||
@@ -1538,7 +1538,7 @@ impl PianoRollPane {
|
||||
let ts = note_start + t * note_duration;
|
||||
let mut bend = 0.0f32;
|
||||
for ev in &new_events {
|
||||
if ev.timestamp > ts { break; }
|
||||
if ev.timestamp.beats_to_f64() > ts { break; }
|
||||
if (ev.status & 0xF0) == 0xE0 && (ev.status & 0x0F) == target_channel {
|
||||
let raw = ((ev.data2 as i16) << 7) | (ev.data1 as i16);
|
||||
bend = (raw - 8192) as f32 / 8192.0;
|
||||
@@ -1550,7 +1550,8 @@ impl PianoRollPane {
|
||||
// Remove old bend events in range before writing combined
|
||||
new_events.retain(|ev| {
|
||||
let is_bend = (ev.status & 0xF0) == 0xE0 && (ev.status & 0x0F) == target_channel;
|
||||
let in_range = ev.timestamp >= note_start - 0.001 && ev.timestamp <= note_start + note_duration + 0.01;
|
||||
let ts = ev.timestamp.beats_to_f64();
|
||||
let in_range = ts >= note_start - 0.001 && ts <= note_start + note_duration + 0.01;
|
||||
!(is_bend && in_range)
|
||||
});
|
||||
|
||||
@@ -1568,20 +1569,15 @@ impl PianoRollPane {
|
||||
let combined = (existing_norm[i] + zone_norm).clamp(-1.0, 1.0);
|
||||
let (lsb, msb) = encode_bend(combined);
|
||||
let ts = note_start + i as f64 / num_steps as f64 * note_duration;
|
||||
new_events.push(daw_backend::audio::midi::MidiEvent::new(ts, 0xE0 | target_channel, lsb, msb));
|
||||
new_events.push(daw_backend::audio::midi::MidiEvent::new(daw_backend::Beats(ts), 0xE0 | target_channel, lsb, msb));
|
||||
}
|
||||
// For End zone: reset just after note ends so it doesn't bleed into next note
|
||||
if zone == PitchBendZone::End {
|
||||
let (lsb, msb) = encode_bend(0.0);
|
||||
new_events.push(daw_backend::audio::midi::MidiEvent::new(note_start + note_duration + 0.005, 0xE0 | target_channel, lsb, msb));
|
||||
new_events.push(daw_backend::audio::midi::MidiEvent::new(daw_backend::Beats(note_start + note_duration + 0.005), 0xE0 | target_channel, lsb, msb));
|
||||
}
|
||||
|
||||
new_events.sort_by(|a, b| a.timestamp.partial_cmp(&b.timestamp).unwrap_or(std::cmp::Ordering::Equal));
|
||||
{
|
||||
let doc = shared.action_executor.document();
|
||||
let bpm = doc.bpm; let fps = doc.framerate;
|
||||
for ev in &mut new_events { ev.sync_from_seconds(bpm, fps); }
|
||||
}
|
||||
self.push_events_action("Set pitch bend", clip_id, old_events, new_events.clone(), shared);
|
||||
shared.midi_event_cache.insert(clip_id, new_events);
|
||||
}
|
||||
@@ -1737,8 +1733,8 @@ impl PianoRollPane {
|
||||
fn update_cache_from_resolved(clip_id: u32, resolved: &[ResolvedNote], shared: &mut SharedPaneState) {
|
||||
let mut events: Vec<daw_backend::audio::midi::MidiEvent> = Vec::with_capacity(resolved.len() * 2);
|
||||
for n in resolved {
|
||||
events.push(daw_backend::audio::midi::MidiEvent::note_on(n.start_time, 0, n.note, n.velocity));
|
||||
events.push(daw_backend::audio::midi::MidiEvent::note_off(n.start_time + n.duration, 0, n.note, 0));
|
||||
events.push(daw_backend::audio::midi::MidiEvent::note_on(daw_backend::Beats(n.start_time), 0, n.note, n.velocity));
|
||||
events.push(daw_backend::audio::midi::MidiEvent::note_off(daw_backend::Beats(n.start_time + n.duration), 0, n.note, 0));
|
||||
}
|
||||
events.sort_by(|a, b| a.timestamp.partial_cmp(&b.timestamp).unwrap());
|
||||
shared.midi_event_cache.insert(clip_id, events);
|
||||
@@ -1787,12 +1783,12 @@ impl PianoRollPane {
|
||||
let resolved = Self::resolve_notes(events);
|
||||
let old_notes = Self::notes_to_backend_format(&resolved);
|
||||
|
||||
let bpm = shared.action_executor.document().bpm;
|
||||
let tempo_map = shared.action_executor.document().tempo_map();
|
||||
let mut new_resolved = resolved.clone();
|
||||
for &idx in &self.selected_note_indices {
|
||||
if idx < new_resolved.len() {
|
||||
let raw_time = (new_resolved[idx].start_time + dt).max(0.0);
|
||||
new_resolved[idx].start_time = snap_to_value(raw_time, self.snap_value, bpm);
|
||||
new_resolved[idx].start_time = snap_to_value(raw_time, self.snap_value, tempo_map);
|
||||
new_resolved[idx].note = (new_resolved[idx].note as i32 + dn).clamp(0, 127) as u8;
|
||||
}
|
||||
}
|
||||
@@ -1968,7 +1964,7 @@ impl PianoRollPane {
|
||||
shared.pending_actions.push(Box::new(action));
|
||||
}
|
||||
|
||||
fn quantize_selected_notes(&mut self, clip_id: u32, bpm: f64, shared: &mut SharedPaneState) {
|
||||
fn quantize_selected_notes(&mut self, clip_id: u32, tempo_map: &daw_backend::TempoMap, shared: &mut SharedPaneState) {
|
||||
let events = match shared.midi_event_cache.get(&clip_id) { Some(e) => e, None => return };
|
||||
let resolved = Self::resolve_notes(events);
|
||||
let old_notes = Self::notes_to_backend_format(&resolved);
|
||||
@@ -1976,7 +1972,7 @@ impl PianoRollPane {
|
||||
for &idx in &self.selected_note_indices {
|
||||
if idx < new_resolved.len() {
|
||||
new_resolved[idx].start_time =
|
||||
snap_to_value(new_resolved[idx].start_time, self.snap_value, bpm).max(0.0);
|
||||
snap_to_value(new_resolved[idx].start_time, self.snap_value, tempo_map).max(0.0);
|
||||
}
|
||||
}
|
||||
let new_notes = Self::notes_to_backend_format(&new_resolved);
|
||||
@@ -2075,11 +2071,11 @@ impl PianoRollPane {
|
||||
// Dot grid background (visible where the spectrogram doesn't draw)
|
||||
let grid_painter = ui.painter_at(view_rect);
|
||||
{
|
||||
let (dot_bpm, dot_ts) = {
|
||||
let (dot_tempo_map, dot_ts) = {
|
||||
let doc = shared.action_executor.document();
|
||||
(doc.bpm, doc.time_signature.clone())
|
||||
(doc.tempo_map().clone(), doc.time_signature.clone())
|
||||
};
|
||||
self.render_dot_grid(&grid_painter, view_rect, dot_bpm, &dot_ts);
|
||||
self.render_dot_grid(&grid_painter, view_rect, &dot_tempo_map, &dot_ts);
|
||||
}
|
||||
|
||||
// Find audio pool index for the active layer's clips
|
||||
@@ -2323,7 +2319,7 @@ impl PaneRenderer for PianoRollPane {
|
||||
for ev in cached.iter_mut() {
|
||||
if ev.is_note_on() && ev.data1 == sn.note
|
||||
&& (ev.status & 0x0F) == sn.channel
|
||||
&& (ev.timestamp - sn.start_time).abs() < 1e-6
|
||||
&& (ev.timestamp.beats_to_f64() - sn.start_time).abs() < 1e-6
|
||||
{
|
||||
ev.data2 = new_vel;
|
||||
}
|
||||
@@ -2360,21 +2356,16 @@ impl PaneRenderer for PianoRollPane {
|
||||
let is_cc1 = (ev.status & 0xF0) == 0xB0
|
||||
&& (ev.status & 0x0F) == sn.channel
|
||||
&& ev.data1 == 1;
|
||||
let at_start = (ev.timestamp - sn.start_time).abs() < 0.001;
|
||||
let at_start = (ev.timestamp.beats_to_f64() - sn.start_time).abs() < 0.001;
|
||||
!(is_cc1 && at_start)
|
||||
});
|
||||
if new_cc1 > 0 {
|
||||
new_events.push(daw_backend::audio::midi::MidiEvent::new(
|
||||
sn.start_time, 0xB0 | sn.channel, 1, new_cc1,
|
||||
daw_backend::Beats(sn.start_time), 0xB0 | sn.channel, 1, new_cc1,
|
||||
));
|
||||
}
|
||||
}
|
||||
new_events.sort_by(|a, b| a.timestamp.partial_cmp(&b.timestamp).unwrap_or(std::cmp::Ordering::Equal));
|
||||
{
|
||||
let doc = shared.action_executor.document();
|
||||
let bpm = doc.bpm; let fps = doc.framerate;
|
||||
for ev in &mut new_events { ev.sync_from_seconds(bpm, fps); }
|
||||
}
|
||||
self.push_events_action("Set modulation", clip_id, old_events, new_events.clone(), shared);
|
||||
shared.midi_event_cache.insert(clip_id, new_events);
|
||||
}
|
||||
@@ -2416,7 +2407,7 @@ impl PaneRenderer for PianoRollPane {
|
||||
// Snap-to dropdown — only in Measures mode
|
||||
let doc = shared.action_executor.document();
|
||||
let is_measures = doc.timeline_mode == lightningbeam_core::document::TimelineMode::Measures;
|
||||
let bpm = doc.bpm;
|
||||
let tempo_map = doc.tempo_map();
|
||||
drop(doc);
|
||||
|
||||
if is_measures {
|
||||
@@ -2429,7 +2420,7 @@ impl PaneRenderer for PianoRollPane {
|
||||
let sel: Vec<&ResolvedNote> = self.selected_note_indices.iter()
|
||||
.filter_map(|&i| resolved.get(i))
|
||||
.collect();
|
||||
self.snap_value = detect_snap(&sel, bpm);
|
||||
self.snap_value = detect_snap(&sel, tempo_map);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1438,7 +1438,7 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
let effect_inst = lightningbeam_core::effect::EffectInstance::new(
|
||||
effect_def,
|
||||
effect_instance.timeline_start,
|
||||
effect_instance.timeline_start + effect_instance.effective_duration(lightningbeam_core::effect::EFFECT_DURATION),
|
||||
effect_instance.timeline_start + effect_instance.effective_duration(lightningbeam_core::effect::EFFECT_DURATION, self.ctx.document.tempo_map()),
|
||||
);
|
||||
|
||||
// Acquire temp buffer for effect output (HDR format)
|
||||
@@ -1793,7 +1793,7 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
if let Some(clip_instance) = vector_layer.clip_instances.iter().find(|ci| ci.id == clip_id) {
|
||||
// Skip clip instances not active at current time
|
||||
let clip_dur = self.ctx.document.get_clip_duration(&clip_instance.clip_id).unwrap_or(0.0);
|
||||
let instance_end = clip_instance.timeline_start + clip_instance.effective_duration(clip_dur);
|
||||
let instance_end = clip_instance.timeline_start + clip_instance.effective_duration(clip_dur, self.ctx.document.tempo_map());
|
||||
if self.ctx.playback_time < clip_instance.timeline_start || self.ctx.playback_time >= instance_end {
|
||||
continue;
|
||||
}
|
||||
@@ -2214,7 +2214,7 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
// Find clip instance visible at playback time
|
||||
let visible_clip = video_layer.clip_instances.iter().find(|inst| {
|
||||
let clip_duration = self.ctx.document.get_clip_duration(&inst.clip_id).unwrap_or(0.0);
|
||||
let effective_duration = inst.effective_duration(clip_duration);
|
||||
let effective_duration = inst.effective_duration(clip_duration, self.ctx.document.tempo_map());
|
||||
playback_time >= inst.timeline_start && playback_time < inst.timeline_start + effective_duration
|
||||
});
|
||||
|
||||
@@ -10287,7 +10287,7 @@ impl StagePane {
|
||||
if let Some(AnyLayer::Video(video_layer)) = document.get_layer(layer_id) {
|
||||
video_layer.clip_instances.iter().find(|inst| {
|
||||
let clip_duration = document.get_clip_duration(&inst.clip_id).unwrap_or(0.0);
|
||||
let effective_duration = inst.effective_duration(clip_duration);
|
||||
let effective_duration = inst.effective_duration(clip_duration, document.tempo_map());
|
||||
playback_time >= inst.timeline_start && playback_time < inst.timeline_start + effective_duration
|
||||
}).map(|inst| inst.id)
|
||||
} else {
|
||||
|
||||
@@ -74,10 +74,11 @@ fn compute_clip_stacking(
|
||||
return vec![(0, 1); clip_instances.len()];
|
||||
}
|
||||
|
||||
let tempo_map = document.tempo_map();
|
||||
let ranges: Vec<(f64, f64)> = clip_instances.iter().map(|ci| {
|
||||
let clip_dur = effective_clip_duration(document, layer, ci).unwrap_or(0.0);
|
||||
let start = ci.effective_start();
|
||||
let end = start + ci.total_duration(clip_dur);
|
||||
let end = start + ci.total_duration(clip_dur, tempo_map);
|
||||
(start, end)
|
||||
}).collect();
|
||||
|
||||
@@ -510,20 +511,14 @@ fn build_audio_clip_cache(
|
||||
.unwrap_or_else(|| audio_backend_uuid(ac.id));
|
||||
let mut ci = ClipInstance::new(clip_id);
|
||||
ci.id = instance_id;
|
||||
ci.timeline_start = ac.external_start;
|
||||
ci.timeline_start_beats = ac.external_start_beats;
|
||||
ci.timeline_start_frames = ac.external_start_frames;
|
||||
ci.trim_start = ac.internal_start;
|
||||
ci.trim_start_beats = ac.internal_start_beats;
|
||||
ci.trim_start_frames = ac.internal_start_frames;
|
||||
ci.trim_end = Some(ac.internal_end);
|
||||
ci.trim_end_beats = Some(ac.internal_end_beats);
|
||||
ci.trim_end_frames = Some(ac.internal_end_frames);
|
||||
let internal_dur = ac.internal_end - ac.internal_start;
|
||||
if (ac.external_duration - internal_dur).abs() > 1e-9 {
|
||||
ci.timeline_duration = Some(ac.external_duration);
|
||||
ci.timeline_duration_beats = Some(ac.external_duration_beats);
|
||||
ci.timeline_duration_frames = Some(ac.external_duration_frames);
|
||||
ci.timeline_start = ac.external_start.beats_to_f64();
|
||||
ci.trim_start = ac.internal_start.seconds_to_f64();
|
||||
ci.trim_end = Some(ac.internal_end.seconds_to_f64());
|
||||
let internal_dur_secs = (ac.internal_end - ac.internal_start).seconds_to_f64();
|
||||
let tempo_map = document.tempo_map();
|
||||
let external_dur_secs = tempo_map.transform(ac.external_duration.beats_to_f64());
|
||||
if (external_dur_secs - internal_dur_secs).abs() > 1e-9 {
|
||||
ci.timeline_duration = Some(ac.external_duration.beats_to_f64());
|
||||
}
|
||||
ci.gain = ac.gain;
|
||||
instances.push(ci);
|
||||
@@ -540,21 +535,12 @@ fn build_audio_clip_cache(
|
||||
.unwrap_or_else(|| midi_backend_uuid(mc.id));
|
||||
let mut ci = ClipInstance::new(clip_id);
|
||||
ci.id = instance_id;
|
||||
ci.timeline_start = mc.external_start;
|
||||
ci.timeline_start_beats = mc.external_start_beats;
|
||||
ci.timeline_start_frames = mc.external_start_frames;
|
||||
ci.trim_start = mc.internal_start;
|
||||
ci.trim_start_beats = mc.internal_start_beats;
|
||||
ci.trim_start_frames = mc.internal_start_frames;
|
||||
ci.trim_end = Some(mc.internal_end);
|
||||
ci.trim_end_beats = Some(mc.internal_end_beats);
|
||||
ci.trim_end_frames = Some(mc.internal_end_frames);
|
||||
let internal_dur = mc.internal_end - mc.internal_start;
|
||||
if (mc.external_duration - internal_dur).abs() > 1e-9 {
|
||||
ci.timeline_duration = Some(mc.external_duration);
|
||||
ci.timeline_duration_beats = Some(mc.external_duration_beats);
|
||||
ci.timeline_duration_frames = Some(mc.external_duration_frames);
|
||||
}
|
||||
ci.timeline_start = mc.external_start.beats_to_f64();
|
||||
ci.trim_start = mc.internal_start.beats_to_f64();
|
||||
ci.trim_end = Some(mc.internal_end.beats_to_f64());
|
||||
// Always set timeline_duration for MIDI clips: duration is in beats, so we
|
||||
// must bypass the content_window_secs * bpm/60 formula (which expects seconds).
|
||||
ci.timeline_duration = Some(mc.external_duration.beats_to_f64());
|
||||
instances.push(ci);
|
||||
}
|
||||
}
|
||||
@@ -955,12 +941,19 @@ impl TimelinePane {
|
||||
&& *shared.metronome_enabled
|
||||
&& self.time_display_format == TimelineMode::Measures
|
||||
{
|
||||
let (bpm, beats_per_measure) = {
|
||||
let (tempo_map, beats_per_measure) = {
|
||||
let doc = shared.action_executor.document();
|
||||
(doc.bpm, doc.time_signature.numerator as f64)
|
||||
(doc.tempo_map().clone(), doc.time_signature.numerator as f64)
|
||||
};
|
||||
// Convert start_time to beats, subtract one measure, convert back to seconds
|
||||
let start_beat = tempo_map.inverse_transform(start_time);
|
||||
let count_in_start_beat = start_beat - beats_per_measure;
|
||||
let seek_to = if count_in_start_beat >= 0.0 {
|
||||
tempo_map.transform(count_in_start_beat)
|
||||
} else {
|
||||
// Before beat 0: extrapolate using initial BPM
|
||||
tempo_map.transform(0.0) - count_in_start_beat.abs() * (60.0 / tempo_map.global_bpm())
|
||||
};
|
||||
let count_in_duration = beats_per_measure * (60.0 / bpm);
|
||||
let seek_to = start_time - count_in_duration; // may be negative
|
||||
|
||||
if let Some(controller_arc) = shared.audio_controller {
|
||||
let mut controller = controller_arc.lock().unwrap();
|
||||
@@ -1025,14 +1018,11 @@ impl TimelinePane {
|
||||
|
||||
// Create document clip + clip instance immediately
|
||||
let doc_clip = AudioClip::new_midi("Recording...",
|
||||
*shared.recording_clips.get(&layer_id).unwrap_or(&0), 0.0);
|
||||
*shared.recording_clips.get(&layer_id).unwrap_or(&0), daw_backend::Beats::ZERO);
|
||||
let doc_clip_id = shared.action_executor.document_mut().add_audio_clip(doc_clip);
|
||||
|
||||
let bpm = shared.action_executor.document().bpm;
|
||||
let fps = shared.action_executor.document().framerate;
|
||||
let mut clip_instance = ClipInstance::new(doc_clip_id)
|
||||
.with_timeline_start(start_time);
|
||||
clip_instance.sync_from_seconds(bpm, fps);
|
||||
|
||||
if let Some(layer) = shared.action_executor.document_mut().get_layer_mut(&layer_id) {
|
||||
if let lightningbeam_core::layer::AnyLayer::Audio(audio_layer) = layer {
|
||||
@@ -1203,8 +1193,9 @@ impl TimelinePane {
|
||||
for (ci_idx, clip_instance) in clip_instances.iter().enumerate() {
|
||||
let clip_duration = effective_clip_duration(document, layer, clip_instance)?;
|
||||
|
||||
let tempo_map = document.tempo_map();
|
||||
let instance_start = clip_instance.effective_start();
|
||||
let instance_duration = clip_instance.total_duration(clip_duration);
|
||||
let instance_duration = clip_instance.total_duration(clip_duration, tempo_map);
|
||||
let instance_end = instance_start + instance_duration;
|
||||
|
||||
let start_x = self.time_to_x(instance_start);
|
||||
@@ -1284,12 +1275,13 @@ impl TimelinePane {
|
||||
let child_clips = group.all_child_clip_instances();
|
||||
let mut spans: Vec<(f64, f64, Vec<uuid::Uuid>)> = Vec::new(); // (start, end, clip_ids)
|
||||
|
||||
let tempo_map = document.tempo_map();
|
||||
for (_child_layer_id, ci) in &child_clips {
|
||||
let clip_dur = document.get_clip_duration(&ci.clip_id).unwrap_or_else(|| {
|
||||
ci.trim_end.unwrap_or(1.0) - ci.trim_start
|
||||
});
|
||||
let start = ci.effective_start();
|
||||
let end = start + ci.total_duration(clip_dur);
|
||||
let end = start + ci.total_duration(clip_dur, tempo_map);
|
||||
spans.push((start, end, vec![ci.id]));
|
||||
}
|
||||
|
||||
@@ -1367,57 +1359,23 @@ impl TimelinePane {
|
||||
((time - self.viewport_start_time) * self.pixels_per_second as f64) as f32
|
||||
}
|
||||
|
||||
/// Effective display start for a clip instance.
|
||||
/// Effective display start for a clip instance, in seconds.
|
||||
///
|
||||
/// In Measures mode, uses `timeline_start_beats` as the canonical position so clips stay
|
||||
/// anchored to their beat position during live BPM drag preview. Falls back to seconds
|
||||
/// in other modes or when beat data is unavailable.
|
||||
fn instance_display_start(&self, ci: &lightningbeam_core::clip::ClipInstance, bpm: f64) -> f64 {
|
||||
if self.time_display_format == lightningbeam_core::document::TimelineMode::Measures
|
||||
&& (ci.timeline_start_beats.abs() > 1e-12 || ci.timeline_start == 0.0)
|
||||
{
|
||||
ci.timeline_start_beats * 60.0 / bpm - ci.loop_before.unwrap_or(0.0)
|
||||
} else {
|
||||
ci.effective_start()
|
||||
}
|
||||
/// `timeline_start` is in beats; converts to seconds using the current (preview) BPM so
|
||||
/// clips stay anchored to their beat position during live BPM drag.
|
||||
fn instance_display_start(&self, ci: &lightningbeam_core::clip::ClipInstance, tempo_map: &daw_backend::TempoMap) -> f64 {
|
||||
tempo_map.transform(ci.effective_start())
|
||||
}
|
||||
|
||||
/// In Measures mode, uses beats fields for the clip's on-timeline duration so the width
|
||||
/// stays correct during live BPM drag preview. Falls back to seconds in other modes.
|
||||
fn instance_display_duration(&self, ci: &lightningbeam_core::clip::ClipInstance, clip_dur_secs: f64, bpm: f64) -> f64 {
|
||||
use lightningbeam_core::document::TimelineMode;
|
||||
if self.time_display_format == TimelineMode::Measures {
|
||||
// Looping/extended clip: explicit timeline_duration_beats
|
||||
if let Some(dur_beats) = ci.timeline_duration_beats {
|
||||
if dur_beats.abs() > 1e-12 {
|
||||
return dur_beats * 60.0 / bpm;
|
||||
}
|
||||
}
|
||||
// Non-looping: derive from trim range in beats
|
||||
let ts_beats = ci.trim_start_beats;
|
||||
if let Some(te_beats) = ci.trim_end_beats {
|
||||
if te_beats.abs() > 1e-12 || ts_beats.abs() > 1e-12 {
|
||||
return (te_beats - ts_beats).max(0.0) * 60.0 / bpm;
|
||||
}
|
||||
}
|
||||
}
|
||||
ci.total_duration(clip_dur_secs)
|
||||
/// Effective on-timeline duration for a clip instance, in seconds.
|
||||
///
|
||||
/// `total_duration` is in beats; converts to seconds using the current (preview) BPM.
|
||||
fn instance_display_duration(&self, ci: &lightningbeam_core::clip::ClipInstance, clip_dur_secs: f64, tempo_map: &daw_backend::TempoMap) -> f64 {
|
||||
tempo_map.transform(ci.timeline_start + ci.total_duration(clip_dur_secs, tempo_map)) - tempo_map.transform(ci.effective_start())
|
||||
}
|
||||
|
||||
/// In Measures mode, returns the clip content start (trim_start) and duration in
|
||||
/// beat-derived display seconds, for use when rendering note overlays.
|
||||
fn content_display_range(&self, ci: &lightningbeam_core::clip::ClipInstance, clip_dur_secs: f64, bpm: f64) -> (f64, f64) {
|
||||
use lightningbeam_core::document::TimelineMode;
|
||||
if self.time_display_format == TimelineMode::Measures {
|
||||
let ts_beats = ci.trim_start_beats;
|
||||
if let Some(te_beats) = ci.trim_end_beats {
|
||||
if te_beats.abs() > 1e-12 || ts_beats.abs() > 1e-12 {
|
||||
let start = ts_beats * 60.0 / bpm;
|
||||
let dur = (te_beats - ts_beats).max(0.0) * 60.0 / bpm;
|
||||
return (start, dur);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Returns the clip content start (trim_start) and duration in display seconds.
|
||||
fn content_display_range(&self, ci: &lightningbeam_core::clip::ClipInstance, clip_dur_secs: f64, _bpm: f64) -> (f64, f64) {
|
||||
let trim_end = ci.trim_end.unwrap_or(clip_dur_secs);
|
||||
(ci.trim_start, (trim_end - ci.trim_start).max(0.0))
|
||||
}
|
||||
@@ -1433,7 +1391,7 @@ impl TimelinePane {
|
||||
/// - Seconds mode: no snapping
|
||||
fn quantize_grid_size(
|
||||
&self,
|
||||
bpm: f64,
|
||||
tempo_map: &daw_backend::TempoMap,
|
||||
time_sig: &lightningbeam_core::document::TimeSignature,
|
||||
framerate: f64,
|
||||
) -> Option<f64> {
|
||||
@@ -1441,8 +1399,8 @@ impl TimelinePane {
|
||||
TimelineMode::Frames => Some(1.0 / framerate),
|
||||
TimelineMode::Measures => {
|
||||
use lightningbeam_core::beat_time::{beat_duration, measure_duration};
|
||||
let beat = beat_duration(bpm);
|
||||
let measure = measure_duration(bpm, time_sig);
|
||||
let beat = beat_duration(0.0, tempo_map);
|
||||
let measure = measure_duration(0.0, tempo_map, time_sig);
|
||||
let pps = self.pixels_per_second as f64;
|
||||
// Very zoomed in: 16th note > 40px → no snap
|
||||
if pps * beat / 4.0 > 40.0 { return None; }
|
||||
@@ -1467,11 +1425,11 @@ impl TimelinePane {
|
||||
fn snap_to_grid(
|
||||
&self,
|
||||
t: f64,
|
||||
bpm: f64,
|
||||
tempo_map: &daw_backend::TempoMap,
|
||||
time_sig: &lightningbeam_core::document::TimeSignature,
|
||||
framerate: f64,
|
||||
) -> f64 {
|
||||
match self.quantize_grid_size(bpm, time_sig, framerate) {
|
||||
match self.quantize_grid_size(tempo_map, time_sig, framerate) {
|
||||
Some(grid) => (t / grid).round() * grid,
|
||||
None => t,
|
||||
}
|
||||
@@ -1481,11 +1439,11 @@ impl TimelinePane {
|
||||
/// Snaps the anchor clip's resulting position to the grid; all selected clips use the same offset.
|
||||
fn snapped_move_offset(
|
||||
&self,
|
||||
bpm: f64,
|
||||
tempo_map: &daw_backend::TempoMap,
|
||||
time_sig: &lightningbeam_core::document::TimeSignature,
|
||||
framerate: f64,
|
||||
) -> f64 {
|
||||
match self.quantize_grid_size(bpm, time_sig, framerate) {
|
||||
match self.quantize_grid_size(tempo_map, time_sig, framerate) {
|
||||
Some(grid) => {
|
||||
let snapped = ((self.drag_anchor_start + self.drag_offset) / grid).round() * grid;
|
||||
snapped - self.drag_anchor_start
|
||||
@@ -1524,7 +1482,7 @@ impl TimelinePane {
|
||||
|
||||
/// Render the time ruler at the top
|
||||
fn render_ruler(&self, ui: &mut egui::Ui, rect: egui::Rect, theme: &crate::theme::Theme,
|
||||
bpm: f64, time_sig: &lightningbeam_core::document::TimeSignature, framerate: f64) {
|
||||
tempo_map: &daw_backend::TempoMap, time_sig: &lightningbeam_core::document::TimeSignature, framerate: f64) {
|
||||
let painter = ui.painter();
|
||||
|
||||
// Background
|
||||
@@ -1570,8 +1528,8 @@ impl TimelinePane {
|
||||
}
|
||||
}
|
||||
TimelineMode::Measures => {
|
||||
let beats_per_second = bpm / 60.0;
|
||||
let beat_dur = lightningbeam_core::beat_time::beat_duration(bpm);
|
||||
let beats_per_second = tempo_map.bpm_at(daw_backend::Beats(0.0)) / 60.0;
|
||||
let beat_dur = lightningbeam_core::beat_time::beat_duration(0.0, tempo_map);
|
||||
let bpm_count = time_sig.numerator;
|
||||
let px_per_beat = beat_dur as f32 * self.pixels_per_second;
|
||||
|
||||
@@ -1724,15 +1682,10 @@ impl TimelinePane {
|
||||
let note_style = theme.style(".timeline-midi-note", ctx);
|
||||
let note_color = note_style.background_color().unwrap_or(egui::Color32::BLACK);
|
||||
|
||||
// In Measures mode during BPM drag, derive display time from beats so notes
|
||||
// stay anchored to their beat positions.
|
||||
// `timestamp` is in beats; convert to display-seconds using the current (preview) BPM.
|
||||
let tempo_map = daw_backend::TempoMap::constant(display_bpm.unwrap_or(120.0));
|
||||
let event_display_time = |ev: &daw_backend::audio::midi::MidiEvent| -> f64 {
|
||||
if let Some(bpm) = display_bpm {
|
||||
if ev.timestamp_beats.abs() > 1e-12 || ev.timestamp == 0.0 {
|
||||
return ev.timestamp_beats * 60.0 / bpm;
|
||||
}
|
||||
}
|
||||
ev.timestamp
|
||||
tempo_map.transform(ev.timestamp.beats_to_f64())
|
||||
};
|
||||
|
||||
// Build a map of active notes (note_number -> note_on_timestamp)
|
||||
@@ -2782,7 +2735,7 @@ impl TimelinePane {
|
||||
}
|
||||
}
|
||||
TimelineMode::Measures => {
|
||||
let beats_per_second = document.bpm / 60.0;
|
||||
let beats_per_second = document.tempo_map().bpm_at(daw_backend::Beats(0.0)) / 60.0;
|
||||
let bpm_count = document.time_signature.numerator;
|
||||
let start_beat = (self.viewport_start_time.max(0.0) * beats_per_second).floor() as i64;
|
||||
let end_beat = (self.x_to_time(rect.width()) * beats_per_second).ceil() as i64;
|
||||
@@ -2860,10 +2813,10 @@ impl TimelinePane {
|
||||
ci.trim_end.unwrap_or(1.0) - ci.trim_start
|
||||
});
|
||||
let mut start = ci.effective_start();
|
||||
let dur = ci.total_duration(clip_dur);
|
||||
let dur = ci.total_duration(clip_dur, document.tempo_map());
|
||||
// Apply drag offset for selected clips during move
|
||||
if is_move_drag && selection.contains_clip_instance(&ci.id) {
|
||||
start = (start + self.snapped_move_offset(document.bpm, &document.time_signature, document.framerate)).max(0.0);
|
||||
start = (start + self.snapped_move_offset(document.tempo_map(), &document.time_signature, document.framerate)).max(0.0);
|
||||
}
|
||||
ranges.push((start, start + dur));
|
||||
}
|
||||
@@ -2933,9 +2886,9 @@ impl TimelinePane {
|
||||
.unwrap_or_else(|| ci.trim_end.unwrap_or(1.0) - ci.trim_start);
|
||||
let mut ci_start = ci.effective_start();
|
||||
if is_move_drag && selection.contains_clip_instance(&ci.id) {
|
||||
ci_start = (ci_start + self.snapped_move_offset(document.bpm, &document.time_signature, document.framerate)).max(0.0);
|
||||
ci_start = (ci_start + self.snapped_move_offset(document.tempo_map(), &document.time_signature, document.framerate)).max(0.0);
|
||||
}
|
||||
let ci_duration = ci.total_duration(clip_dur);
|
||||
let ci_duration = ci.total_duration(clip_dur, document.tempo_map());
|
||||
let ci_end = ci_start + ci_duration;
|
||||
|
||||
let sx = self.time_to_x(ci_start);
|
||||
@@ -3052,9 +3005,9 @@ impl TimelinePane {
|
||||
let clip_dur = audio_clip.duration;
|
||||
let mut ci_start = ci.effective_start();
|
||||
if is_move_drag && selection.contains_clip_instance(&ci.id) {
|
||||
ci_start = (ci_start + self.snapped_move_offset(document.bpm, &document.time_signature, document.framerate)).max(0.0);
|
||||
ci_start = (ci_start + self.snapped_move_offset(document.tempo_map(), &document.time_signature, document.framerate)).max(0.0);
|
||||
}
|
||||
let ci_duration = ci.total_duration(clip_dur);
|
||||
let ci_duration = ci.total_duration(clip_dur, document.tempo_map());
|
||||
|
||||
let ci_screen_start = rect.min.x + self.time_to_x(ci_start);
|
||||
let ci_screen_end = ci_screen_start + (ci_duration * self.pixels_per_second as f64) as f32;
|
||||
@@ -3150,11 +3103,11 @@ impl TimelinePane {
|
||||
.filter(|ci| selection.contains_clip_instance(&ci.id))
|
||||
.filter_map(|ci| {
|
||||
let dur = document.get_clip_duration(&ci.clip_id)?;
|
||||
Some((ci.id, ci.effective_start(), ci.total_duration(dur)))
|
||||
Some((ci.id, ci.effective_start(), ci.total_duration(dur, document.tempo_map())))
|
||||
})
|
||||
.collect();
|
||||
if !group.is_empty() {
|
||||
Some(document.clamp_group_move_offset(&layer.id(), &group, self.snapped_move_offset(document.bpm, &document.time_signature, document.framerate)))
|
||||
Some(document.clamp_group_move_offset(&layer.id(), &group, self.snapped_move_offset(document.tempo_map(), &document.time_signature, document.framerate)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -3167,7 +3120,7 @@ impl TimelinePane {
|
||||
let preview_ranges: Vec<(f64, f64)> = clip_instances.iter().map(|ci| {
|
||||
let clip_dur = effective_clip_duration(document, layer, ci).unwrap_or(0.0);
|
||||
let mut start = ci.effective_start();
|
||||
let mut duration = ci.total_duration(clip_dur);
|
||||
let mut duration = ci.total_duration(clip_dur, document.tempo_map());
|
||||
|
||||
let is_selected = selection.contains_clip_instance(&ci.id);
|
||||
let is_linked = if self.clip_drag_state.is_some() {
|
||||
@@ -3187,7 +3140,7 @@ impl TimelinePane {
|
||||
}
|
||||
}
|
||||
ClipDragType::TrimLeft => {
|
||||
let new_trim = self.snap_to_grid(ci.trim_start + self.drag_offset, document.bpm, &document.time_signature, document.framerate).max(0.0).min(clip_dur);
|
||||
let new_trim = self.snap_to_grid(ci.trim_start + self.drag_offset, document.tempo_map(), &document.time_signature, document.framerate).max(0.0).min(clip_dur);
|
||||
let offset = new_trim - ci.trim_start;
|
||||
start = (ci.timeline_start + offset).max(0.0);
|
||||
duration = (clip_dur - new_trim).max(0.0);
|
||||
@@ -3197,7 +3150,7 @@ impl TimelinePane {
|
||||
}
|
||||
ClipDragType::TrimRight => {
|
||||
let old_trim_end = ci.trim_end.unwrap_or(clip_dur);
|
||||
let new_trim_end = self.snap_to_grid(old_trim_end + self.drag_offset, document.bpm, &document.time_signature, document.framerate).max(ci.trim_start).min(clip_dur);
|
||||
let new_trim_end = self.snap_to_grid(old_trim_end + self.drag_offset, document.tempo_map(), &document.time_signature, document.framerate).max(ci.trim_start).min(clip_dur);
|
||||
duration = (new_trim_end - ci.trim_start).max(0.0);
|
||||
}
|
||||
ClipDragType::LoopExtendRight => {
|
||||
@@ -3205,7 +3158,7 @@ impl TimelinePane {
|
||||
let content_window = (trim_end - ci.trim_start).max(0.0);
|
||||
let current_right = ci.timeline_duration.unwrap_or(content_window);
|
||||
let right_edge = ci.timeline_start + current_right + self.drag_offset;
|
||||
let snapped_edge = self.snap_to_grid(right_edge, document.bpm, &document.time_signature, document.framerate);
|
||||
let snapped_edge = self.snap_to_grid(right_edge, document.tempo_map(), &document.time_signature, document.framerate);
|
||||
let new_right = (snapped_edge - ci.timeline_start).max(content_window);
|
||||
let loop_before = ci.loop_before.unwrap_or(0.0);
|
||||
duration = loop_before + new_right;
|
||||
@@ -3217,7 +3170,7 @@ impl TimelinePane {
|
||||
let desired = (current_loop_before - self.drag_offset).max(0.0);
|
||||
let snapped = (desired / content_window).round() * content_window;
|
||||
start = ci.timeline_start - snapped;
|
||||
duration = snapped + ci.effective_duration(clip_dur);
|
||||
duration = snapped + ci.effective_duration(clip_dur, document.tempo_map());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3236,13 +3189,13 @@ impl TimelinePane {
|
||||
if let Some(clip_duration) = clip_duration {
|
||||
// Calculate effective duration accounting for trimming.
|
||||
// In Measures mode, uses beats fields so width tracks BPM during live drag.
|
||||
let mut instance_duration = self.instance_display_duration(clip_instance, clip_duration, document.bpm);
|
||||
let mut instance_duration = self.instance_display_duration(clip_instance, clip_duration, document.tempo_map());
|
||||
|
||||
// Instance positioned on the layer's timeline using timeline_start.
|
||||
// In Measures mode, uses timeline_start_beats so clips stay at their beat
|
||||
// position during live BPM drag preview.
|
||||
let _layer_data = layer.layer();
|
||||
let mut instance_start = self.instance_display_start(clip_instance, document.bpm);
|
||||
let mut instance_start = self.instance_display_start(clip_instance, document.tempo_map());
|
||||
|
||||
// Apply drag offset preview for selected clips with snapping
|
||||
let is_selected = selection.contains_clip_instance(&clip_instance.id);
|
||||
@@ -3267,7 +3220,7 @@ impl TimelinePane {
|
||||
|
||||
// Track preview trim values for note/waveform rendering.
|
||||
// In Measures mode, derive from beats so they track BPM during live drag.
|
||||
let (base_trim_start, base_clip_duration) = self.content_display_range(clip_instance, clip_duration, document.bpm);
|
||||
let (base_trim_start, base_clip_duration) = self.content_display_range(clip_instance, clip_duration, document.bpm());
|
||||
let mut preview_trim_start = base_trim_start;
|
||||
let mut preview_clip_duration = base_clip_duration;
|
||||
|
||||
@@ -3282,7 +3235,7 @@ impl TimelinePane {
|
||||
}
|
||||
ClipDragType::TrimLeft => {
|
||||
// Trim left: calculate new trim_start with snap to adjacent clips
|
||||
let desired_trim_start = self.snap_to_grid(clip_instance.trim_start + self.drag_offset, document.bpm, &document.time_signature, document.framerate)
|
||||
let desired_trim_start = self.snap_to_grid(clip_instance.trim_start + self.drag_offset, document.tempo_map(), &document.time_signature, document.framerate)
|
||||
.max(0.0)
|
||||
.min(clip_duration);
|
||||
|
||||
@@ -3322,7 +3275,7 @@ impl TimelinePane {
|
||||
ClipDragType::TrimRight => {
|
||||
// Trim right: extend or reduce duration with snap to adjacent clips
|
||||
let old_trim_end = clip_instance.trim_end.unwrap_or(clip_duration);
|
||||
let desired_trim_end = self.snap_to_grid(old_trim_end + self.drag_offset, document.bpm, &document.time_signature, document.framerate)
|
||||
let desired_trim_end = self.snap_to_grid(old_trim_end + self.drag_offset, document.tempo_map(), &document.time_signature, document.framerate)
|
||||
.max(clip_instance.trim_start)
|
||||
.min(clip_duration);
|
||||
|
||||
@@ -3356,7 +3309,7 @@ impl TimelinePane {
|
||||
let content_window = (trim_end - clip_instance.trim_start).max(0.0);
|
||||
let current_right = clip_instance.timeline_duration.unwrap_or(content_window);
|
||||
let right_edge = clip_instance.timeline_start + current_right + self.drag_offset;
|
||||
let snapped_edge = self.snap_to_grid(right_edge, document.bpm, &document.time_signature, document.framerate);
|
||||
let snapped_edge = self.snap_to_grid(right_edge, document.tempo_map(), &document.time_signature, document.framerate);
|
||||
let desired_right = (snapped_edge - clip_instance.timeline_start).max(content_window);
|
||||
|
||||
let new_right = if desired_right > current_right {
|
||||
@@ -3404,7 +3357,7 @@ impl TimelinePane {
|
||||
};
|
||||
|
||||
// Recompute instance_start and instance_duration
|
||||
let right_duration = clip_instance.effective_duration(clip_duration);
|
||||
let right_duration = clip_instance.effective_duration(clip_duration, document.tempo_map());
|
||||
instance_start = clip_instance.timeline_start - new_loop_before;
|
||||
instance_duration = new_loop_before + right_duration;
|
||||
content_origin = clip_instance.timeline_start;
|
||||
@@ -3525,7 +3478,7 @@ impl TimelinePane {
|
||||
if iter_duration <= 0.0 { continue; }
|
||||
|
||||
let note_bpm = if self.time_display_format == lightningbeam_core::document::TimelineMode::Measures {
|
||||
Some(document.bpm)
|
||||
Some(document.bpm())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
@@ -3547,7 +3500,7 @@ impl TimelinePane {
|
||||
}
|
||||
} else {
|
||||
let note_bpm = if self.time_display_format == lightningbeam_core::document::TimelineMode::Measures {
|
||||
Some(document.bpm)
|
||||
Some(document.bpm())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
@@ -4066,7 +4019,7 @@ impl TimelinePane {
|
||||
let clip_duration = effective_clip_duration(document, layer, clip_instance);
|
||||
|
||||
if let Some(clip_duration) = clip_duration {
|
||||
let instance_duration = clip_instance.total_duration(clip_duration);
|
||||
let instance_duration = clip_instance.total_duration(clip_duration, document.tempo_map());
|
||||
let instance_start = clip_instance.effective_start();
|
||||
let instance_end = instance_start + instance_duration;
|
||||
|
||||
@@ -4419,7 +4372,7 @@ impl TimelinePane {
|
||||
HashMap::new();
|
||||
|
||||
// Compute snapped offset once for all selected clips (preserves relative spacing)
|
||||
let move_offset = self.snapped_move_offset(document.bpm, &document.time_signature, document.framerate);
|
||||
let move_offset = self.snapped_move_offset(document.tempo_map(), &document.time_signature, document.framerate);
|
||||
|
||||
// Iterate through all layers (including group children) to find selected clip instances
|
||||
for (layer, clip_instances) in all_layer_clip_instances(context_layers, &audio_cache) {
|
||||
@@ -4481,8 +4434,7 @@ impl TimelinePane {
|
||||
|
||||
// New trim_start is snapped then clamped to valid range
|
||||
let desired_trim_start = self.snap_to_grid(
|
||||
old_trim_start + self.drag_offset,
|
||||
document.bpm, &document.time_signature, document.framerate,
|
||||
old_trim_start + self.drag_offset, document.tempo_map(), &document.time_signature, document.framerate,
|
||||
).max(0.0).min(clip_duration);
|
||||
|
||||
// Apply overlap prevention when extending left
|
||||
@@ -4525,11 +4477,10 @@ impl TimelinePane {
|
||||
|
||||
// Calculate new trim_end based on current duration
|
||||
let current_duration =
|
||||
clip_instance.effective_duration(clip_duration);
|
||||
clip_instance.effective_duration(clip_duration, document.tempo_map());
|
||||
let old_trim_end_val = clip_instance.trim_end.unwrap_or(clip_duration);
|
||||
let desired_trim_end = self.snap_to_grid(
|
||||
old_trim_end_val + self.drag_offset,
|
||||
document.bpm, &document.time_signature, document.framerate,
|
||||
old_trim_end_val + self.drag_offset, document.tempo_map(), &document.time_signature, document.framerate,
|
||||
).max(clip_instance.trim_start).min(clip_duration);
|
||||
|
||||
// Apply overlap prevention when extending right
|
||||
@@ -4607,7 +4558,7 @@ impl TimelinePane {
|
||||
let content_window = (trim_end - clip_instance.trim_start).max(0.0);
|
||||
let current_right = clip_instance.timeline_duration.unwrap_or(content_window);
|
||||
let right_edge = clip_instance.timeline_start + current_right + self.drag_offset;
|
||||
let snapped_edge = self.snap_to_grid(right_edge, document.bpm, &document.time_signature, document.framerate);
|
||||
let snapped_edge = self.snap_to_grid(right_edge, document.tempo_map(), &document.time_signature, document.framerate);
|
||||
let desired_right = snapped_edge - clip_instance.timeline_start;
|
||||
|
||||
let new_right = if desired_right > current_right {
|
||||
@@ -4785,7 +4736,7 @@ impl TimelinePane {
|
||||
if cursor_over_ruler && !alt_held && (response.clicked() || (response.dragged() && !self.is_panning)) {
|
||||
if let Some(pos) = response.interact_pointer_pos() {
|
||||
let x = (pos.x - content_rect.min.x).max(0.0);
|
||||
let new_time = self.snap_to_grid(self.x_to_time(x).max(0.0), document.bpm, &document.time_signature, document.framerate);
|
||||
let new_time = self.snap_to_grid(self.x_to_time(x).max(0.0), document.tempo_map(), &document.time_signature, document.framerate);
|
||||
*playback_time = new_time;
|
||||
self.is_scrubbing = true;
|
||||
// Seek immediately so it works while playing
|
||||
@@ -4799,7 +4750,7 @@ impl TimelinePane {
|
||||
else if self.is_scrubbing && response.dragged() && !self.is_panning {
|
||||
if let Some(pos) = response.interact_pointer_pos() {
|
||||
let x = (pos.x - content_rect.min.x).max(0.0);
|
||||
let new_time = self.snap_to_grid(self.x_to_time(x).max(0.0), document.bpm, &document.time_signature, document.framerate);
|
||||
let new_time = self.snap_to_grid(self.x_to_time(x).max(0.0), document.tempo_map(), &document.time_signature, document.framerate);
|
||||
*playback_time = new_time;
|
||||
if let Some(controller_arc) = audio_controller {
|
||||
let mut controller = controller_arc.lock().unwrap();
|
||||
@@ -5092,9 +5043,9 @@ impl PaneRenderer for TimelinePane {
|
||||
|
||||
// Time display (format-dependent)
|
||||
{
|
||||
let (bpm, time_sig_num, time_sig_den, framerate) = {
|
||||
let (tempo_map, bpm, time_sig_num, time_sig_den, framerate) = {
|
||||
let doc = shared.action_executor.document();
|
||||
(doc.bpm, doc.time_signature.numerator, doc.time_signature.denominator, doc.framerate)
|
||||
(doc.tempo_map().clone(), doc.bpm(), doc.time_signature.numerator, doc.time_signature.denominator, doc.framerate)
|
||||
};
|
||||
|
||||
match self.time_display_format {
|
||||
@@ -5104,7 +5055,7 @@ impl PaneRenderer for TimelinePane {
|
||||
TimelineMode::Measures => {
|
||||
let time_sig = lightningbeam_core::document::TimeSignature { numerator: time_sig_num, denominator: time_sig_den };
|
||||
let pos = lightningbeam_core::beat_time::time_to_measure(
|
||||
*shared.playback_time, bpm, &time_sig,
|
||||
*shared.playback_time, &tempo_map, &time_sig,
|
||||
);
|
||||
ui.colored_label(text_color, format!(
|
||||
"BAR: {}.{} | BPM: {:.0} | {}/{}",
|
||||
@@ -5204,7 +5155,7 @@ impl PaneRenderer for TimelinePane {
|
||||
self.bpm_drag_start = Some(bpm);
|
||||
}
|
||||
// Live preview: update document directly so grid reflows immediately
|
||||
shared.action_executor.document_mut().bpm = bpm_val;
|
||||
shared.action_executor.document_mut().set_bpm(bpm_val);
|
||||
if let Some(controller_arc) = shared.audio_controller {
|
||||
let mut controller = controller_arc.lock().unwrap();
|
||||
controller.set_tempo(bpm_val as f32, (time_sig_num, time_sig_den));
|
||||
@@ -5214,35 +5165,17 @@ impl PaneRenderer for TimelinePane {
|
||||
// On commit, dispatch a single ChangeBpmAction (single undo entry)
|
||||
if bpm_response.drag_stopped() || bpm_response.lost_focus() {
|
||||
if let Some(start_bpm) = self.bpm_drag_start.take() {
|
||||
let new_bpm = shared.action_executor.document().bpm;
|
||||
let new_bpm = shared.action_executor.document().bpm();
|
||||
if (start_bpm - new_bpm).abs() > 1e-6
|
||||
&& self.time_display_format == lightningbeam_core::document::TimelineMode::Measures
|
||||
{
|
||||
use lightningbeam_core::actions::ChangeBpmAction;
|
||||
// document.bpm is already new_bpm from the live preview — keep it.
|
||||
// ChangeBpmAction::new uses the passed old/new params, not document.bpm,
|
||||
// so we don't need to revert (which would cause a one-frame flash).
|
||||
// document.bpm() is already new_bpm from the live preview — build action
|
||||
// with new_bpm so it records the correct undo state.
|
||||
let action = ChangeBpmAction::new(
|
||||
start_bpm,
|
||||
new_bpm,
|
||||
shared.action_executor.document(),
|
||||
shared.midi_event_cache,
|
||||
);
|
||||
// Immediately update midi_event_cache for rendering
|
||||
for (clip_id, events) in action.new_midi_events() {
|
||||
shared.midi_event_cache.insert(clip_id, events.clone());
|
||||
}
|
||||
// Optimistically rescale automation keyframe times in the cache.
|
||||
// The backend rescales asynchronously via ApplyBpmChange; this keeps
|
||||
// the cache consistent without waiting for the engine to round-trip.
|
||||
let scale = start_bpm / new_bpm;
|
||||
for lanes in self.automation_cache.values_mut() {
|
||||
for lane in lanes.iter_mut() {
|
||||
for kf in lane.keyframes.iter_mut() {
|
||||
kf.time *= scale;
|
||||
}
|
||||
}
|
||||
}
|
||||
shared.pending_actions.push(Box::new(action));
|
||||
}
|
||||
}
|
||||
@@ -5271,7 +5204,7 @@ impl PaneRenderer for TimelinePane {
|
||||
doc.time_signature.denominator = *den;
|
||||
if let Some(controller_arc) = shared.audio_controller {
|
||||
let mut controller = controller_arc.lock().unwrap();
|
||||
controller.set_tempo(doc.bpm as f32, (*num, *den));
|
||||
controller.set_tempo(doc.bpm() as f32, (*num, *den));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5331,7 +5264,7 @@ impl PaneRenderer for TimelinePane {
|
||||
let clip_duration = effective_clip_duration(document, layer, clip_instance);
|
||||
|
||||
if let Some(clip_duration) = clip_duration {
|
||||
let instance_duration = clip_instance.effective_duration(clip_duration);
|
||||
let instance_duration = clip_instance.effective_duration(clip_duration, document.tempo_map());
|
||||
let instance_end = clip_instance.timeline_start + instance_duration;
|
||||
max_endpoint = max_endpoint.max(instance_end);
|
||||
}
|
||||
@@ -5390,7 +5323,7 @@ impl PaneRenderer for TimelinePane {
|
||||
|
||||
// Render time ruler (clip to ruler rect)
|
||||
ui.set_clip_rect(ruler_rect.intersect(original_clip_rect));
|
||||
self.render_ruler(ui, ruler_rect, shared.theme, document.bpm, &document.time_signature, document.framerate);
|
||||
self.render_ruler(ui, ruler_rect, shared.theme, document.tempo_map(), &document.time_signature, document.framerate);
|
||||
|
||||
// Render layer rows with clipping
|
||||
ui.set_clip_rect(content_rect.intersect(original_clip_rect));
|
||||
@@ -5486,8 +5419,8 @@ impl PaneRenderer for TimelinePane {
|
||||
// Invalidate automation cache when BPM changes (but not during a live drag —
|
||||
// during drag the backend hasn't rescaled yet so re-querying would give stale data).
|
||||
let bpm_committed = self.bpm_drag_start.is_none();
|
||||
if bpm_committed && (document.bpm - self.automation_cache_bpm).abs() > 1e-9 {
|
||||
self.automation_cache_bpm = document.bpm;
|
||||
if bpm_committed && (document.bpm() - self.automation_cache_bpm).abs() > 1e-9 {
|
||||
self.automation_cache_bpm = document.bpm();
|
||||
self.automation_cache.clear();
|
||||
}
|
||||
|
||||
@@ -5631,7 +5564,7 @@ impl PaneRenderer for TimelinePane {
|
||||
for inst in instances {
|
||||
if !shared.selection.contains_clip_instance(&inst.id) { continue; }
|
||||
if let Some(dur) = document.get_clip_duration(&inst.clip_id) {
|
||||
let eff = inst.effective_duration(dur);
|
||||
let eff = inst.effective_duration(dur, document.tempo_map());
|
||||
let start = inst.timeline_start;
|
||||
let end = start + eff;
|
||||
let min_dist = min_split_px as f64 / self.pixels_per_second as f64;
|
||||
@@ -5657,7 +5590,7 @@ impl PaneRenderer for TimelinePane {
|
||||
.filter(|ci| shared.selection.contains_clip_instance(&ci.id))
|
||||
.all(|ci| {
|
||||
if let Some(dur) = document.get_clip_duration(&ci.clip_id) {
|
||||
let eff = ci.effective_duration(dur);
|
||||
let eff = ci.effective_duration(dur, document.tempo_map());
|
||||
let max_extend = document.find_max_trim_extend_right(
|
||||
&layer_id, &ci.id, ci.timeline_start, eff,
|
||||
);
|
||||
@@ -5696,7 +5629,7 @@ impl PaneRenderer for TimelinePane {
|
||||
enabled = instances.iter().all(|ci| {
|
||||
let paste_start = (ci.timeline_start + offset).max(0.0);
|
||||
if let Some(dur) = document.get_clip_duration(&ci.clip_id) {
|
||||
let eff = ci.effective_duration(dur);
|
||||
let eff = ci.effective_duration(dur, document.tempo_map());
|
||||
document
|
||||
.find_nearest_valid_position(
|
||||
&layer_id,
|
||||
|
||||
Reference in New Issue
Block a user