perry-rylance / midi-php
Read, build and write MIDI files, tracks and events in PHP
1.0.1
2025-08-25 10:24 UTC
Requires
- php: >=8.2.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
Development
-dev
containers with XDebug are provided and will stay open once started.
Testing
All tests can be run with cross-version-tests.sh
.
Tests can be run on specific versions by starting the respective containers.
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