File Coverage

blib/lib/Music/VoicePhrase.pm
Criterion Covered Total %
statement 42 42 100.0
branch n/a
condition n/a
subroutine 12 12 100.0
pod n/a
total 54 54 100.0


line stmt bran cond sub pod time code
1             package Music::VoicePhrase;
2             our $AUTHORITY = 'cpan:GENE';
3              
4             # ABSTRACT: Construct a measured phrase of notes
5              
6             our $VERSION = '0.0104';
7              
8 2     2   569442 use v5.36;
  2         7  
9 2     2   1162 use Moo;
  2         15372  
  2         16  
10 2     2   3414 use strictures 2;
  2         3093  
  2         64  
11 2     2   730 use Carp qw(croak);
  2         5  
  2         85  
12 2     2   911 use Music::Duration::Partition ();
  2         144543  
  2         93  
13 2     2   1056 use Music::Scales qw(get_scale_MIDI);
  2         12588  
  2         185  
14 2     2   1296 use Music::VoiceGen ();
  2         20860  
  2         68  
15 2     2   15 use namespace::clean;
  2         9  
  2         9  
16              
17              
18             has base => (
19             is => 'ro',
20             isa => sub { croak "$_[0] is not a valid note" unless $_[0] =~ /^[A-G][#b]?$/i },
21             default => sub { 'C' },
22             );
23              
24              
25             has scale => (
26             is => 'ro',
27             isa => sub { croak "$_[0] is not a valid scale name" unless $_[0] =~ /^\w+$/ },
28             default => sub { 'major' },
29             );
30              
31              
32             has octave => (
33             is => 'ro',
34             isa => sub { croak "$_[0] is not a valid octave" unless $_[0] =~ /^[0-9]$/ },
35             default => sub { 0 },
36             );
37              
38              
39             has pitches => (
40             is => 'lazy',
41             isa => sub { croak "$_[0] is not an array-ref" unless ref $_[0] eq 'ARRAY' },
42             builder => '_build_pitches',
43             );
44              
45 1     1   2524 sub _build_pitches ($self) {
  1         3  
  1         1  
46 1         13 my @pitches = (
47             get_scale_MIDI($self->base, $self->octave, $self->scale),
48             get_scale_MIDI($self->base, $self->octave + 1, $self->scale),
49             );
50 1         127 return \@pitches;
51             }
52              
53              
54             has intervals => (
55             is => 'ro',
56             isa => sub { croak "$_[0] is not an array-ref" unless ref $_[0] eq 'ARRAY' },
57             default => sub { [-3, -2, -1, 1, 2, 3] },
58             );
59              
60             has _voice => (
61             is => 'lazy',
62             builder => '_build__voice',
63             );
64              
65 1     1   1268 sub _build__voice ($self) {
  1         2  
  1         2  
66 1         72 my $voice = Music::VoiceGen->new(
67             pitches => $self->pitches,
68             intervals => $self->intervals,
69             );
70 1         3168 return $voice;
71             }
72              
73              
74             has size => (
75             is => 'ro',
76             isa => sub { croak "$_[0] is not a valid size" unless $_[0] =~ /^\d+$/ },
77             default => sub { 4 },
78             );
79              
80              
81             has pool => (
82             is => 'ro',
83             isa => sub { croak "$_[0] is not an array-ref" unless ref $_[0] eq 'ARRAY' },
84             default => sub { [qw(dhn hn qn)] },
85             );
86              
87              
88             has weights => (
89             is => 'ro',
90             isa => sub { croak "$_[0] is not an array-ref" unless ref $_[0] eq 'ARRAY' },
91             default => sub { [1, 2, 2] },
92             );
93              
94              
95             has groups => (
96             is => 'ro',
97             isa => sub { croak "$_[0] is not an array-ref" unless ref $_[0] eq 'ARRAY' },
98             default => sub { [0, 0, 0] },
99             );
100              
101             has _rhythm => (
102             is => 'lazy',
103             builder => '_build__rhythm',
104             );
105              
106 1     1   9 sub _build__rhythm ($self) {
  1         1  
  1         1  
107 1         14 my $mdp = Music::Duration::Partition->new(
108             size => $self->size,
109             pool => $self->pool,
110             weights => $self->weights,
111             groups => $self->groups,
112             );
113             }
114              
115              
116             has motif_num => (
117             is => 'rw',
118             isa => sub { croak "$_[0] is not an integer" unless $_[0] =~ /^\d+$/ },
119             default => sub { 4 },
120             );
121              
122              
123             has motifs => (
124             is => 'rw',
125             lazy => 1,
126             builder => '_build_motifs',
127             );
128              
129 1     1   3404 sub _build_motifs ($self) {
  1         2  
  1         2  
130 1         20 my @motifs = $self->_rhythm->motifs($self->motif_num);
131 1         1618 return \@motifs;
132             }
133              
134              
135             has verbose => (
136             is => 'ro',
137             isa => sub { croak "$_[0] is not a boolean" unless $_[0] =~ /^[01]$/ },
138             default => sub { 0 },
139             );
140              
141              
142             sub BUILD ($self, $args) {
143             # $self->_build_motifs;
144             }
145              
146              
147             1;
148              
149             __END__