feat(midi): import Standard MIDI Files with transactional undo (phase 104)

This commit is contained in:
Johannes Findeisen 2026-11-06 02:28:25 +01:00
commit f37ad8987a
9 changed files with 234 additions and 5 deletions

View file

@ -60,3 +60,25 @@ are cropped and notes outside the trim are omitted. Trailing silence remains.
Export does not edit the project or undo history. Audio clips reject. Only note
messages are exported: instruments, opaque plugin data, controller maps,
automation and audio are excluded. Export is unavailable during recording.
## Import MIDI files
File → Import MIDI (also in the sequencer Create menu) adds a clip at the cursor
on the selected non-bus track, or creates a track when none is selected. Import
is one undoable prepared edit; malformed files, capacity errors and failed
backend preparation retain the old project and IDs.
The reader supports Standard MIDI File types 0 and 1 with PPQN timing, including
running status and velocity-zero note-offs. File tracks merge into one clip;
channels and velocities remain. Timing rounds to 960 ticks per quarter note,
with positive sub-tick notes given one tick. Trailing silence remains. The project
tempo is retained: tempo maps, time signatures, CC/sustain, program changes,
pitch bend, SysEx and other metadata are not imported. This is a notes workflow,
not full-song or instrument reconstruction.
Limits are 1 MiB per file, 64 file tracks, 65,536 parsed events and 4,096 notes
within the project's total note capacity. SMPTE timing and type 2 reject explicitly.
Unterminated notes, zero source duration and malformed events reject rather than
silently dropping notes. Unmatched note-offs are harmless and ignored. Overlapping
same-pitch notes pair FIFO within each file track/channel. Project save/reload
uses the existing format; no format migration or extra dependency is required.

View file

@ -2286,12 +2286,12 @@ Implemented: a C99 atomic type-0/960-PPQN SMF exporter and GUI save chooser expo
Import type 0/1 PPQN MIDI notes onto the selected track or a new track, with safe parsing, explicit limits, tempo policy and one undoable prepared adoption.
### Tasks and acceptance criteria
- [ ] Implement and document the workflow with bounded validation and safe ownership.
- [ ] Pass meaningful core and GUI checks, including errors and persistence or undo.
- [ ] Commit this phase separately after validation.
- [x] Implement and document the workflow with bounded validation and safe ownership.
- [x] Pass meaningful core and GUI checks, including errors and persistence or undo.
- [x] Commit this phase separately after validation.
### Implementation status
Planned.
Implemented: bounded C99 type 0/1 PPQN notes import with running status, channel/velocity preservation, tick conversion, track merging and retained project tempo. File/Import MIDI and Create/Import MIDI add at the cursor on the current or a new track through one prepared undo edit. Export/import roundtrips, independent type-1 fixture, every truncation prefix, malformed/unsupported/bus/overflow rejection, allocation-failure rollback and GUI import/undo/redo/new-track/failed-adoption checks passed, together with the full core/reliability suite. Notes-only limits are explicit in MIDI_WORKFLOWS.md.
---