Take management: move takes onto the clip instance
Take management should be per clip instance — deleting a take from one half of a comped split shouldn't pull it out from under the other half. That's cleanest if the takes themselves live on the instance rather than the clip, so they do now. AudioClipType::TakeFolder is gone entirely. A clip is plain Sampled/Midi content again, and an instance with a non-empty `takes` list simply OVERRIDES it with whichever take is active. Splitting already clones the instance, so each half gets its own take list for free — no index remapping across instances, no copy-on-write, no shared-state surprise — and comping still works, because the halves can still each select a different take. It collapsed machinery too: resolve() moved from the clip to the instance, and owns_audio_pool_index went back to a one-liner. Management (DeleteTakeAction, DeleteUnusedTakesAction, RenameTakeAction): - Right-click a clip with more than one take: `Delete "<active take>"` and "Delete Unused Takes". Deletion is named after the take that's PLAYING rather than being a generic entry, so you pick the victim by selecting it — one clear act instead of hunting a small trash icon in a list (which is where this started, and it was fiddly). - Double-click a take in the dropdown to rename it in place. - What happens to the selection on delete is the subtle part, and there's a test per case: deleting a take BELOW the active one shifts the selection down so you keep hearing the same take; deleting the ACTIVE take lands on whatever slid into its place (not silently back to take 1); deleting the LAST take steps back one. The only take can't be deleted at all — the menu item isn't offered. - Deleted takes' audio stays in the pool: undo has to put it back, and the other half of a split may still be playing it. Fixes: - A recording that stopped before the loop came round wasn't joining an existing take list — it landed as a separate overlapping clip. Trigger- on-wrap is right for the FIRST recording, but once takes exist there, a further run is plainly another take however short. The engine can't know that (it's document state), so the editor passes `force_takes` with the start-recording command and the run is cut and padded to the region even with zero wraps. This forced cycle_loop_len and `wrapped` apart on the MIDI side: the region length has to be known from the start, but the clip should only pin to full-region length AFTER a pass completes, or the bar jumps to full width the moment you hit record. - Recording a second take left BOTH sounding. append_cycle_takes tore down the recording's backend clip by looking it up in clip_instance_to_backend_map — but on the audio path the recording instance isn't in that map yet; it's only added during promotion, which the append path skips. The event already carries the engine's clip id, so it's handed over explicitly now. - The take badge is hidden when there's only one take — no choice to make.
This commit is contained in:
@@ -24,9 +24,20 @@ pub struct CycleRecordInfo {
|
||||
/// punch-in (record while already rolling); take 1 gets this much silence prepended so it still
|
||||
/// spans the whole region.
|
||||
pub lead_pad_frames: usize,
|
||||
/// How many times the transport wrapped during this recording. Zero means the user stopped
|
||||
/// before completing a pass, which stays an ordinary single recording.
|
||||
/// How many times the transport wrapped during this recording. Zero normally means the user
|
||||
/// stopped before completing a pass, which stays an ordinary single recording — unless
|
||||
/// `force_takes` says otherwise.
|
||||
pub wrap_count: usize,
|
||||
/// Cut takes even if the transport never wrapped.
|
||||
///
|
||||
/// Set when the region already holds takes: a further recording there is another take, however
|
||||
/// short, and it gets padded out to the region like any partial pass. Without this a run that
|
||||
/// stopped before the loop came round would land as a separate overlapping clip instead of
|
||||
/// joining the take list.
|
||||
///
|
||||
/// The editor decides this at record start, because whether takes already exist is document
|
||||
/// state the engine can't see.
|
||||
pub force_takes: bool,
|
||||
}
|
||||
|
||||
/// Min/max waveform peaks for a finished buffer of interleaved samples.
|
||||
@@ -130,7 +141,7 @@ impl RecordingState {
|
||||
/// single recording, which keeps the existing path untouched).
|
||||
pub fn slice_takes(&self) -> Option<Vec<Vec<f32>>> {
|
||||
let cycle = self.cycle?;
|
||||
if cycle.wrap_count == 0 || cycle.loop_len_frames == 0 {
|
||||
if (cycle.wrap_count == 0 && !cycle.force_takes) || cycle.loop_len_frames == 0 {
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -295,13 +306,19 @@ pub struct MidiRecordingState {
|
||||
active_notes: HashMap<u8, ActiveMidiNote>,
|
||||
/// Completed notes: (time_offset, note, velocity, duration) — all times in beats
|
||||
pub completed_notes: Vec<(Beats, u8, u8, Beats)>,
|
||||
/// The cycle region's length in beats, when recording into a cycle.
|
||||
/// The cycle region's length in beats, if one was armed at record start.
|
||||
///
|
||||
/// A cycle MIDI recording is anchored at the region start (`start_time == loop_start`), which is
|
||||
/// what makes MERGE fall out for free: the transport always wraps back into the region, so every
|
||||
/// note's offset already lands inside `[0, loop_len)` and successive passes overdub onto each
|
||||
/// other with no folding needed. Set only if the transport actually wrapped.
|
||||
/// other with no folding needed.
|
||||
pub cycle_loop_len: Option<Beats>,
|
||||
/// Whether the transport actually came round. Distinct from `cycle_loop_len`, which only says a
|
||||
/// region was armed: the clip only pins to the full region once a pass has completed, so until
|
||||
/// then the bar still grows with the playhead.
|
||||
pub wrapped: bool,
|
||||
/// Cut takes even if the transport never wrapped — see [`CycleRecordInfo::force_takes`].
|
||||
pub force_takes: bool,
|
||||
/// Which cycle pass is currently being recorded (0-based). Bumped at each wrap.
|
||||
current_pass: usize,
|
||||
/// The pass each completed note belongs to, parallel to `completed_notes`.
|
||||
@@ -320,6 +337,8 @@ impl MidiRecordingState {
|
||||
active_notes: HashMap::new(),
|
||||
completed_notes: Vec::new(),
|
||||
cycle_loop_len: None,
|
||||
wrapped: false,
|
||||
force_takes: false,
|
||||
current_pass: 0,
|
||||
note_pass: Vec::new(),
|
||||
}
|
||||
@@ -450,9 +469,10 @@ impl MidiRecordingState {
|
||||
self.note_on(note, velocity, region_start);
|
||||
}
|
||||
|
||||
// The transport wrapped, so this is a cycle recording: the clip spans the whole region
|
||||
// rather than however long the user happened to hold the record button.
|
||||
// A pass has completed, so from here the clip spans the whole region rather than however long
|
||||
// the user happens to hold the record button.
|
||||
self.cycle_loop_len = Some(region_end - region_start);
|
||||
self.wrapped = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -462,6 +482,14 @@ mod cycle_tests {
|
||||
|
||||
/// A recording state holding `audio_data`, armed for cycle recording. Mono, 100 Hz, so a frame
|
||||
/// is a sample and 5 frames is 50 ms (exactly the min-take threshold).
|
||||
fn rec_forced(audio: Vec<f32>, loop_len_frames: usize, lead_pad_frames: usize, wraps: usize) -> RecordingState {
|
||||
let mut r = rec(audio, loop_len_frames, lead_pad_frames, wraps);
|
||||
if let Some(c) = r.cycle.as_mut() {
|
||||
c.force_takes = true;
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
fn rec(audio: Vec<f32>, loop_len_frames: usize, lead_pad_frames: usize, wraps: usize) -> RecordingState {
|
||||
let mut r = RecordingState::new(
|
||||
0,
|
||||
@@ -480,6 +508,7 @@ mod cycle_tests {
|
||||
loop_len_frames,
|
||||
lead_pad_frames,
|
||||
wrap_count: wraps,
|
||||
force_takes: false,
|
||||
});
|
||||
r
|
||||
}
|
||||
@@ -492,6 +521,18 @@ mod cycle_tests {
|
||||
assert!(r.slice_takes().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn force_takes_makes_a_partial_pass_a_take() {
|
||||
// Recording over a region that already holds takes: this run is another take however short
|
||||
// it ran, so it's cut and padded like any partial pass rather than landing as a separate
|
||||
// overlapping clip. Two real frames of an 8-frame region -> one take, silence for the rest.
|
||||
let takes = rec_forced(vec![1.0, 2.0], 8, 0, 0)
|
||||
.slice_takes()
|
||||
.expect("forced takes");
|
||||
assert_eq!(takes.len(), 1);
|
||||
assert_eq!(takes[0], vec![1.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn takes_are_cut_at_exact_loop_multiples() {
|
||||
// 12 frames of audio, 4-frame loop, started at the region start => 3 clean takes.
|
||||
|
||||
Reference in New Issue
Block a user