Fix midi tracks recording previews
This commit is contained in:
@@ -416,13 +416,23 @@ impl Engine {
|
||||
if let Some(recording) = &self.midi_recording_state {
|
||||
let current_time = self.playhead as f64 / self.sample_rate as f64;
|
||||
let duration = current_time - recording.start_time;
|
||||
let notes = recording.get_notes().to_vec();
|
||||
let notes = recording.get_notes_with_active(current_time);
|
||||
let _ = self.event_tx.push(AudioEvent::MidiRecordingProgress(
|
||||
recording.track_id,
|
||||
recording.clip_id,
|
||||
duration,
|
||||
notes,
|
||||
));
|
||||
// Keep the snapshot up to date so the UI can display a growing clip bar.
|
||||
let track_id = recording.track_id;
|
||||
let clip_id = recording.clip_id;
|
||||
if let Some(crate::audio::track::TrackNode::Midi(track)) = self.project.get_track_mut(track_id) {
|
||||
if let Some(instance) = track.clip_instances.iter_mut().find(|i| i.clip_id == clip_id) {
|
||||
instance.internal_end = duration;
|
||||
instance.external_duration = duration;
|
||||
}
|
||||
}
|
||||
self.refresh_clip_snapshot();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -253,6 +253,18 @@ impl MidiRecordingState {
|
||||
self.completed_notes.len()
|
||||
}
|
||||
|
||||
/// Get all completed notes plus currently-held notes with a provisional duration.
|
||||
/// Used for live preview during recording so held notes appear immediately.
|
||||
pub fn get_notes_with_active(&self, current_time: f64) -> Vec<(f64, u8, u8, f64)> {
|
||||
let mut notes = self.completed_notes.clone();
|
||||
for active in self.active_notes.values() {
|
||||
let time_offset = active.start_time - self.start_time;
|
||||
let provisional_dur = (current_time - active.start_time).max(0.0);
|
||||
notes.push((time_offset, active.note, active.velocity, provisional_dur));
|
||||
}
|
||||
notes
|
||||
}
|
||||
|
||||
/// Get the note numbers of all currently held (active) notes
|
||||
pub fn active_note_numbers(&self) -> Vec<u8> {
|
||||
self.active_notes.keys().copied().collect()
|
||||
|
||||
Reference in New Issue
Block a user