v0.34.0: Calculate BPM from the audio, on the right-click menu

Spectral-flux onsets + autocorrelation in numpy, decoded by the ffmpeg CLI;
no new dependency. Runs on a worker with the status-bar progress bar, for
one track or many, and the batch is one Ctrl+Z.
This commit is contained in:
2026-10-02 14:55:35 -07:00
parent 481edd65ce
commit 10ced778af
7 changed files with 504 additions and 4 deletions
+23
View File
@@ -627,6 +627,29 @@ class LibraryManager(QObject):
redo=lambda: [self._revert_track_fields(tid, new)
for tid, new, _old in changes]))
def set_tracks_bpm(self, values: dict[int, int]):
"""Calculate BPM's results: a different bpm per track, tag written to
each file, recorded as ONE undoable command."""
changes = [] # (track_id, new_fields, old_fields)
with timed("set_tracks_bpm (%d tracks)", len(values)):
for track_id, bpm in values.items():
track = self.library.tracks.get(track_id)
if not track or track.bpm == bpm:
continue
changed = {"bpm": bpm}
if not self._write_track_tags(track, changed):
continue
changes.append((track_id, changed, {"bpm": track.bpm}))
self._apply_track_fields(track_id, changed)
if not changes:
return
self.undo_stack.push(Command(
"Calculate BPM",
undo=lambda: [self._revert_track_fields(tid, old)
for tid, _new, old in changes],
redo=lambda: [self._revert_track_fields(tid, new)
for tid, new, _old in changes]))
def _write_track_tags(self, track, field_map: dict) -> bool:
# Library-only fields (rating, size, start/stop times) have no tag
# representation; don't rewrite the audio file for them.