Music::RhythmSet::Util - pattern generation and classification functions
Various functions related to the generation and classification of patterns of beats, and so forth. A pattern of beats is assumed to be an array reference of zeros and ones, e.g. for 4/4 time in 16th notes
[ 1,0,0,0, 1,0,0,0, 1,0,0,0, 1,0,0,0 ]
Nothing is exported by default; the functions must be used fully qualified or by importing them on the use line.
use
Converts a pattern such as [qw/1 0 1 0/] to a string such as x.x.. Opposite of pattern_from.
[qw/1 0 1 0/]
x.x.
What percentage of onsets between two patterns are identical? Makes assumptions about the patterns which may not be true; ideally feed it patterns of the same length.
compare_onsets([1,0,0,0],[1,0,1,0])
Returns a list consisting of the number of measures and the total number of beats in those measures given a replay-log.
Generates trials number of patterns via rand_onsets and selects for the "best" pattern by the lowest combined score of score_stddev and score_fourfour. This routine will need to be profiled and tuned for the need at hand; see the eg/variance script under this module's distribution for one way to study how the function behaves.
eg/variance
Flattens the given replay-log into a single array reference of beats.
Converts a pattern into "onset-coordinate vector" notation. This format is suitable to be fed to Music::AtonalUtil.
Returns a count of how many onsets there are in the pattern.
Since version 0.02.
Converts a beat string such as x.x. into an array reference such as [qw/1 0 1 0/]. Opposite of beatstring.
It may be more sensible to use from_string in Music::RhythmSet::Voice or Music::RhythmSet especially if there are multiple patterns and TTL being parsed.
Randomly turns on onsets in total beats and returns that as an array reference of zeros and ones. Will likely need to be filtered somehow to select for more usable results.
Fiddled with by hand so that a lower score is something closer to one opinion of 4/4 time in 16th notes. A (probably poor) attempt to select for patterns such as
[ 1,0,0,0, 0,0,1,0, 1,0,0,0, 0,0,1,0 ]
and not the identical but rotated off-beat
[ 0,0,0,0, 0,1,0,1, 0,0,0,0, 0,1,0,1 ]
Assumes the pattern is 16 beats in length.
Standard deviation of the distances to the following onset; lower scores indicate higher regularity (non-clumping) of the onsets. However, you probably want a rhythm somewhere between the zero score
and
[ 1,1,1,1, 0,0,0,0, 0,0,0,0, 0,0,0,0 ]
(or the various rotations of the above) as the first is probably too regular and the second probably too irregular.
This method should work on patterns of any length (CPU and memory and user patience permitting).
Increases the size of the pattern to new-length which ideally should be a positive integer multiple of the current pattern length, possibly the "least common multiple" with some other pattern length:
$ perl -MMath::BigInt -E 'say Math::BigInt->new(8)->blcm(6,7)' 168
At some point it may be more useful to convert the onsets into "close enough" slots of at most 32 or 64 beats depending on the resolution desired, or to simply use measures of different lengths. I have not experimented with measures of different lengths over multiple voices so do not know what the problems will be.
Returns a new pattern.
A small wrapper around MIDI::Opus that writes a MIDI track (or tracks) to a file. The optional params may include format and ticks (see the MIDI specification).
As write_midi except that the individual track(s) are written to individual files. The template should contain a sprintf format that among other things contains a %d for the track number. The i parameter can be used to set the starting track number, 1 by default.
sprintf
%d
1
None known.
Music::AtonalUtil has various relevant routines, especially for beat patterns of length 12.
"The Geometry of Musical Rhythm" by Godfried T. Toussaint.
Balanced parentheses (there are code problems for this) are somewhat musical and may be converted to rhythm via
tr/()/10/; # and maybe also s/(?<=1)(1+)/"0" x length $1/eg;
Copyright 2021 Jeremy Mates
This program is distributed under the (Revised) BSD License: https://opensource.org/licenses/BSD-3-Clause
To install Music::RhythmSet, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Music::RhythmSet
CPAN shell
perl -MCPAN -e shell install Music::RhythmSet
For more information on module installation, please visit the detailed CPAN module installation guide.