NAME

Music::VoicePhrase - Construct measured phrases of notes

VERSION

version 0.0127

SYNOPSIS

use Music::VoicePhrase ();

my $mvp = Music::VoicePhrase->new;

# or also with external processing metadata:
my %metadata = (key => 'value!', color => 'hot-pink');
$mvp = Music::VoicePhrase->new(metadata => \%metadata);
$mvp->metadata(\%metadata);
my $value = $mvp->metadata->{key}; # ghetto access - ugh

my $motifs = $mvp->motifs; # using defaults
my $voices = $mvp->voices;

# get fresh:
$motifs = $mvp->build_motifs;
$voices = $mvp->build_voices;

DESCRIPTION

A Music::VoicePhrase constructs a measured phrase of voices with both pitch and rhythmic values.

This module is also equipped with handy attributes to make real-time processing work. See the linked phrase generator app in the "SEE ALSO" section.

ATTRIBUTES

base

$base = $mvp->base;

Base scale note.

Default: C

index

$index = $mvp->index;
$mvp->index($n);

A handy index!

Default: 0

scale

$scale = $mvp->scale;

Scale name known to the Music::Scales module.

Default: major

octave

$octave = $mvp->octave;

Octave integer from 0 to 9.

Default: 0

pitches

$pitches = $mvp->pitches;

Pitches that define the Music::VoiceGen selection. (This is just an array-ref of midi-numbers.)

Default: 2 consecutive octaves given the base note, scale name, and starting octave.

intervals

$intervals = $mvp->intervals;

Intervals that define the Music::VoiceGen selection.

Default: [-3, -2, -1, 1, 2, 3]

size

$size = $mvp->size;

The number of beats in a phrase. This is usually an integer like 4 beats for a measure. But it can also be a float, as the Music::Duration::Partition module takes fractional numbers to represent odd meters.

For instance size 2.5 represents 5/8 time. Because a size of <5> represents 5/4 time.

Default: 4

pool

$pool = $mvp->pool;

The pool of note durations, given in Perl MIDI abbreviated notation, that define a Music::Duration::Partition phrase.

Default: ['dhn', 'hn', 'qn']

weights

$weights = $mvp->weights;

Weights that define a Music::Duration::Partition phrase.

Default: [ 1, 2, 2 ]

groups

$groups = $mvp->groups;

Groups that define a Music::Duration::Partition phrase.

Default: [ 0, 0, 0 ]

motif_num

$motif_num = $mvp->motif_num;

The number of motifs to generate by the build_motifs() method.

Default: 4

motifs

$motifs = $mvp->motifs;

The rhythmic motifs generated by the Music::Duration::Partition module.

Default: 4 motifs

voices

$voices = $mvp->voices;

The pitches that are generated by the Music::VoiceGen rand() method.

Default: 4 voices

metadata

$metadata = $mvp->metadata;
$key = $mvp->metadata->{key}
$mvp->metadata(\%data);
$mvp->metadata->{key} = 'Value!';

Extra, named key/value things! No fancy get/set methods - sorry!

Default: {} (nothing extra)

verbose

$verbose = $mvp->verbose;

Show progress.

Default: 0

Extra

These attributes are used in real-time processing, etc.

name

$name = $mvp->name;

Name for the given part.

Default: 'part'

patch

$patch = $mvp->patch;

Patch / synth program integer from 0 to 127.

Default: 0 (GM piano)

gate

$gate = $mvp->gate;

A possibly fractional amount representing how long a note-length is between 0 and 2. A 0 value means that the note is not played. A 2 means the note is to be held twice as long.

Default: 1 (unity)

volume

$volume = $mvp->volume;
$mvp->volume($n);

A value from 0 to 127.

Default: 100

queue

$queue = $mvp->queue;

The priority queue list of notes to play or stop.

note

$note = $mvp->note;
$mvp->note($n);

The currently selected note hash.

Default: {}

onsets

$onsets = $mvp->onsets;

A list of note onsets.

channel

$channel = $mvp->channel;

The MIDI channel of the part.

Default: 0

rest_prob

$rest_prob = $mvp->rest_prob;
$mvp->rest_prob($n);

A value of 0 means there is no resting. A 20% chance of a rest would be 0.2. A value of 1 means "only rest." Ha!

Default: 0

METHODS

new

$mvp = Music::VoicePhrase->new(%arguments);

Create a new Music::VoicePhrase object.

build_motifs

$motifs = $mvp->build_motifs;

Build a fresh list of motifs based on the motif_num attribute.

build_voices

$voices = $mvp->build_voices;

Build a fresh list of voices based on the number of motifs.

increment_index

$i = $mvp->increment_index;

Just add one to the index attribute.

SEE ALSO

Moo

Music::Duration::Partition

Music::Scales

Music::VoiceGen

https://github.com/ology/Phrase-Generator

AUTHOR

Gene Boggs <gene.boggs@gmail.com>

COPYRIGHT AND LICENSE

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