Skip to content

Commit

Permalink
Improve soundfont loading by adding preset selection and fallback mec…
Browse files Browse the repository at this point in the history
…hanism
  • Loading branch information
Guy Chronister committed Dec 19, 2024
1 parent a274aae commit e88a3d8
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions neothesia-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,31 @@ impl Recorder {
let synth = if args.len() > 2 {
let settings = Settings::new().unwrap();
let synth = Synth::new(settings).unwrap();
synth.sfload(&args[2], true).unwrap_or_else(|_| {
let sfont_id = synth.sfload(&args[2], true).unwrap_or_else(|_| {
eprintln!("Failed to load soundfont");
std::process::exit(1);
});
synth.program_select(0, 0, 0, 0).unwrap();

// Try to find a piano preset (usually bank 0, preset 0-3)
let presets = [(0, 0), (0, 1), (0, 2), (0, 3)];
let mut success = false;

for (bank, preset) in presets {
if synth.program_select(0, sfont_id, bank, preset).is_ok() {
success = true;
break;
}
}

if !success {
eprintln!("Warning: Could not find piano preset, using first available preset");
// Try to select any available preset
if let Err(e) = synth.program_select(0, sfont_id, 0, 0) {
eprintln!("Error selecting preset: {}", e);
std::process::exit(1);
}
}

Some(Arc::new(synth))
} else {
None
Expand Down

0 comments on commit e88a3d8

Please sign in to comment.