The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Music::Duration::Partition - Partition a musical duration into rhythmic phrases

VERSION

version 0.0820

SYNOPSIS

  use Music::Duration::Partition ();

  my $mdp = Music::Duration::Partition->new(
    size => 8,                  # 2 measures in 4/4 time
    pool => [qw(hn dqn qn en)], # made from these durations
  );

  # the pool may be optionally weighted
  $mdp = Music::Duration::Partition->new(
    size    => 100,
    pool    => [qw(d50  d25)],
    weights => [   0.7, 0.3 ],
  );

  # the pool may also be grouped
  $mdp = Music::Duration::Partition->new(
    pool   => [qw(hn qn tqn)],
    groups => [   1, 1, 3   ],
  );

  my $motif  = $mdp->motif;     # list-ref of pool members
  my @motifs = $mdp->motifs(4); # list of motifs

DESCRIPTION

A Music::Duration::Partition divides a musical duration given by size, into rhythmic phrases of smaller durations drawn from the pool.

For example, to generate a measure in 5/4 time, set size equal to 5 and set the pool to an array-reference of MIDI::Simple durations whose lengths are less than or equal to 5 quarter notes.

To generate a measure in 5/8 time, set size equal to 2.5 (meaning 5 eighth notes).

For MIDI usage, please see Music::Duration::Partition::Tutorial::Quickstart and Music::Duration::Partition::Tutorial::Advanced.

ATTRIBUTES

size

  $size = $mdp->size;

The value, in quarter notes, of the duration to partition.

Default: 4

pool

  $pool = $mdp->pool;

The list of possible note durations to use in constructing a rhythmic motif.

Default: [ keys %MIDI::Simple::Length ] (wn, hn, qn, ...)

This can be either a list of duration names, or duration values, specified with a preceding d. A mixture of both is not well defined. YMMV

pool_select

  $code = $mdp->pool_select->();
  $mdp->pool_select( sub { ... } );

A code reference used to select an item from the given duration pool.

Default: Random item from pool

weights

  $weights = $mdp->weights;

The frequencies of pool item selection.

The number of weights must equal the number of pool entries. The weights do not have to sum to 1 and can be any relative numbers.

Default: Equal probability for each pool entry

groups

  $groups = $mdp->groups;

The number of times that a pool item is selected in sequence.

The number of groups must equal the number of pool entries.

Default: 0 for each pool entry

* 0 and 1 mean the same thing for grouping. So if needed, an entry should have a value greater than one.

remainder

  $remainder = $mdp->remainder;

Append any remaining duration ticks to the end of the motif.

Default: 1 "Yes. Make it so."

verbose

  $verbose = $mdp->verbose;

Show the progress of the motif method.

Default: 0

METHODS

new

  $mdp = Music::Duration::Partition->new(%arguments);

Create a new Music::Duration::Partition object.

motif

  $motif = $mdp->motif;

Generate a rhythmic phrase of the given size.

This method returns a possibly different rhythmic motif each time it is called.

The default pool_select used constructs this by selecting a pool duration at random, that fits into the size remaining after each application, in a loop until the size is met.

motifs

  @motifs = $mdp->motifs;
  @motifs = $mdp->motifs($n);

Return n motifs.

Default: n=1

add_to_score

  $mdp->add_to_score($score, $motif, $pitches);

Add the motif and pitches to the score.

SEE ALSO

The eg/* and t/01-methods.t programs in this distribution.

https://ology.github.io/music-duration-partition-tutorial/

List::Util

Math::Random::Discrete

MIDI::Simple

Moo

AUTHOR

Gene Boggs <gene@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2019-2024 by Gene Boggs.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.