Quick Start

The PHP MIDI Library requires PHP 5.3.0 or later. If you have no patience and a UNIX shell, take a look at the quick and dirty section. Otherwise, read the entire page (it won't take long).

Quick and Dirty

  1. Download or clone
  2. Create script: vi midilibtest.php
  3. Paste and exchange placeholder MIDI file with location of real MIDI file:
    <?php
    
        require_once 'Midi/bootstrap.php';
    
        use \Midi\Parsing\FileParser;
        use \Midi\Reporting\TextFormatter;
        use \Midi\Reporting\Printer;
    
        $parser = new FileParser();
        $parser->load('/path/to/midi/file.mid');
    
        $printer = new Printer(new TextFormatter(), $parser);
        $printer->printAll();
    
    ?>
    
  4. Save
  5. Run: php midilibtest.php
  6. ???
  7. Profit

Installation

  1. Download the default package
  2. Extract it somewhere
  3. To use the library in your code, all you need to do is include the bootstrap.php file, which is located at Midi/bootstrap.php.

Usage

When you include the bootstrapper, it autoloads all the classes you'll need to use the library. Below is a code snippet that will parse a file named "test.mid" and use the TextFormatter to format the results. This will print the parse results out to stdout.

<?php

    require_once 'Midi/bootstrap.php';

    use \Midi\Parsing\FileParser;
    use \Midi\Reporting\TextFormatter;
    use \Midi\Reporting\Printer;

    $parser = new FileParser();
    $parser->load('test.mid');

    $printer = new Printer(new TextFormatter(), $parser);
    $printer->printAll();

?>

To get prettier results, like you can see in the demo, use the HtmlFormatter along with the MultiFilePrinter. Note that using this combination of formatter and printer uses AJAX to do pagination, which means you need a webserver to view the results. Use the FilePrinter instead if a webserver is not available. This will make one giant HTML file rather than many, as the MultiFilePrinter does.

When you run this code snippet, it will create a directory called "test" and place the resultant HTML files in there.

<?php

    require_once 'Midi/bootstrap.php';

    use \Midi\Parsing\FileParser;
    use \Midi\Reporting\HtmlFormatter;
    use \Midi\Reporting\MultiFilePrinter;

    $file = 'test.mid';

    $parser = new FileParser();
    $parser->load($file);

    $formatter = new HtmlFormatter();
    $formatter->setMultiFile(true);

    $printer = new MultiFilePrinter($formatter, $parser, dirname(__FILE__) . '/test');
    $printer->printAll();

?>