Music::Duration::Partition::Tutorial::Quickstart
version 0.0820
use MIDI::Util qw(setup_score); use Music::Duration::Partition (); use Music::Scales qw(get_scale_MIDI);
my $score = setup_score();
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.
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.
my @motifs = $mdp->motifs(4);
Return a set of motifs.
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.
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.
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.
$score->write_score('duration-partition.mid');
Write the score out to a MIDI file.
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!
Next is the Music::Duration::Partition::Tutorial::Advanced tutorial.
Gene Boggs <gene@cpan.org>
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.
To install Music::Duration::Partition, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Music::Duration::Partition
CPAN shell
perl -MCPAN -e shell install Music::Duration::Partition
For more information on module installation, please visit the detailed CPAN module installation guide.