#!/usr/bin/perl -w use strict; use MIDI::Simple; sub play_notes { my @measures = @_; my $tmp_note = $measures[0]; $tmp_note =~ s/;\s*[^:]+:.*$//; my $note_count; ++$note_count while $tmp_note =~ m#\s+#g; my $notes; for my $index (0 .. $#measures) { for my $play (split /;\s*/, $measures[$index]) { my ($inst, $note) = $play =~ m#^([^:]+):\s*(.*)$#; @{$notes->[$index]->{$inst}} = split /\s+/, $note; } } for my $index (0 .. $#{$notes}) { for my $index2 (0 .. $note_count-1) { my @play; for my $inst (keys %{$notes->[$index]}) { my ($channel, $patch) = split '/', $inst; push @play, sub{ my $it = shift; patch_change $channel, $patch; $it->n("c$channel", $notes->[$index]->{$inst}->[$index2]); }; } synch @play; } } } new_score; set_tempo( 60000000 / ($ARGV[0] || 240) ); my @notes = join '; ', ( ( map{ "1/$_: " . join ' ', map { int(rand 128) } 1..50 } int(rand 128), int(rand 128), int(rand 128) ), ( "9/0: " . join ' ', map { $_ % (int(rand 2) ? 3 : 5 ) ? int(rand 53)+35 : 'rest' } 1..50 ) ); play_notes(@notes); print "Playing midi music...\n"; open Q, "| timidity - > /dev/null"; write_score \*Q; close Q;