feat(drums): capture velocities alongside times in unmapped-percussion reporting (#808)

* feat(drums): capture velocities alongside times in unmapped-percussion reporting

Both drum converters opt-in out_unmapped capture (convert_drum_track_from_midi,
convert_drum_track_to_drumtab) gain an index-aligned `velocities` list next to
`times`, carrying each dropped note real dynamics — MIDI velocity verbatim; GP
velocity with the same 1-127 gate as mapped hits, falling back to the 100
import default. A hand-mapping UI (the editor unmapped-notes dialog) can then
restore mapped notes at their source dynamics instead of flattening to v:100
(editor-side consumer: feedBack-plugin-editor#111).

The GP path chronological sort now reorders times and velocities in LOCKSTEP
so multi-voice measures cannot silently reassign dynamics. Additive: callers
that ignore the new key are unaffected.

Tests: extended tests/test_midi_import_drums.py + tests/test_gp2rs_drums.py
(alignment, lockstep sort, out-of-range fallback) — 26 passing.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JEoFeTPSnz4NpwwCG52hnu

* docs(gp2rs): clarify velocity-default comment, mark dead-path fallback

- The mapped-GP velocity comment conflated GP's authoring default (95,
  Velocities.default) with the drumtab render default (100,
  DEFAULT_VELOCITY in lib/drums.py) used when `v` is omitted. Clarify
  both defaults and that only the latter applies to omitted hits.
- Mark the `else: times.sort()` fallback in the unmapped-percussion
  time/velocity sort as belt-and-suspenders — times and velocities are
  always appended together under the same len<100 guard, so lengths
  can't actually diverge.

No behavior change; comment-only maintainability nits from PR review.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: ChrisBeWithYou <chris@rifflarr.local>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: byrongamatos <xasiklas@gmail.com>
This commit is contained in:
ChrisBeWithYou
2026-07-07 23:58:49 +02:00
committed by GitHub
co-authored by Claude Opus 4.8 ChrisBeWithYou byrongamatos
parent fadaa154e9
commit 5cb4ea0623
5 changed files with 95 additions and 23 deletions
+43 -5
View File
@@ -223,15 +223,15 @@ def test_unmapped_percussion_silently_skipped(monkeypatch):
def test_unmapped_percussion_reported_via_out_unmapped(monkeypatch):
"""Opting in via out_unmapped records the dropped MIDI notes (count +
times) so a caller can surface a warning / mapping UI."""
times + velocities) so a caller can surface a warning / mapping UI."""
_setup(monkeypatch)
track = _fake_track(
string_midis=[56, 36, 54],
beats=[
(0.0, [_fake_note(string_idx=1)]), # cowbell — drop
(1.0, [_fake_note(string_idx=2)]), # kick — keep
(1.5, [_fake_note(string_idx=3)]), # tambourine — drop
(2.0, [_fake_note(string_idx=1)]), # cowbell again — drop
(0.0, [_fake_note(string_idx=1, velocity=88)]), # cowbell — drop
(1.0, [_fake_note(string_idx=2)]), # kick — keep
(1.5, [_fake_note(string_idx=3, velocity=25)]), # tambourine — drop
(2.0, [_fake_note(string_idx=1, velocity=44)]), # cowbell again — drop
],
)
song = SimpleNamespace(tracks=[track])
@@ -247,6 +247,44 @@ def test_unmapped_percussion_reported_via_out_unmapped(monkeypatch):
# Times are captured (rounded to 3 dp).
assert unmapped[56]["times"] == [0.0, 2.0]
assert unmapped[54]["times"] == [1.5]
# Velocities ride index-aligned with times — the mapping UI can carry
# the source dynamics through instead of flattening to a default.
assert unmapped[56]["velocities"] == [88, 44]
assert unmapped[54]["velocities"] == [25]
def test_unmapped_velocities_sort_in_lockstep_with_times(monkeypatch):
"""Multi-voice measures can capture times out of order; the final sort
must reorder velocities WITH their times, not leave them behind."""
_setup(monkeypatch)
track = _fake_track(
string_midis=[56],
beats=[
# Deliberately reversed chronology within the measure.
(2.0, [_fake_note(string_idx=1, velocity=44)]),
(0.0, [_fake_note(string_idx=1, velocity=88)]),
],
)
song = SimpleNamespace(tracks=[track])
unmapped: dict[int, dict] = {}
gp2rs.convert_drum_track_to_drumtab(song, 0, out_unmapped=unmapped)
assert unmapped[56]["times"] == [0.0, 2.0]
assert unmapped[56]["velocities"] == [88, 44], \
"velocity must follow its time through the sort"
def test_unmapped_out_of_range_velocity_falls_back_to_default(monkeypatch):
"""A corrupt/zero GP velocity records the 100 import default rather
than poisoning the aligned list."""
_setup(monkeypatch)
track = _fake_track(
string_midis=[56],
beats=[(0.0, [_fake_note(string_idx=1, velocity=0)])],
)
song = SimpleNamespace(tracks=[track])
unmapped: dict[int, dict] = {}
gp2rs.convert_drum_track_to_drumtab(song, 0, out_unmapped=unmapped)
assert unmapped[56]["velocities"] == [100]
def test_zero_velocity_omitted_from_wire(monkeypatch):
+8 -4
View File
@@ -185,18 +185,18 @@ def test_unmapped_drum_note_skipped(tmp_path):
def test_unmapped_drum_note_reported_via_out_unmapped(tmp_path):
"""Opting in via out_unmapped records the dropped MIDI notes (count +
times) so a caller can surface a warning / mapping UI."""
times + velocities) so a caller can surface a warning / mapping UI."""
mid = mido.MidiFile(type=1, ticks_per_beat=480)
track = mido.MidiTrack()
mid.tracks.append(track)
track.append(mido.MetaMessage("set_tempo", tempo=500000, time=0))
track.append(mido.Message("note_on", channel=9, note=56, velocity=100, time=0)) # cowbell — drop
track.append(mido.Message("note_on", channel=9, note=56, velocity=88, time=0)) # cowbell — drop
track.append(mido.Message("note_off", channel=9, note=56, velocity=0, time=240))
track.append(mido.Message("note_on", channel=9, note=36, velocity=100, time=0)) # kick — keep
track.append(mido.Message("note_off", channel=9, note=36, velocity=0, time=240))
track.append(mido.Message("note_on", channel=9, note=54, velocity=100, time=0)) # tambourine — drop
track.append(mido.Message("note_on", channel=9, note=54, velocity=25, time=0)) # tambourine — drop
track.append(mido.Message("note_off", channel=9, note=54, velocity=0, time=240))
track.append(mido.Message("note_on", channel=9, note=56, velocity=100, time=0)) # cowbell again — drop
track.append(mido.Message("note_on", channel=9, note=56, velocity=44, time=0)) # cowbell again — drop
track.append(mido.Message("note_off", channel=9, note=56, velocity=0, time=240))
unmapped: dict[int, dict] = {}
@@ -209,6 +209,10 @@ def test_unmapped_drum_note_reported_via_out_unmapped(tmp_path):
# Each unmapped MIDI carries the times at which it fired (rounded 3 dp).
assert all(isinstance(t, float) for t in unmapped[56]["times"])
assert len(unmapped[56]["times"]) == 2
# Velocities ride index-aligned with times — the mapping UI can carry
# the source dynamics through instead of flattening to a default.
assert unmapped[56]["velocities"] == [88, 44]
assert unmapped[54]["velocities"] == [25]
def test_non_channel9_events_ignored(tmp_path):