perry-rylance/midi-php

Read, build and write MIDI files, tracks and events in PHP

1.0.0 2025-07-21 07:57 UTC

This package is auto-updated.

Last update: 2025-07-21 08:51:01 UTC


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 your ReadStream

Creating MIDI data

  • Instantiate a new File
  • Instantiate a new Track and push it to your files tracks
  • Instantiate any subclasses of Event you need, eg NoteOnEvent
  • 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 your File passing in your WriteStream
  • Use toBinary on your WriteStream 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 (replacing php84 with whichever version you wish to target)

Credits