| 1 | package Music::Intervals; | ||||||||||||||||||||||||||||||||||||||
| 2 | 2 | our $AUTHORITY = 'cpan:GENE'; | |||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: Breakdown of musical intervals | ||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||
| 9 | 2 | our $VERSION = '0.1101'; | |||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use strictures 2; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Algorithm::Combinatorics qw( combinations ); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use Data::Dumper::Compact qw(ddc); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use List::Util qw(first); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use Math::Prime::Util qw(factor lcm); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use Math::Factor::XS qw( prime_factors ); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use MIDI::Pitch qw( name2freq ); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use Music::Intervals::Ratios; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use Music::Tension::Cope (); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use Number::Fraction (); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | use POSIX qw(log2); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 23 | 2 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||
| 26 | has notes => ( | ||||||||||||||||||||||||||||||||||||||
| 27 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | default => sub { [qw( C E G )] }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 29 | 2 | ); | |||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||
| 31 | 2 | has _dyads => ( | |||||||||||||||||||||||||||||||||||||
| 32 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 33 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||
| 34 | builder => 1, | ||||||||||||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||||||||||||
| 36 | 8 | ▶ | sub _build__dyads { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_build__dyads: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 37 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 38 | 8 | my %dyads = $self->dyads($self->notes); | |||||||||||||||||||||||||||||||||||||
| 39 | 8 | return \%dyads; | |||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||
| 42 | 11 | ▶ | has _octave => ( is => 'ro', default => sub { 4 } ); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 43 | 11 | ▶ | has _concert => ( is => 'ro', default => sub { 440 } ); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 44 | 11 | ▶ | has _tonic => ( is => 'ro', default => sub { 'C' } ); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 45 | 11 | ▶ | has _semitones => ( is => 'ro', default => sub { 12 } ); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 46 | 11 | ▶ | has _midikey => ( is => 'ro', default => sub { 69 } ); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||
| 48 | 2 | has _temper => ( | |||||||||||||||||||||||||||||||||||||
| 49 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 50 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||
| 51 | builder => 1, | ||||||||||||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||||||||||||
| 53 | 2 | ▶ | sub _build__temper { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_build__temper: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 54 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 55 | 2 | $self->_semitones * 100 / log(2); | |||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||
| 58 | 2 | has _tonic_frequency => ( | |||||||||||||||||||||||||||||||||||||
| 59 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 60 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||
| 61 | builder => 1, | ||||||||||||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||||||||||||
| 63 | 7 | ▶ | sub _build__tonic_frequency { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_build__tonic_frequency: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 64 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 65 | 7 | return name2freq($self->_tonic . $self->_octave); | |||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||
| 68 | 2 | has _note_index => ( | |||||||||||||||||||||||||||||||||||||
| 69 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 70 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||
| 71 | builder => 1, | ||||||||||||||||||||||||||||||||||||||
| 72 | ); | ||||||||||||||||||||||||||||||||||||||
| 73 | 1 | ▶ | sub _build__note_index { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_build__note_index: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 74 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 75 | 1 | return { map { $_ => eval "$Music::Intervals::Ratios::ratio->{$_}{ratio}" } @{ $self->notes } }; | |||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||
| 78 | 2 | has _ratio_index => ( | |||||||||||||||||||||||||||||||||||||
| 79 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 80 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||
| 81 | builder => 1, | ||||||||||||||||||||||||||||||||||||||
| 82 | ); | ||||||||||||||||||||||||||||||||||||||
| 83 | 10 | ▶ | sub _build__ratio_index { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_build__ratio_index: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 84 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 85 | 10 | return { map { $_ => $Music::Intervals::Ratios::ratio->{$_}{ratio} } @{ $self->notes } }; | |||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||
| 88 | 2 | has _ratio_name_index => ( | |||||||||||||||||||||||||||||||||||||
| 89 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 90 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||
| 91 | builder => 1, | ||||||||||||||||||||||||||||||||||||||
| 92 | ); | ||||||||||||||||||||||||||||||||||||||
| 93 | 3 | ▶ | sub _build__ratio_name_index { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_build__ratio_name_index: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 94 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 95 | return { | ||||||||||||||||||||||||||||||||||||||
| 96 | 3 | map { $Music::Intervals::Ratios::ratio->{$_}{ratio} => { | |||||||||||||||||||||||||||||||||||||
| 97 | symbol => $_, | ||||||||||||||||||||||||||||||||||||||
| 98 | name => $Music::Intervals::Ratios::ratio->{$_}{name} } | ||||||||||||||||||||||||||||||||||||||
| 99 | 1524 | } keys %$Music::Intervals::Ratios::ratio | |||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||
| 104 | 6 | ▶ | sub integer_notation { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
integer_notation: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 105 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||
| 107 | my %integer_notation = map { $_ => sprintf '%.0f', | ||||||||||||||||||||||||||||||||||||||
| 108 | $self->_midikey + $self->_semitones | ||||||||||||||||||||||||||||||||||||||
| 109 | 12 | * log( ($self->_tonic_frequency * (eval $self->_ratio_index->{$_})) / $self->_concert ) / log(2) | |||||||||||||||||||||||||||||||||||||
| 110 | 6 | } @{ $self->notes }; | |||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||
| 112 | 6 | return \%integer_notation; | |||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||
| 116 | 2 | ▶ | sub eq_tempered_cents { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
eq_tempered_cents: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 117 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||
| 119 | 2 | my %dyads = %{ $self->_dyads }; | |||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||
| 121 | my %eq_tempered_cents = map { | ||||||||||||||||||||||||||||||||||||||
| 122 | 2 | $_ => log( $dyads{$_}->{eq_tempered} ) * $self->_temper | |||||||||||||||||||||||||||||||||||||
| 123 | } keys %dyads; | ||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||
| 125 | 2 | return \%eq_tempered_cents; | |||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||
| 129 | 4 | ▶ | sub eq_tempered_frequencies { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
eq_tempered_frequencies: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 130 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||
| 132 | my %eq_tempered_frequencies = map { | ||||||||||||||||||||||||||||||||||||||
| 133 | 10 | ▶ | $_ => name2freq( $_ . $self->_octave ) || $self->_concert * $self->_note_index->{$_} | ||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
name2freq($_ . $self->_octave) || $self->_concert * $self->_note_index->{$_}
MC/DC0%0/2
name2freq($_ . $self->_octave) || $self->_concert * $self->_note_index->{$_}
name2freq($_ . $self->_octave)
$self->_concert * $self->_note_index->{$_}
Truth table33%1/3
A || B
A= name2freq($_ . $self->_octave)B= $self->_concert * $self->_note_index->{$_}
| |||||||||||||||||||||||||||||||||||||||
| 134 | 4 | } @{ $self->notes }; | |||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||
| 136 | 4 | return \%eq_tempered_frequencies; | |||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||
| 140 | 4 | ▶ | sub eq_tempered_intervals { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
eq_tempered_intervals: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 141 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||
| 143 | 4 | my %dyads = %{ $self->_dyads }; | |||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||
| 145 | my %eq_tempered_intervals = map { | ||||||||||||||||||||||||||||||||||||||
| 146 | 4 | $_ => $dyads{$_}->{eq_tempered} | |||||||||||||||||||||||||||||||||||||
| 147 | 9 | } keys %dyads; | |||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||
| 149 | 4 | return \%eq_tempered_intervals; | |||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||
| 153 | 4 | ▶ | sub natural_cents { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
natural_cents: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 154 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||
| 156 | 4 | my %dyads = %{ $self->_dyads }; | |||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||
| 158 | my %natural_cents = map { | ||||||||||||||||||||||||||||||||||||||
| 159 | 4 | $_ => log( eval $dyads{$_}->{natural} ) * $self->_temper | |||||||||||||||||||||||||||||||||||||
| 160 | } keys %dyads; | ||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||
| 162 | 4 | return \%natural_cents; | |||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||
| 166 | 2 | ▶ | sub natural_frequencies { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
natural_frequencies: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 167 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||
| 169 | my %natural_frequencies = map { | ||||||||||||||||||||||||||||||||||||||
| 170 | $_ => { | ||||||||||||||||||||||||||||||||||||||
| 171 | $self->_tonic_frequency * eval $self->_ratio_index->{$_} . '' | ||||||||||||||||||||||||||||||||||||||
| 172 | => { $self->_ratio_index->{$_} => $Music::Intervals::Ratios::ratio->{$_}{name} } | ||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||
| 174 | 2 | } @{ $self->notes }; | |||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||
| 176 | 2 | return \%natural_frequencies; | |||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||
| 180 | 3 | ▶ | sub natural_intervals { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
natural_intervals: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 181 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||
| 183 | 3 | my %dyads = %{ $self->_dyads }; | |||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||
| 185 | my %natural_intervals = map { | ||||||||||||||||||||||||||||||||||||||
| 186 | 3 | $_ => { | |||||||||||||||||||||||||||||||||||||
| 187 | $dyads{$_}->{natural} => $self->_ratio_name_index->{ $dyads{$_}->{natural} }{name} | ||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||
| 189 | 4 | } keys %dyads; | |||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||
| 191 | 3 | return \%natural_intervals; | |||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||
| 195 | 2 | ▶ | sub natural_prime_factors { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
natural_prime_factors: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 196 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||
| 198 | 2 | my %dyads = %{ $self->_dyads }; | |||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||
| 200 | my %natural_prime_factors = map { | ||||||||||||||||||||||||||||||||||||||
| 201 | 2 | $_ => { | |||||||||||||||||||||||||||||||||||||
| 202 | $dyads{$_}->{natural} => $self->ratio_factorize( $dyads{$_}->{natural} ) | ||||||||||||||||||||||||||||||||||||||
| 203 | 3 | } | |||||||||||||||||||||||||||||||||||||
| 204 | } keys %dyads; | ||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||
| 206 | 2 | return \%natural_prime_factors; | |||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||
| 210 | 10 | ▶ | sub dyads { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
dyads: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 211 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 212 | 10 | my ($c) = @_; | |||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||
| 214 | 10 | ▶ | return () if @$c <= 1; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||
| 216 | 9 | my @pairs = combinations( $c, 2 ); | |||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||
| 218 | 9 | my %dyads; | |||||||||||||||||||||||||||||||||||||
| 219 | 9 | for my $i (@pairs) { | |||||||||||||||||||||||||||||||||||||
| 220 | # Construct our "dyadic" fraction. | ||||||||||||||||||||||||||||||||||||||
| 221 | 15 | my $numerator = Number::Fraction->new( $self->_ratio_index->{ $i->[1] } ); | |||||||||||||||||||||||||||||||||||||
| 222 | 15 | my $denominator = Number::Fraction->new( $self->_ratio_index->{ $i->[0] } ); | |||||||||||||||||||||||||||||||||||||
| 223 | 15 | my $fraction = $numerator / $denominator; | |||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||
| 225 | 15 | my $str = $fraction->to_string; | |||||||||||||||||||||||||||||||||||||
| 226 | # Handle the octave. | ||||||||||||||||||||||||||||||||||||||
| 227 | 15 | ▶ | $str .= '/1' if $fraction->to_string eq 2; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||
| 229 | # Calculate both natural and equal temperament values for our ratio. | ||||||||||||||||||||||||||||||||||||||
| 230 | $dyads{"@$i"} = { | ||||||||||||||||||||||||||||||||||||||
| 231 | natural => $str, | ||||||||||||||||||||||||||||||||||||||
| 232 | # The value is either the known pitch ratio or a calculation | ||||||||||||||||||||||||||||||||||||||
| 233 | eq_tempered => | ||||||||||||||||||||||||||||||||||||||
| 234 | ( name2freq( $i->[1] . $self->_octave ) || ( $self->_concert * $self->_note_index->{ $i->[1] } ) ) / | ||||||||||||||||||||||||||||||||||||||
| 235 | 15 | ▶ | ( name2freq( $i->[0] . $self->_octave ) || ( $self->_concert * $self->_note_index->{ $i->[0] } ) ), | ||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
name2freq($i->[1] . $self->_octave) || $self->_concert * $self->_note_index->{$i->[1]}
name2freq($i->[0] . $self->_octave) || $self->_concert * $self->_note_index->{$i->[0]}
MC/DC0%0/2
name2freq($i->[1] . $self->_octave) || $self->_concert * $self->_note_index->{$i->[1]}
name2freq($i->[1] . $self->_octave)
$self->_concert * $self->_note_index->{$i->[1]}
MC/DC0%0/2
name2freq($i->[0] . $self->_octave) || $self->_concert * $self->_note_index->{$i->[0]}
name2freq($i->[0] . $self->_octave)
$self->_concert * $self->_note_index->{$i->[0]}
Truth table66%2/3
A || B
A= name2freq($i->[1] . $self->_octave)B= $self->_concert * $self->_note_index->{$i->[1]}
Truth table33%1/3
A || B
A= name2freq($i->[0] . $self->_octave)B= $self->_concert * $self->_note_index->{$i->[0]}
| |||||||||||||||||||||||||||||||||||||||
| 236 | }; | ||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||
| 239 | 9 | return %dyads; | |||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||
| 243 | 4 | ▶ | sub ratio_factorize { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
ratio_factorize: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 244 | 4 | my ($self, $dyad) = @_; | |||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||
| 246 | 4 | my ( $numerator, $denominator ) = split /\//, $dyad; | |||||||||||||||||||||||||||||||||||||
| 247 | 4 | $numerator = [ prime_factors($numerator) ]; | |||||||||||||||||||||||||||||||||||||
| 248 | 4 | $denominator = [ prime_factors($denominator) ]; | |||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||
| 250 | 4 | return sprintf( '(%s) / (%s)', | |||||||||||||||||||||||||||||||||||||
| 251 | join( '*', @$numerator ), | ||||||||||||||||||||||||||||||||||||||
| 252 | join( '*', @$denominator ) | ||||||||||||||||||||||||||||||||||||||
| 253 | ); | ||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||
| 257 | 2 | ▶ | sub by_name { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
by_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 258 | 2 | my ( $self, $name ) = @_; | |||||||||||||||||||||||||||||||||||||
| 259 | 2 | return $Music::Intervals::Ratios::ratio->{$name}; | |||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||
| 263 | 1 | ▶ | sub by_ratio { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
by_ratio: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 264 | 1 | my ( $self, $ratio ) = @_; | |||||||||||||||||||||||||||||||||||||
| 265 | 1 | return $self->_ratio_name_index->{$ratio}; | |||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||
| 269 | 1 | ▶ | sub by_description { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
by_description: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 270 | 1 | my ( $self, $string ) = @_; | |||||||||||||||||||||||||||||||||||||
| 271 | 1 | $string = lc $string; | |||||||||||||||||||||||||||||||||||||
| 272 | 1 | my %matches; | |||||||||||||||||||||||||||||||||||||
| 273 | 1 | for my $ratio (keys %$Music::Intervals::Ratios::ratio) { | |||||||||||||||||||||||||||||||||||||
| 274 | 508 | my $found = $Music::Intervals::Ratios::ratio->{$ratio}; | |||||||||||||||||||||||||||||||||||||
| 275 | $matches{$ratio} = $found | ||||||||||||||||||||||||||||||||||||||
| 276 | 508 | ▶ | if lc($found->{name}) =~ /$string/; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||
| 278 | 1 | return \%matches; | |||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||
| 282 | 4 | ▶ | sub cope { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
cope: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 283 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 284 | 4 | my $dyads = $self->_dyads; | |||||||||||||||||||||||||||||||||||||
| 285 | 4 | my $midi = $self->integer_notation; | |||||||||||||||||||||||||||||||||||||
| 286 | 4 | my %cope; | |||||||||||||||||||||||||||||||||||||
| 287 | 4 | my $tension = Music::Tension::Cope->new; | |||||||||||||||||||||||||||||||||||||
| 288 | 4 | for my $d (keys %$dyads) { | |||||||||||||||||||||||||||||||||||||
| 289 | 4 | my ($i, $j) = split / /, $d; | |||||||||||||||||||||||||||||||||||||
| 290 | 4 | $cope{$d} = $tension->vertical([ $midi->{$i}, $midi->{$j} ]); | |||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||
| 292 | 4 | return \%cope; | |||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||
| 296 | 4 | ▶ | sub tenney { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
tenney: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 297 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 298 | 4 | my $dyads = $self->_dyads; | |||||||||||||||||||||||||||||||||||||
| 299 | 4 | my %interval; | |||||||||||||||||||||||||||||||||||||
| 300 | 4 | for my $d (keys %$dyads) { | |||||||||||||||||||||||||||||||||||||
| 301 | 4 | ▶ | my $first = first { $Music::Intervals::Ratios::ratio->{$_}{ratio} eq $dyads->{$d}{natural} } keys %$Music::Intervals::Ratios::ratio; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 302 | 4 | ▶ | $first = 0 unless $first; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 303 | $interval{$first} = { | ||||||||||||||||||||||||||||||||||||||
| 304 | 4 | ▶ | ratio => $first ? $Music::Intervals::Ratios::ratio->{$first}{ratio} : '0/0', | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 305 | dyad => $d, | ||||||||||||||||||||||||||||||||||||||
| 306 | }; | ||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||
| 308 | 4 | my %tenney; | |||||||||||||||||||||||||||||||||||||
| 309 | 4 | for my $int (keys %interval) { | |||||||||||||||||||||||||||||||||||||
| 310 | 4 | my ($i, $j) = split /\//, $interval{$int}{ratio}; | |||||||||||||||||||||||||||||||||||||
| 311 | 4 | ▶ | $tenney{ $interval{$int}{dyad} } = !($i && $j) ? 0 : log2($i * $j); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$i && $j
MC/DC50%1/2
$i && $j
$i
$j
Truth table66%2/3
A && B
A= $iB= $j
| |||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||
| 313 | 4 | return \%tenney; | |||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||
| 317 | 4 | ▶ | sub suavitatis { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
suavitatis: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 318 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 319 | 4 | my $dyads = $self->_dyads; | |||||||||||||||||||||||||||||||||||||
| 320 | 4 | my %interval; | |||||||||||||||||||||||||||||||||||||
| 321 | 4 | for my $d (keys %$dyads) { | |||||||||||||||||||||||||||||||||||||
| 322 | 4 | ▶ | my $first = first { $Music::Intervals::Ratios::ratio->{$_}{ratio} eq $dyads->{$d}{natural} } keys %$Music::Intervals::Ratios::ratio; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 323 | 4 | ▶ | $first = 0 unless $first; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 324 | $interval{$first} = { | ||||||||||||||||||||||||||||||||||||||
| 325 | 4 | ▶ | ratio => $first ? $Music::Intervals::Ratios::ratio->{$first}{ratio} : '0/0', | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 326 | dyad => $d, | ||||||||||||||||||||||||||||||||||||||
| 327 | }; | ||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||
| 329 | 4 | my %suavitatis; | |||||||||||||||||||||||||||||||||||||
| 330 | 4 | for my $int (keys %interval) { | |||||||||||||||||||||||||||||||||||||
| 331 | 4 | my ($i, $j) = split /\//, $interval{$int}{ratio}; | |||||||||||||||||||||||||||||||||||||
| 332 | 4 | my $lcm = lcm($i, $j); | |||||||||||||||||||||||||||||||||||||
| 333 | 4 | my @factors = factor($lcm); | |||||||||||||||||||||||||||||||||||||
| 334 | 4 | my $sum = 0; | |||||||||||||||||||||||||||||||||||||
| 335 | 4 | $sum += $_ - 1 for @factors; | |||||||||||||||||||||||||||||||||||||
| 336 | 4 | $suavitatis{ $interval{$int}{dyad} } = 1 + $sum; | |||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||
| 338 | 4 | return \%suavitatis; | |||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||
| 341 | 2 | 1; | |||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||
| 343 | __END__ | ||||||||||||||||||||||||||||||||||||||