perry-rylance / midi-php
Read, build and write MIDI files, tracks and events in PHP
1.0.0
2025-07-21 07:57 UTC
Requires
- php: >=8.0.0
- aeviiq/collection: ^4.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.84
- illuminate/support: ^12.20
- pestphp/pest: ^3.8
- phpstan/phpstan: ^2.1
README
A package for reading and writing MIDI files and streams in PHP.
Usage
Reading MIDI data
- Get your data into a binary string
- Instantiate a
new ReadStream
with your binary data - Instantiate a
new File
- Call
readBytes
passing in yourReadStream
Creating MIDI data
- Instantiate a
new File
- Instantiate a
new Track
and push it to your filestracks
- Instantiate any subclasses of
Event
you need, egNoteOnEvent
- Push your events to the tracks
events
- Don't forget
EndOfTrackEvent
!
Writing MIDI data
- You'll need a
File
either read in or created from scratch as described above - Instantiate a
new WriteStream
- Call
writeBytes
on yourFile
passing in yourWriteStream
- Use
toBinary
on yourWriteStream
to get the binary data
Testing
TODO: Docs and script for run tests on all versions of PHP
docker compose up
docker exec -t php84 composer test
(replacingphp84
with whichever version you wish to target)
Credits
- With thanks to Recording Blogs, Teragon Audio and Mido for insight into the MIDI spec.
- With thanks to jazz-soft for the test files.
- With thanks to Jeff Boudier for MIDIopsy