blib/lib/Music/VoicePhrase.pm

filter: Statementstmt 98.2% 111 / 113 Branchbran 50.0% 27 / 54 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 98.2% 56 / 57 Podpod 100% 3 / 3 totaltotal 84.3% 199 / 236 CC 30 SCAR 6.7
CC
30
Cov
81%
__ANON__
6.7
__ANON__
2.1
__ANON__
2.1
CRAP 2.0
↑ Summary
1 package Music::VoicePhrase;
2 2 our $AUTHORITY = 'cpan:GENE';
3  
4 # ABSTRACT: Construct measured phrases of notes
5  
6 2 our $VERSION = '0.0127';
7  
8 2 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Music::Duration::Partition ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Music::Scales qw(get_scale_MIDI);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Music::VoiceGen ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17  
18 has base => (
19 is => 'rw',
20 5 ▶ isa => sub { croak "$_[0] is not a valid note" unless $_[0] =~ /^[A-G][#b]?$/i },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /^[A-G][#b]?$/iu 0 5 5
21 5 ▶ default => sub { 'C' },
Subroutine __ANON__: called CC=1 SCAR=0.0
22 2 );
23  
24  
25 has index => (
26 is => 'rw',
27 5 ▶ isa => sub { croak "$_[0] is not an integer" unless $_[0] =~ /^\d+$/ },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /^\d+$/u 0 5 5
28 5 ▶ default => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
29 2 );
30  
31  
32 has scale => (
33 is => 'rw',
34 5 ▶ isa => sub { croak "$_[0] is not a valid scale name" unless $_[0] =~ /^\w+$/ },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /^\w+$/u 0 5 5
35 5 ▶ default => sub { 'major' },
Subroutine __ANON__: called CC=1 SCAR=0.0
36 2 );
37  
38  
39 has octave => (
40 is => 'rw',
41 5 ▶ isa => sub { croak "$_[0] is not a valid octave" unless $_[0] =~ /^[0-9]$/ },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /^[0-9]$/u 0 5 5
42 5 ▶ default => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
43 2 );
44  
45  
46 has pitches => (
47 is => 'rw',
48 lazy => 1,
49 2 ▶ isa => sub { croak "$_[0] is not an array-ref" unless ref $_[0] eq 'ARRAY' },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "ARRAY" 0 2 2
50 2 builder => '_build_pitches',
51 );
52  
53 1 ▶sub _build_pitches ($self) {
Subroutine _build_pitches: called CC=2 SCAR=7.1
54 1 my @pitches = (
55 get_scale_MIDI($self->base, $self->octave, $self->scale),
56 get_scale_MIDI($self->base, $self->octave + 1, $self->scale),
57 );
58 1 ▶ say 'Built pitches: ', join ' ', @pitches if $self->verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 1 1
59 1 return \@pitches;
60 }
61  
62  
63 has intervals => (
64 is => 'rw',
65 5 ▶ isa => sub { croak "$_[0] is not an array-ref" unless ref $_[0] eq 'ARRAY' },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "ARRAY" 0 5 5
66 5 ▶ default => sub { [-3, -2, -1, 1, 2, 3] },
Subroutine __ANON__: called CC=1 SCAR=0.0
67 2 );
68  
69 2 has voice => (
70 is => 'rw',
71 lazy => 1,
72 builder => '_build_voice',
73 clearer => 'clear_voice',
74 );
75  
76 2 ▶sub _build_voice ($self) {
Subroutine _build_voice: called CC=2 SCAR=7.1
77 2 my $voice = Music::VoiceGen->new(
78 pitches => $self->pitches,
79 intervals => $self->intervals,
80 verbose => $self->verbose,
81 );
82 2 ▶ say "Built voice: $voice" if $self->verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 2 2
83 2 return $voice;
84 }
85  
86  
87 has size => (
88 is => 'rw',
89 5 ▶ isa => sub { croak "$_[0] is not a valid size" unless $_[0] =~ /^[\d.]+$/ },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /^[\d.]+$/u 0 5 5
90 3 ▶ default => sub { 4 },
Subroutine __ANON__: called CC=1 SCAR=0.0
91 2 );
92  
93  
94 has pool => (
95 is => 'rw',
96 5 ▶ isa => sub { croak "$_[0] is not an array-ref" unless ref $_[0] eq 'ARRAY' },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "ARRAY" 0 5 5
97 5 ▶ default => sub { [qw(dhn hn qn)] },
Subroutine __ANON__: called CC=1 SCAR=0.0
98 2 );
99  
100  
101 has weights => (
102 is => 'rw',
103 5 ▶ isa => sub { croak "$_[0] is not an array-ref" unless ref $_[0] eq 'ARRAY' },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "ARRAY" 0 5 5
104 5 ▶ default => sub { [1, 2, 2] },
Subroutine __ANON__: called CC=1 SCAR=0.0
105 2 );
106  
107  
108 has groups => (
109 is => 'rw',
110 5 ▶ isa => sub { croak "$_[0] is not an array-ref" unless ref $_[0] eq 'ARRAY' },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "ARRAY" 0 5 5
111 5 ▶ default => sub { [0, 0, 0] },
Subroutine __ANON__: called CC=1 SCAR=0.0
112 2 );
113  
114 2 has _rhythm => (
115 is => 'rw',
116 lazy => 1,
117 builder => '_build__rhythm',
118 );
119  
120 2 ▶sub _build__rhythm ($self) {
Subroutine _build__rhythm: called CC=2 SCAR=7.1
121 2 my $mdp = Music::Duration::Partition->new(
122 size => $self->size,
123 pool => $self->pool,
124 weights => $self->weights,
125 groups => $self->groups,
126 verbose => $self->verbose,
127 );
128 2 ▶ say "Built rhythm generator: $mdp" if $self->verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 2 2
129 2 return $mdp;
130 }
131  
132  
133 has motif_num => (
134 is => 'rw',
135 5 ▶ isa => sub { croak "$_[0] is not an integer" unless $_[0] =~ /^\d+$/ },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /^\d+$/u 0 5 5
136 4 ▶ default => sub { 4 },
Subroutine __ANON__: called CC=1 SCAR=0.0
137 2 );
138  
139  
140 2 has motifs => (
141 is => 'rw',
142 lazy => 1,
143 builder => 'build_motifs',
144 clearer => 'clear_motifs',
145 );
146  
147  
148 2 has voices => (
149 is => 'rw',
150 lazy => 1,
151 builder => 'build_voices',
152 );
153  
154  
155 has metadata => (
156 is => 'rw',
157 5 ▶ isa => sub { croak "$_[0] is not a hash-ref" unless ref $_[0] eq 'HASH' },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "HASH" 0 5 5
158 4 ▶ default => sub { +{} },
Subroutine __ANON__: called CC=1 SCAR=0.0
159 2 );
160  
161  
162 has verbose => (
163 is => 'rw',
164 5 ▶ isa => sub { croak "$_[0] is not a boolean" unless $_[0] =~ /^[01]$/ },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /^[01]$/u 0 5 5
165 5 ▶ default => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
166 2 );
167  
168  
169 has name => (
170 is => 'rw',
171 5 ▶ isa => sub { croak "$_[0] is not a valid part name" unless defined $_[0] },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 5 5
172 5 ▶ default => sub { 'part' },
Subroutine __ANON__: called CC=1 SCAR=0.0
173 2 );
174  
175  
176 has patch => (
177 is => 'rw',
178 5 ▶ isa => sub { croak "$_[0] is not a valid patch" unless $_[0] =~ /^[0-9]+$/ },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /^[0-9]+$/u 0 5 5
179 5 ▶ default => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
180 2 );
181  
182  
183 has gate => (
184 is => 'rw',
185 5 ▶ isa => sub { croak "$_[0] is not a valid gate" unless $_[0] =~ /^[0-9.-]+$/ && $_[0] >= 0 && $_[0] <= 2 },
Subroutine __ANON__: called CC=4 SCAR=19.1
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /^[0-9.-]+$/u and $_[0] >= 0 and $_[0] <= 2 0 5 5
Condition33%2/6
$_[0] =~ /^[0-9.-]+$/u and $_[0] >= 0 and $_[0] <= 2
!ll&&!rl&&r
005
$_[0] =~ /^[0-9.-]+$/u and $_[0] >= 0
!ll&&!rl&&r
005
MC/DC0%0/3
$_[0] =~ /^[0-9.-]+$/u and $_[0] >= 0 and $_[0] <= 2
$_[0] =~ /^[0-9.-]+$/u $_[0] >= 0 $_[0] <= 2
Truth table25%1/4
A and B and C
A= $_[0] =~ /^[0-9.-]+$/uB= $_[0] >= 0C= $_[0] <= 2
ABCresult
0XX0
10X0
1100
1111
186 5 ▶ default => sub { 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
187 2 );
188  
189  
190 has volume => (
191 is => 'rw',
192 5 ▶ isa => sub { croak "$_[0] is not an integer" unless $_[0] =~ /^\d+$/ },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /^\d+$/u 0 5 5
193 5 ▶ default => sub { 100 },
Subroutine __ANON__: called CC=1 SCAR=0.0
194 2 );
195  
196  
197 has queue => (
198 is => 'rw',
199 5 ▶ isa => sub { croak "$_[0] is not an array-ref" unless ref $_[0] eq 'ARRAY' },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "ARRAY" 0 5 5
200 5 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
201 2 );
202  
203  
204 has note => (
205 is => 'rw',
206 5 ▶ isa => sub { croak "$_[0] is not a valid note" unless ref $_[0] eq 'HASH' },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "HASH" 0 5 5
207 5 ▶ default => sub { +{} },
Subroutine __ANON__: called CC=1 SCAR=0.0
208 2 );
209  
210  
211 has onsets => (
212 is => 'rw',
213 5 ▶ isa => sub { croak "$_[0] is not an array-ref" unless ref $_[0] eq 'ARRAY' },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "ARRAY" 0 5 5
214 5 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
215 2 );
216  
217  
218 has channel => (
219 is => 'rw',
220 5 ▶ isa => sub { croak "$_[0] is not an integer" unless $_[0] =~ /^\d+$/ },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /^\d+$/u 0 5 5
221 5 ▶ default => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
222 2 );
223  
224  
225 has rest_prob => (
226 is => 'rw',
227 5 ▶ isa => sub { croak "$_[0] is not a valid probability" unless $_[0] =~ /^[\d.]+$/ },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /^[\d.]+$/u 0 5 5
228 5 ▶ default => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
229 2 );
230  
231  
232 # sub BUILD ($self, $args) {
233 # $self->_build_motifs;
234 # }
235  
236  
237 2 ▶sub build_motifs ($self) {
Subroutine build_motifs: called CC=2 SCAR=7.1
Pod documented
238 2 my @motifs = $self->_rhythm->motifs($self->motif_num);
239 2 ▶ say "Built motifs: @motifs" if $self->verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 2 2
240 2 return \@motifs;
241 }
242  
243  
244 2 ▶sub build_voices ($self) {
Subroutine build_voices: called CC=2 SCAR=7.0
Pod documented
245 2 my @voices = map { $self->voice->rand } $self->motifs->@*;
246 2 ▶ say "Built voices: @voices" if $self->verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 2 2
247 2 return \@voices;
248 }
249  
250  
251 0 ▶sub increment_index ($self) {
Subroutine increment_index: not called CC=1 SCAR=6.9
Pod documented
252 0 $self->index($self->index + 1);
253 0 return $self->index;
254 }
255  
256 2 1;
257  
258 __END__
↑ Summary