Skip to content

MIDI import: Lemon SoundFont Player as a channel type - #471

Open
ItsAlphaNeon wants to merge 1 commit into
mainfrom
midi-import-soundfont
Open

ItsAlphaNeon wants to merge 1 commit into
mainfrom
midi-import-soundfont

Conversation

@ItsAlphaNeon

Copy link
Copy Markdown
Owner

Closes #440.

A MIDI file couldn't be heard on a SoundFont without replacing every imported channel's instrument by hand. The Import MIDI data form's Channel type now lists Lemon SoundFont Player: Accept asks for a .sf2 file, and every new channel plays it, each at the preset its track asks for.

How each channel's preset is chosen

  • The program and bank (controller 0) its MIDI channel holds at the channel's first note: the last change at or before it, from any track (the note's own track wins a tie), else the first one after it, else 0.
  • MIDI channel 10 takes the drum bank, 128.
  • When the font lacks that preset: for drums, kit 0 or the font's first kit; otherwise the program in bank 0, or in the lowest melodic bank that has it; otherwise the font's first preset.
  • One preset per channel: later program changes aren't followed, as with the other channel types.

The font dialog opens in the last font's folder with its name filled in. Cancel imports nothing. A file that isn't a usable font stops the import with a warning, before anything changes. With the form not shown, the session's last font is used.

Under the hood

  • lemon-soundfont: sf2::preset_ids reads a font's preset list from its headers, seeking past the sample data, so a large font isn't read twice. sf2::general_midi_preset does the fallback, and State::set_program names a preset without the font open.
  • add_channel takes an optional state: a built-in plugin's saved state, as the project file keeps it. The channel is then hosted from that state by the plugin's own sync instead of as a fresh instance, and undo/redo keep it. A sampler, layer or other non-built-in channel refuses it. docs/control-plane.md documents it.
  • docs/status.md describes the new entry.

Tests

  • Program and bank detection: the drum channel, ties, a change after the first note, bank select, per track and per MIDI channel.
  • The whole import through the form and the font dialog: cancel, not-a-font, the states written, the players hosted from them, undo/redo.
  • The control-plane state field and its refusals.
  • On 9 real .sf2 files, preset_ids agrees with the full parse (an ignored test, OS_SF2=...).
  • cargo test -p os-app -p os-session -p lemon-soundfont passes, and so does the no-default-features check. Not tried by hand in the running app.

🤖 Generated with Claude Code

The Import MIDI data form's Channel type lists Lemon SoundFont Player
(issue #440). Accept asks for a SoundFont, and every new channel plays
it at its track's General MIDI program and bank, MIDI channel 10 at the
drum kit, or the nearest preset the font has. The next import offers
the same font.

- lemon-soundfont: preset_ids reads a font's presets from its headers,
  skipping the sample data; general_midi_preset picks the nearest one.
- add_channel takes a built-in plugin's saved state; the channel is
  then hosted from it instead of as a new instance.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[PROPOSAL] Add SoundFont Player (General MIDI) to Channel type in MIDI import

1 participant