💾 Archived View for thrig.me › blog › 2023 › 08 › 11 › midiwheel.pl captured on 2024-06-16 at 13:30:47.

View Raw

More Information

⬅️ Previous capture (2023-09-08)

-=-=-=-=-=-=-

#!/usr/bin/env perl
# midiwheel - when does a wheel change match the next semitone up? this
# may vary by device or software

use 5.36.0;
use MIDI;
my $chan       = 0;
my $dtime      = 24;
my $pitch      = 69;
my $next_pitch = $pitch + 1;
my $ticks      = 96;
my $velo       = 120;
my $wheel_step = 81;

my $file = shift // 'out.midi';

my @events;
sub INSTANT () { 0 }

my $wheel = 0;
while ( $wheel <= 8191 ) {
    push @events,
      [ pitch_wheel_change => INSTANT, $chan, 0 ],
      [ note_on            => INSTANT, $chan, $next_pitch, $velo ],
      [ note_off           => $dtime, $chan, $next_pitch, 0 ],
      [ pitch_wheel_change => INSTANT, $chan, $wheel ],
      [ note_on            => INSTANT, $chan, $pitch, $velo ],
      [ text_event         => INSTANT, "wheel $wheel" ],
      [ note_off           => $dtime, $chan, $pitch, 0 ];
    $wheel += $wheel_step;
}

MIDI::Opus->new(
    {   format => 0,
        ticks  => $ticks,
        tracks => [ MIDI::Track->new( { events => \@events } ) ]
    }
)->write_to_file($file);