MIDI-Bassline-Walk

 view release on metacpan or  search on metacpan

lib/MIDI/Bassline/Walk.pm  view on Meta::CPAN


# Find the closest absolute difference to the key, in the list
sub _closest {
    my ($key, $list) = @_;
    # Remove the key from the list
    $list = [ grep { $_ != $key } @$list ];
    return undef unless @$list;
    # Find the absolute difference
    my @diff = map { abs($key - $_) } @$list;
    my $min = min @diff;
    my @closest;
    # Get all the minimum elements of list
    for my $n (0 .. $#diff) {
        next if $diff[$n] != $min;
        push @closest, $list->[$n];
    }
    # Return a random minimum
    return $closest[int rand @closest];
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

MIDI::Bassline::Walk - Generate walking basslines

=head1 VERSION

version 0.0508

=head1 SYNOPSIS

  use MIDI::Bassline::Walk;

  my $bassline = MIDI::Bassline::Walk->new(verbose => 1);
  my $notes = $bassline->generate('F7b5', 8);

  $bassline = MIDI::Bassline::Walk->new(
    verbose   => 1,
    guitar    => 1,
    wrap      => 'C3',
    modal     => 1,
    keycenter => 'Bb',
  );
  $notes = $bassline->generate('F7b5', 8);

  # $score->n('qn', $_) for @$notes; # MIDI

=head1 DESCRIPTION

C<MIDI::Bassline::Walk> generates randomized, walking basslines.

Chords and the key use C<#> and C<b> for accidentals.

The "formula" implemented by this module is basically: "Play any notes
of the chord, modal chord scale, or chord-root scale (and drop any
notes replaced by extended jazz chords)."

The chords recognized by this module, are those known to
L<Music::Chord::Note>.  Please see the source of that module for the
list.

The logic and music theory implemented here, can generate some
possibly sour notes.  This is an approximate composition tool, and not
a drop-in bass player.  Import rendered MIDI into a DAW and alter
notes until they sound suitable.

=head1 ATTRIBUTES

=head2 guitar

  $guitar = $bassline->guitar;

Transpose notes below C<E1> (midinum C<28>) up an octave. This is the
lowest note of a bass guitar in standard tuning.

Default: C<0>

=head2 wrap

  $wrap = $bassline->wrap;

Transpose notes that are above this ISO pitch (e.g. C3), down an
octave.

Default: C<0> (do not wrap)

=head2 modal

  $modal = $bassline->modal;

Maintain the key-center and only choose notes within a mode.

Default: C<0>

=head2 chord_notes

  $chord_notes = $bassline->chord_notes;

Use unique chord notes that may possibly lie outside of the scale
(e.g. C<b5> "flavor") for note choices.

Default: C<1>

=head2 keycenter

  $keycenter = $bassline->keycenter;

The key-center for B<modal> accompaniment.

Default: C<C>

=head2 intervals

  $intervals = $bassline->intervals;



( run in 0.915 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )