Fix MIDI overload resolution for ArrayLike support (#450)#471
Open
gijzelaerr wants to merge 5 commits intospotify:masterfrom
Open
Fix MIDI overload resolution for ArrayLike support (#450)#471gijzelaerr wants to merge 5 commits intospotify:masterfrom
gijzelaerr wants to merge 5 commits intospotify:masterfrom
Conversation
PR spotify#450 changed ExternalPlugin binding lambdas to accept py::object instead of const py::array for the audio input parameter. This broke pybind11's overload resolution for instrument plugins: since py::object matches any Python type, calls with MIDI messages (e.g. plugin(notes, 5.0, sr, reset=False)) would match the audio overload before the MIDI overload, causing ensureArrayLike() to fail on non-array-like MIDI message lists with: TypeError: Pedalboard only supports 32-bit and 64-bit floating point audio for processing. The fix restores const py::array as the parameter type in the ExternalPlugin binding lambdas (for AbstractExternalPlugin, VST3Plugin, and AudioUnitPlugin) so pybind11 correctly rejects non-array inputs and falls through to the MIDI overload. The base Plugin class and standalone process() function retain py::object since they have no MIDI overloads. pybind11 will still auto-convert array-like objects (torch tensors, etc.) to py::array via the buffer protocol and __array__ interface. Based on psobot's work in spotify#450. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ArrayLikeobject instead of justnumpy.ndarray. #450 (psobot's ArrayLike support PR)ArrayLikeobject instead of justnumpy.ndarray. #450 changed ExternalPlugin binding lambdas fromconst py::arraytopy::object, which broke pybind11's overload resolution between the audioprocess/__call__and MIDIrenderMIDIMessagesoverloadsplugin(notes, 5.0, sr, reset=False)), thepy::objectaudio overload matched first, causingensureArrayLike()to fail on non-array MIDI message lists with:TypeError: Pedalboard only supports 32-bit and 64-bit floating point audio for processing.const py::arrayas the parameter type in the ExternalPlugin binding lambdas (AbstractExternalPlugin, VST3Plugin, AudioUnitPlugin) so pybind11 correctly rejects non-array inputs and falls through to the MIDI overloadPluginclass and standaloneprocess()function retainpy::objectsince they have no MIDI overloads to conflict withpy::arrayvia the buffer protocol and__array__interface during argument dispatchBased on @psobot's work in #450.
Test plan
renderMIDIMessagesinstead of the audioprocesspathprocess()function🤖 Generated with Claude Code