PlayTab/Note.pm

filter: Statementstmt 92.8% 39 / 42 Branchbran 71.4% 10 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 88.8% 8 / 9 Podpod 0.0% 0 / 5 totaltotal 77.3% 58 / 75 CC 9 SCAR 13.6
CC
9
Cov
85%
parse
7.3
new
2.1
transpose
2.0
CRAP 3.9
« PlayTab/Output/PostScript.pm ↑ Summary PlayTab/NoteMap.pm »
1 #! perl
2  
3 # Author : Johan Vromans
4 # Created On : Wed Aug 22 22:33:31 2007
5 # Last Modified By: Johan Vromans
6 # Last Modified On: Sat Mar 29 22:25:40 2014
7 # Update Count : 7
8 # Status : Unknown, Use with caution!
9  
10 package App::Music::PlayTab::Note;
11  
12 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 7 our $VERSION = "1.005";
16  
17 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 7 ▶use App::Music::PlayTab::NoteMap qw(note_to_key key_to_note);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 7 my $debug;
21  
22 699 ▶sub new {
Subroutine new: called CC=2 SCAR=7.6
Pod undocumented
23 699 my $pkg = shift;
24 699 ▶ $pkg = ref($pkg) || $pkg;
Condition33%1/3
ref $pkg || $pkg
l!l&&r!l&&!r
06990
MC/DC0%0/2
ref $pkg || $pkg
ref $pkg $pkg
Truth table33%1/3
A || B
A= ref $pkgB= $pkg
ABresult
1X1
011
000
25 699 bless {}, $pkg;
26 }
27  
28 699 ▶sub parse {
Subroutine parse: called CC=7 SCAR=19.9
Pod undocumented
29 699 my ($self, $note) = @_;
30  
31 # Parse note name and return internal code.
32 699 ▶ $self = $self->new unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 699 0 699
33  
34 # Trim.
35 699 $note =~ s/\s+$//;
36 699 $self->{unparsed} = $note;
37  
38 # Get out if relative scale specifier.
39 699 ▶ return '*' if $note eq '*'; # TODO: Why?
Branch: 1 branch
BranchTrueFalseTotal
if $note eq "*" 0 699 699
40  
41 699 my $res;
42  
43 # Try sharp notes, e.g. Ais, C#.
44 699 ▶ if ( $note =~ /^([a-g])(is|\#)$/i ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($note =~ /^([a-g])(is|\#)$/i) { } 65 634 699
elsif ($note =~ /^([a-g])(e?s|b)$/i) { } 107 527 634
elsif ($note =~ /^([a-g])$/i) { } 527 0 527
45 65 $res = (note_to_key($1) + 1) % 12;
46 }
47 # Try flat notes, e.g. Es, Bes, Db.
48 elsif ( $note =~ /^([a-g])(e?s|b)$/i ) {
49 107 $res = (note_to_key($1) - 1) % 12;
50 107 $self->{useflat} = 1;
51 }
52 # Try plain note, e.g. A, C.
53 elsif ( $note =~ /^([a-g])$/i ) {
54 527 $res = note_to_key($1);
55 }
56  
57 # No more tries.
58 699 ▶ unless ( defined $res ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $res) 0 699 699
59 0 croak("Unrecognized note name \"$note\"");
60 }
61  
62 # Return.
63 699 $self->{key} = $res;
64 699 $self;
65 }
66  
67 275 ▶sub transpose {
Subroutine transpose: called CC=2 SCAR=6.9
Pod undocumented
68 275 my ($self, $xp) = @_;
69 275 ▶ return $self unless $xp;
Branch: 1 branch
BranchTrueFalseTotal
unless $xp 6 269 275
70 269 $self->{key} = ($self->{key} + $xp) % 12;
71 269 $self->{useflat} = $xp < 0;
72 269 $self;
73 }
74  
75 0 ▶sub key {
Subroutine key: not called CC=1 SCAR=6.9
Pod undocumented
76 0 my $self = shift;
77 0 $self->{key};
78 }
79  
80 819 ▶sub name {
Subroutine name: called CC=1 SCAR=0.0
Pod undocumented
81 819 my $self = shift;
82 819 App::Music::PlayTab::NoteMap::key_to_note($self->{key}, $self->{useflat});
83 }
84  
85 7 1;
86  
87 __END__
« PlayTab/Output/PostScript.pm ↑ Summary PlayTab/NoteMap.pm »