#!/usr/local/bin/perl

# The very low-level way to build MIDI data:

use MIDI;
$chimes_track = MIDI::Track->new({ 'events' => [
 ['text_event',0, 'www.ely.anglican.org/parishes/camgsm/chimes.html'],
 ['text_event',0, 'Lord through this hour/ be Thou our guide'],
 ['text_event',0, 'so, by Thy power/ no foot shall slide'],
 ['text_event',0, '(coded at ' . scalar(localtime) . ' )'],
 ['patch_change', 0, 1, 16], # Patch 16 = Drawbar Organ
 map( (['note_on',0,1,$_->[0],96], ['note_off',$_->[1],1,$_->[0],0]),
      [25,96],[29,96],[27,96],[20,192],[25,96],[27,96],[29,96],[25,192],
      [29,96],[25,96],[27,96],[20,192],[20,96],[27,96],[29,96],[25,192],
    )# [Note,Duration] ==> ['note_on',0,1, N ,96], ['note_off', D ,1, N ,0]
] });
$chimes = MIDI::Opus->new(
 { 'format' => 0, 'ticks' => 96, 'tracks' => [ $chimes_track ] } );
$chimes->write_to_file('chimes.mid');
