💾 Archived View for thrig.me › music › midi › standard.pl captured on 2024-05-12 at 16:12:35.

View Raw

More Information

⬅️ Previous capture (2023-11-04)

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

#!/usr/bin/env perl
# standard - generate a standard drum track
use 5.36.0;
use MIDI;
sub CHAN () { 9 }
sub NOW ()  { 0 }
sub VELO () { 100 }

sub BASS () { 36 }    # try instead 35?
sub CLAP () { 39 }
sub HHAT () { 42 }    # was 44

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

sub note ( $pitch, $velocity = VELO, $dur = 48, $chan = CHAN ) {
    [ note_on => NOW, $chan, $pitch, $velocity ],
      [ note_off => $dur, $chan, $pitch, 0 ];
}

my @Events;

for ( 1 .. 16 ) {
    # this is half a measure, so double the loops
    push @Events, note(BASS), note(HHAT), note(CLAP), note(HHAT);
}

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