Quick-start

Version

version 0.0814

Setup

Import Modules

  use MIDI::Util qw(setup_score);
  use Music::Duration::Partition ();
  use Music::Scales qw(get_scale_MIDI);

Get a Score

  my $score = setup_score();

Construct an object

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

More attributes may be set, but we'll leave that for the advanced tutorial.

Phrases

A single motif

  my $a_motif = $mdp->motif;
  # e.g. ['qn','en','en','hn','qn','qn','dqn','en']

A "motif" is (usually) a short phrase that is used in the development or progression of a piece of music.

For this module, a motif is an ordered set of rhythmic durations.

Multiple motifs

  my @motifs = $mdp->motifs(4);

Return a set of motifs.

Pitches and Voices

Define pitches

  my @pitches = get_scale_MIDI('C', 4, 'major');

Use the scale method to get a set of pitches in the key of C major, in the fourth octave.

Collect voices

  my @voices;

  for my $motif (@motifs) {
      my @notes;

      for my $i (@$motif) {
          push @notes, $pitches[ int rand @pitches ];
      }

      push @voices, \@notes;
  }

Here the voices to be played, are collected and correspond directly to the motifs.

Finish

Add notes to the score

  for my $i (1 .. 4) {
      for my $n (0 .. $#motifs) {
          $mdp->add_to_score($score, $motifs[$n], $voices[$n]);
      }
  }

Loop over the indices of the motifs and voices, adding each to the score, repeated four times.

And Write

  $score->write_score('duration-partition.mid');

Write the score out to a MIDI file.

MIDI Playback

Use the venerable command-line program, timidity++ , which is likely available through your package manager (e.g. apt, homebrew). You can also use the excellent, cross platform program, VLC .

  > timidity duration-partition.mid

Voila!

Advanced

Next is the Music::Duration::Partition::Tutorial::Advanced tutorial.

Copyright and License

This software is copyright (c) 2019-2023 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.