Skip to content

Instantly share code, notes, and snippets.

@ramondelafuente
Created August 28, 2014 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramondelafuente/636579ca69eed2096711 to your computer and use it in GitHub Desktop.
Save ramondelafuente/636579ca69eed2096711 to your computer and use it in GitHub Desktop.
Route::get('/experiment', function() {
//create a new file parser
$parser = new Tmont\Midi\Parsing\FileParser();
$midiFile = __DIR__ . '/../lib/kotta/assets/examples/simple.mid';
// $midiFile = __DIR__ . '/../vendor/tmont/midiparser/sample/And_We_Die_Young.mid';
//replace this path with the path to an actual MIDI file
$parser->load($midiFile);
$formatter = new Kotta\Formatter\NoteFormatter(0);
$printer = new Tmont\Midi\Reporting\Printer($formatter, $parser);
$printer->printAll();
$stream = $formatter->getStream();
$chunker = new \Kotta\Chunker();
$chunks = $chunker->chunk($stream);
// $result = '';
// foreach ($chunks[0]->getBars() as $bar) {
// foreach ($bar->getSymbols() as $symbol) {
// $result .= $symbol->getValue() . '<br>';
// }
// }
//
// return $result;
$chunk = $chunks[0];
$converter = new \Kotta\Symbol\Converter( base_path('lib/kotta/assets/symbols') );
$symbolPainter = new \Kotta\Painter\SymbolPainter($converter);
$chunkPainter = new \Kotta\Painter\ChunkPainter($chunk, $symbolPainter, $converter);
$png = $chunkPainter->paint();
header('Content-type: image/png');
echo (string) imagepng($png);
exit;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment