Algorithm-Gutter

 view release on metacpan or  search on metacpan

eg/rainmidi3000.pl  view on Meta::CPAN

my $ch       = 0;                     # MIDI channel (9 for drums)
my $tick     = 32;                    # default duration (dtime)

# So you can figure out how things were wired up if you actually get
# good results from this thing, unless you are on OpenBSD, or this code
# is somehow incorrect.
my $seed = shift;
if ( defined $seed ) {
    srand $seed;
} else {
    say "SEED ", srand;
}

# See MIDI::Event and the MIDI specification.
my @events = (
    [ text_event => 0, 'RAIN-MIDI 3000 ][' ],
    #[ patch_change => 0, $ch, 11 ],
    [ set_tempo => 0, 450_000 ],
);

my $gobj  = Algorithm::Gutter->new( rain => \&water );

eg/rainmidi3000.pl  view on Meta::CPAN

        if ( defined $cell->update ) {
            $s .= join ' ', $cell->enabled ? '+' : '-', sprintf '% 3d',
              $cell->threshold;
            my $c = $cell->context;
            if ( $cell->update == \&pitch ) {
                $s .= ' MIDI -> ' . $cell->context->{pitch};
            } else {
                $s .= ' TOGGLE #' . $cell->context->{toggles}->id;
            }
        }
        say $s;
    }
}

# Generate MIDI events for one or more pitches happening at the
# same time.
sub sound {
    my ( $offset, @pitch ) = @_;
    # TWEAK limit how notes can sound at the same time. Note choice will
    # depend on how the pitches get shuffled into the gutter.
    my $at_most = 4;



( run in 1.477 second using v1.01-cache-2.11-cpan-483215c6ad5 )