Skip to content
DuckDB community extension

midi

Read, analyze, generate, and play MIDI files with SQL. Provides table functions for parsing Standard MIDI Files, scalar functions for note/frequency conversion, and macOS playback via AudioToolbox.

01 / SETUP

Install and load

Run these commands in a Haybarn SQL session. The extension is available from the community repository.

Haybarn 2.0.0 · SQL
INSTALL midi FROM community;
LOAD midi FROM community;

Try it in a temporary SQL session with midi already loaded. Queries run in this tab; examples using files or services need their own setup.

Using upstream DuckDB? Follow the maintainer’s installation instructions.

02 / QUERY

Usage example

Generate a test MIDI file

SQL
-- Load the extension

-- Generate a test MIDI file
SELECT midi_gen('/tmp/test.mid', 'scale');

-- Read all events
SELECT * FROM read_midi('/tmp/test.mid') LIMIT 10;

-- Analyze notes with pairing
SELECT note_name, count(*) as freq, round(avg(duration_sec), 2) as avg_dur
FROM midi_notes('/tmp/test.mid')
GROUP BY note_name ORDER BY freq DESC;

-- Play (macOS only)
SELECT midi_play('/tmp/test.mid');

Provided by nkwork9999. Not yet verified on Haybarn 2.0.0.

Sample data & setup

About this extension

duckdb-midi brings MIDI file support to DuckDB. Parse, analyze, generate, and play Standard MIDI Files entirely from SQL.

Uses craigsapp/midifile for SMF parsing/writing and macOS AudioToolbox for playback.

Project overview from the community descriptor.

Documentation and resources

Project and build details
Repository
nkwork9999/duckdb-midi
License
MIT
Maintainers
nkwork9999
Written in
C++
Build source
bd85cbe38388
Build definition
Community descriptor