midi import in daw backend
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
use daw_backend::load_midi_file;
|
||||
|
||||
fn main() {
|
||||
let clip = load_midi_file("darude-sandstorm.mid", 0, 44100).unwrap();
|
||||
|
||||
println!("Clip duration: {:.2}s", clip.duration);
|
||||
println!("Total events: {}", clip.events.len());
|
||||
println!("\nEvent summary:");
|
||||
|
||||
let mut note_on_count = 0;
|
||||
let mut note_off_count = 0;
|
||||
let mut other_count = 0;
|
||||
|
||||
for event in &clip.events {
|
||||
if event.is_note_on() {
|
||||
note_on_count += 1;
|
||||
} else if event.is_note_off() {
|
||||
note_off_count += 1;
|
||||
} else {
|
||||
other_count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
println!(" Note On events: {}", note_on_count);
|
||||
println!(" Note Off events: {}", note_off_count);
|
||||
println!(" Other events: {}", other_count);
|
||||
|
||||
// Show events around 28 seconds
|
||||
println!("\nEvents around 28 seconds (27-29s):");
|
||||
let sample_rate = 44100.0;
|
||||
let start_sample = (27.0 * sample_rate) as u64;
|
||||
let end_sample = (29.0 * sample_rate) as u64;
|
||||
|
||||
for (i, event) in clip.events.iter().enumerate() {
|
||||
if event.timestamp >= start_sample && event.timestamp <= end_sample {
|
||||
let time_sec = event.timestamp as f64 / sample_rate;
|
||||
let event_type = if event.is_note_on() {
|
||||
"NoteOn"
|
||||
} else if event.is_note_off() {
|
||||
"NoteOff"
|
||||
} else {
|
||||
"Other"
|
||||
};
|
||||
println!(" [{:4}] {:.3}s: {} ch={} note={} vel={}",
|
||||
i, time_sec, event_type, event.channel(), event.data1, event.data2);
|
||||
}
|
||||
}
|
||||
|
||||
// Check for stuck notes - note ons without corresponding note offs
|
||||
println!("\nChecking for unmatched notes...");
|
||||
let mut active_notes = std::collections::HashMap::new();
|
||||
|
||||
for (i, event) in clip.events.iter().enumerate() {
|
||||
if event.is_note_on() {
|
||||
let key = (event.channel(), event.data1);
|
||||
active_notes.insert(key, i);
|
||||
} else if event.is_note_off() {
|
||||
let key = (event.channel(), event.data1);
|
||||
active_notes.remove(&key);
|
||||
}
|
||||
}
|
||||
|
||||
if !active_notes.is_empty() {
|
||||
println!("Found {} notes that never got note-off events:", active_notes.len());
|
||||
for ((ch, note), event_idx) in active_notes.iter().take(10) {
|
||||
let time_sec = clip.events[*event_idx].timestamp as f64 / sample_rate;
|
||||
println!(" Note {} on channel {} at {:.2}s (event #{})", note, ch, time_sec, event_idx);
|
||||
}
|
||||
} else {
|
||||
println!("All notes have matching note-off events!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
use daw_backend::load_midi_file;
|
||||
|
||||
fn main() {
|
||||
let clip = load_midi_file("darude-sandstorm.mid", 0, 44100).unwrap();
|
||||
|
||||
println!("Clip duration: {:.3}s", clip.duration);
|
||||
println!("Total events: {}", clip.events.len());
|
||||
|
||||
// Show the last 30 events
|
||||
println!("\nLast 30 events:");
|
||||
let sample_rate = 44100.0;
|
||||
let start_idx = clip.events.len().saturating_sub(30);
|
||||
|
||||
for (i, event) in clip.events.iter().enumerate().skip(start_idx) {
|
||||
let time_sec = event.timestamp as f64 / sample_rate;
|
||||
let event_type = if event.is_note_on() {
|
||||
"NoteOn "
|
||||
} else if event.is_note_off() {
|
||||
"NoteOff"
|
||||
} else {
|
||||
"Other "
|
||||
};
|
||||
println!(" [{:4}] {:.3}s: {} ch={} note={:3} vel={:3}",
|
||||
i, time_sec, event_type, event.channel(), event.data1, event.data2);
|
||||
}
|
||||
|
||||
// Find notes that are still active at the end of the clip
|
||||
println!("\nNotes active at end of clip ({:.3}s):", clip.duration);
|
||||
let mut active_notes = std::collections::HashMap::new();
|
||||
|
||||
for event in &clip.events {
|
||||
let time_sec = event.timestamp as f64 / sample_rate;
|
||||
|
||||
if event.is_note_on() {
|
||||
let key = (event.channel(), event.data1);
|
||||
active_notes.insert(key, time_sec);
|
||||
} else if event.is_note_off() {
|
||||
let key = (event.channel(), event.data1);
|
||||
active_notes.remove(&key);
|
||||
}
|
||||
}
|
||||
|
||||
if !active_notes.is_empty() {
|
||||
println!("Found {} notes still active after all events:", active_notes.len());
|
||||
for ((ch, note), start_time) in &active_notes {
|
||||
println!(" Channel {} Note {} started at {:.3}s (no note-off before clip end)",
|
||||
ch, note, start_time);
|
||||
}
|
||||
} else {
|
||||
println!("All notes are turned off by the end!");
|
||||
}
|
||||
|
||||
// Check maximum polyphony
|
||||
println!("\nAnalyzing polyphony...");
|
||||
let mut max_polyphony = 0;
|
||||
let mut current_notes = std::collections::HashSet::new();
|
||||
|
||||
for event in &clip.events {
|
||||
if event.is_note_on() {
|
||||
let key = (event.channel(), event.data1);
|
||||
current_notes.insert(key);
|
||||
max_polyphony = max_polyphony.max(current_notes.len());
|
||||
} else if event.is_note_off() {
|
||||
let key = (event.channel(), event.data1);
|
||||
current_notes.remove(&key);
|
||||
}
|
||||
}
|
||||
|
||||
println!("Maximum simultaneous notes: {}", max_polyphony);
|
||||
println!("Available synth voices: 16");
|
||||
if max_polyphony > 16 {
|
||||
println!("WARNING: Polyphony exceeds available voices! Voice stealing will occur.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user