Add custom layouts, piano pane, midi file import
This commit is contained in:
@@ -149,6 +149,12 @@ impl Engine {
|
||||
}
|
||||
}
|
||||
|
||||
/// Process live MIDI input from all MIDI tracks
|
||||
fn process_live_midi(&mut self, output: &mut [f32]) {
|
||||
// Process all MIDI tracks to handle live input
|
||||
self.project.process_live_midi(output, self.sample_rate, self.channels);
|
||||
}
|
||||
|
||||
/// Process audio callback - called from the audio thread
|
||||
pub fn process(&mut self, output: &mut [f32]) {
|
||||
// Process all pending commands
|
||||
@@ -203,8 +209,8 @@ impl Engine {
|
||||
self.frames_since_last_event = 0;
|
||||
}
|
||||
} else {
|
||||
// Not playing, output silence
|
||||
output.fill(0.0);
|
||||
// Not playing, but process live MIDI input
|
||||
self.process_live_midi(output);
|
||||
}
|
||||
|
||||
// Process recording if active (independent of playback state)
|
||||
@@ -263,9 +269,13 @@ impl Engine {
|
||||
self.playing = false;
|
||||
self.playhead = 0;
|
||||
self.playhead_atomic.store(0, Ordering::Relaxed);
|
||||
// Stop all MIDI notes when stopping playback
|
||||
self.project.stop_all_notes();
|
||||
}
|
||||
Command::Pause => {
|
||||
self.playing = false;
|
||||
// Stop all MIDI notes when pausing playback
|
||||
self.project.stop_all_notes();
|
||||
}
|
||||
Command::Seek(seconds) => {
|
||||
let samples = (seconds * self.sample_rate as f64 * self.channels as f64) as u64;
|
||||
@@ -673,6 +683,16 @@ impl Engine {
|
||||
// Notify UI that reset is complete
|
||||
let _ = self.event_tx.push(AudioEvent::ProjectReset);
|
||||
}
|
||||
|
||||
Command::SendMidiNoteOn(track_id, note, velocity) => {
|
||||
// Send a live MIDI note on event to the specified track's instrument
|
||||
self.project.send_midi_note_on(track_id, note, velocity);
|
||||
}
|
||||
|
||||
Command::SendMidiNoteOff(track_id, note) => {
|
||||
// Send a live MIDI note off event to the specified track's instrument
|
||||
self.project.send_midi_note_off(track_id, note);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1083,4 +1103,14 @@ impl EngineController {
|
||||
pub fn reset(&mut self) {
|
||||
let _ = self.command_tx.push(Command::Reset);
|
||||
}
|
||||
|
||||
/// Send a live MIDI note on event to a track's instrument
|
||||
pub fn send_midi_note_on(&mut self, track_id: TrackId, note: u8, velocity: u8) {
|
||||
let _ = self.command_tx.push(Command::SendMidiNoteOn(track_id, note, velocity));
|
||||
}
|
||||
|
||||
/// Send a live MIDI note off event to a track's instrument
|
||||
pub fn send_midi_note_off(&mut self, track_id: TrackId, note: u8) {
|
||||
let _ = self.command_tx.push(Command::SendMidiNoteOff(track_id, note));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -406,6 +406,54 @@ impl Project {
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
|
||||
/// Stop all notes on all MIDI tracks
|
||||
pub fn stop_all_notes(&mut self) {
|
||||
for track in self.tracks.values_mut() {
|
||||
if let TrackNode::Midi(midi_track) = track {
|
||||
midi_track.stop_all_notes();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Process live MIDI input from all MIDI tracks (called even when not playing)
|
||||
pub fn process_live_midi(&mut self, output: &mut [f32], sample_rate: u32, channels: u32) {
|
||||
// Process all MIDI tracks to handle queued live input events
|
||||
for track in self.tracks.values_mut() {
|
||||
if let TrackNode::Midi(midi_track) = track {
|
||||
// Process only queued live events, not clips
|
||||
midi_track.process_live_input(output, sample_rate, channels);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Send a live MIDI note on event to a track's instrument
|
||||
pub fn send_midi_note_on(&mut self, track_id: TrackId, note: u8, velocity: u8) {
|
||||
if let Some(TrackNode::Midi(track)) = self.tracks.get_mut(&track_id) {
|
||||
// Create a MIDI event and queue it to the instrument
|
||||
let event = crate::audio::midi::MidiEvent {
|
||||
timestamp: 0, // Immediate playback
|
||||
status: 0x90, // Note on
|
||||
data1: note,
|
||||
data2: velocity,
|
||||
};
|
||||
track.instrument.queue_event(event);
|
||||
}
|
||||
}
|
||||
|
||||
/// Send a live MIDI note off event to a track's instrument
|
||||
pub fn send_midi_note_off(&mut self, track_id: TrackId, note: u8) {
|
||||
if let Some(TrackNode::Midi(track)) = self.tracks.get_mut(&track_id) {
|
||||
// Create a MIDI event and queue it to the instrument
|
||||
let event = crate::audio::midi::MidiEvent {
|
||||
timestamp: 0, // Immediate playback
|
||||
status: 0x80, // Note off
|
||||
data1: note,
|
||||
data2: 0,
|
||||
};
|
||||
track.instrument.queue_event(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Project {
|
||||
|
||||
@@ -388,6 +388,33 @@ impl MidiTrack {
|
||||
!self.muted && (!any_solo || self.solo)
|
||||
}
|
||||
|
||||
/// Stop all currently playing notes on this track's instrument
|
||||
pub fn stop_all_notes(&mut self) {
|
||||
self.instrument.all_notes_off();
|
||||
}
|
||||
|
||||
/// Process only live MIDI input (queued events) without rendering clips
|
||||
/// This is used when playback is stopped but we want to hear live input
|
||||
pub fn process_live_input(
|
||||
&mut self,
|
||||
output: &mut [f32],
|
||||
sample_rate: u32,
|
||||
channels: u32,
|
||||
) {
|
||||
// Generate audio from the instrument (which processes queued events)
|
||||
self.instrument.process(output, channels as usize, sample_rate);
|
||||
|
||||
// Apply effect chain
|
||||
for effect in &mut self.effects {
|
||||
effect.process(output, channels as usize, sample_rate);
|
||||
}
|
||||
|
||||
// Apply track volume (no automation during live input)
|
||||
for sample in output.iter_mut() {
|
||||
*sample *= self.volume;
|
||||
}
|
||||
}
|
||||
|
||||
/// Render this MIDI track into the output buffer
|
||||
pub fn render(
|
||||
&mut self,
|
||||
|
||||
Reference in New Issue
Block a user