💾 Archived View for thrig.me › blog › 2023 › 08 › 11 › whee.pl captured on 2023-09-08 at 17:07:39.
-=-=-=-=-=-=-
#!/usr/bin/env perl use 5.36.0; use MIDI; my $chan = 0; my $ticks = 96; my $file = shift // 'out.midi'; sub INSTANT () { 0 } # 500_000 is 120 - 400_000 is 150 and 460 seems about right? my @events = [ set_tempo => INSTANT, 460_000 ]; sub velo { 96 + int( rand 4 + rand 4 + rand 4 ) } sub whee ( $p1, $p2, $step = 2048, $dtime = 24 ) { my $wheel = 0; while ( $wheel < 8191 ) { push @events, [ pitch_wheel_change => INSTANT, $chan, 0 ], [ note_on => INSTANT, $chan, $p2, velo ], [ note_off => $dtime, $chan, $p2, 0 ], [ pitch_wheel_change => INSTANT, $chan, $wheel ], [ note_on => INSTANT, $chan, $p1, velo ], [ note_off => $dtime, $chan, $p1, 0 ]; $wheel += $step; } $wheel = 8191; while ( $wheel > 0 ) { push @events, [ pitch_wheel_change => INSTANT, $chan, $wheel ], [ note_on => INSTANT, $chan, $p2, velo ], [ note_off => $dtime, $chan, $p2, 0 ], [ pitch_wheel_change => INSTANT, $chan, 0 ], [ note_on => INSTANT, $chan, $p1, velo ], [ note_off => $dtime, $chan, $p1, 0 ]; $wheel -= $step; } } whee( 69, 69 ); whee( 69, 69 ); whee( 69, 72 ); whee( 69, 74 ); whee( 69, 76 ); whee( 69, 76 ); whee( 69, 81 ); whee( 69, 81 ); whee( 76, 76 ); whee( 76, 79 ); whee( 76, 76 ); whee( 76, 79 ); whee( 69, 81 ); whee( 69, 81 ); whee( 76, 77 ); whee( 76, 77 ); whee( 74, 76 ); whee( 74, 76 ); whee( 76, 77 ); whee( 76, 77 ); whee( 69, 76 ); whee( 69, 81 ); whee( 69, 76 ); whee( 69, 81 ); whee( 69, 76 ); whee( 69, 74 ); whee( 68, 76 ); whee( 67, 71 ); whee( 66, 69 ); whee( 65, 72 ); whee( 64, 67 ); whee( 64, 69 ); MIDI::Opus->new( { format => 0, ticks => $ticks, tracks => [ MIDI::Track->new( { events => \@events } ) ] } )->write_to_file($file);