Repository navigation
Conversation
|
Thanks for this @Antojoel — MIDI export is a really nice addition, and the Two things before this can go in:
Also two small ones while you're in there:
Thanks again — looking forward to getting this in! |
|
Sure I'll get it sorted. |
Adds a per-stem "Export as MIDI" action using Basic Pitch (Spotify, Apache-2.0) with its ONNX backend — avoids pulling in TensorFlow alongside the existing torch stack. The onnx model itself ships inside the pip package (~230KB); installed on demand into the existing venv the first time it's used (~300MB dependency tree: librosa, onnxruntime, scipy, numba). - python/midi.py: runs transcription, emits the same JSON-line progress protocol as separate.py/roformer.py. basic-pitch prints debug noise straight to stdout via print() (isfinite/shape/dtype per chunk, progress banners) — redirected away so only our JSON lines reach the parent process. - env.ts: ensureMidiEngine() installs "basic-pitch[onnx]" into the venv, gated behind a marker file once installed. Also pins "setuptools<81" alongside it — resampy (a transitive basic-pitch dependency) still does `import pkg_resources`, which setuptools removed in 81, and this project's own bootstrap already upgrades setuptools to latest, so this reliably breaks without the pin. - pipeline.ts: exportStemAsMidi() spawns midi.py and resolves once it reports "done". - UI: a MIDI icon button per stem in StemLane, wired through Player with a busy spinner and an inline error banner on failure. - Verified via pip dry-run that basic-pitch[onnx] resolves against the project's pinned numpy<2 without forcing an upgrade, and pulls no tensorflow. - Installed for real into a venv reproducing this project's exact bootstrap sequence (pip install -U pip wheel setuptools, then the pinned demucs/torch/numpy install) and confirmed torch, demucs and basic_pitch all import together cleanly. - Ran python/midi.py through that venv against real separated stems (piano, guitar, bass) from an actual split — valid .mid output each time, clean single-JSON-line-per-event stdout, no traceback. - Reproduced the pkg_resources failure without the setuptools pin, confirmed the pin fixes it, in that exact venv. - npm run typecheck && npm run build pass; dev app boots with the new IPC handlers registered.
basic-pitch 0.4.0 hard-requires full tensorflow on non-Darwin with python >= 3.11 (our bundled runtime is 3.11) and coremltools on Darwin, and ICASSP_2022_MODEL_PATH prefers TF > CoreML > TFLite > ONNX, so the [onnx] extra still pulled TF and never actually ran on onnx. - install basic-pitch==0.4.0 with --no-deps and list its runtime deps explicitly, with onnxruntime as the only backend - load the onnx model explicitly in midi.py - verify the install imports before writing the .midi-ready marker - correct the size estimate (~150MB) Measured download on py3.11: Windows 445MB -> 126MB, Linux 678MB -> 157MB, macOS ~111MB; no tensorflow on any platform.
95ac0a2 to
87ca649
Compare
|
@danielravina thanks for the review, all addressed in 87ca649:
Tested on macOS: fresh install pulls only onnxruntime (no tensorflow/coremltools), smoke check passes, stems export to valid |
Summary
Adds a per-stem Export as MIDI action (new icon button next to the existing WAV export button in each stem lane), using Basic Pitch (Spotify, Apache-2.0) for audio-to-note transcription.
--no-deps: basic-pitch 0.4.0's own metadata hard-requires fulltensorflowon Windows/Linux when Python ≥3.11 (our bundled runtime is 3.11.10) andcoremltoolson macOS, even with the[onnx]extra. On top of that,ICASSP_2022_MODEL_PATHpicks the first importable backend in the order TF > CoreML > TFLite > ONNX, so ONNX would never actually be used. Sobasic-pitch==0.4.0is installed with--no-deps, its runtime deps are listed explicitly inenv.tswithonnxruntimeas the only backend, andmidi.pyloads the ONNX model explicitly viabuild_icassp_2022_model_path(FilenameSuffix.onnx).python/midi.py— new script following the same JSON-line progress protocol asseparate.py/roformer.py. Note: Basic Pitch prints debug noise straight to stdout via bareprint()calls (per-chunkisfinite/shape/dtype, progress banners) — redirected away in the script so only our JSON lines reach the parent process's stdout parser.env.ts—ensureMidiEngine(): installs the deps, thenbasic-pitch==0.4.0 --no-deps, then runs an import smoke check (onnxruntime,basic_pitch.inference, ONNX model file present) before writing the.midi-readymarker, so a broken install fails at install time rather than on first export.pipeline.ts—exportStemAsMidi()spawns the script and resolves on its"done"event.A real bug caught along the way
While integration-testing against this project's actual venv (not just a scratch one), basic-pitch installed cleanly but failed at import time:
resampy(a transitive dependency) still doesimport pkg_resources, whichsetuptoolsremoved in version 81. This project's own bootstrap (pip install -U pip wheel setuptools) always installs the latest setuptools, so this reliably breaks. Fixed by pinningsetuptools<81alongside the basic-pitch install — verified the pin resolves it, in the same venv where I reproduced the failure.Download size (measured, Python 3.11)
Resolved per target platform with
uv pip compile --python-platform(plainpip download --platformevaluates markers against the host, which is why an earlier macOS dry run showed no TensorFlow), then downloaded the exact wheels:basic-pitch[onnx](before)--no-deps+ explicit deps (now)Test plan
numpy,torch,demucs, andbasic_pitchall import together cleanly.python/midi.pythrough that venv against real separated stems (piano, guitar, bass) from an actual split — valid.midoutput each time (verified note counts and duration withpretty_midi), clean single-JSON-line-per-event stdout, no traceback.midi.pytranscribes a two-tone test file to the expected 2 notes.pkg_resourcesfailure without thesetuptoolspin, then confirmed the pin fixes it, in that exact venv.npm run typecheck&&npm run buildpass; dev app boots cleanly with the new IPC handlers registered.