#!/usr/bin/perl # # makeWhitneyMusic.pl - Jim Bumgardner # # NOTE: Most of the variations on the Whitney Music Box were not # made using MIDI. Some of them, such as the ones based on harmonics # or on microtones, cannot be made using a MIDI instrument because of # the precise tunings involved. Instead, I generated the audio directly # using my software synthesizer "Syd". # # I did use MIDI for some of the later variations which use Piano sounds # (particularly #12 and #13. For #11, which uses a different piano sound, # I used a more elegant Nyquist script. # # This is the script I used for #12. # # - Jim Bumgardner # use Data::Dumper; # for debugging use MIDI; $syntax = < 10); return $d * $ticksPerBeat; } sub kToVelocity($$) { my ($k, $i) = @_; return 64; } sub kToCount($) { my ($k) = @_; return $ptab[$k] if $primes; return ($k+1); } @myEList = (); foreach $k (0..$nbrTines-1) { foreach $n (0..kToCount($k)-1) { push @myEList, { t=>kToTime($k,$n), pitch=>kToPitch($k,$n), vel=>kToVelocity($k,$n)}; push @myEList, { t=>kToTime($k,$n)+kToDuration($k,$n), pitch=>kToPitch($k,$n), vel=>0}; } } # print Dumper(\@myEList); $lTicks = 0; foreach $e (sort {$a->{t} <=> $b->{t}} @myEList) { $offset = int($e->{t} - $lTicks); push @{$mEventList}, ['note_on', $offset, 0, int($e->{pitch}), int($e->{vel})]; $lTicks += $offset; } # print Dumper($mEventList); my $op = MIDI::Opus->new({ 'format' => 1, 'ticks' => $ticksPerBeat, # ticks per quarternote 'tracks' => [ # 2 tracks... # Track #0 ... MIDI::Track->new({ 'type' => 'MTrk', 'events' => [ # 3 events. ['time_signature', 0, 4, 2, 24, 8], ['key_signature', 0, 0, 0], ['set_tempo', 0, int(1000000*60/$tempo)], # microseconds per quarter note ] }), # Track #1 ... MIDI::Track->new({ 'type' => 'MTrk', 'events' => $mEventList }), ] }); $op->write_to_file("$ofile");