Stream/Tables.pm

filter: Statementstmt 95.7% 45 / 47 Branchbran 83.3% 20 / 24 Conditioncond 80.0% 8 / 10 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 87.5% 14 / 16 Podpod 100% 11 / 11 totaltotal 87.7% 100 / 114 CC 17 SCAR 18.4
CC
17
Cov
90%
message_length
13.2
status_name
2.1
status_byte
2.1
CRAP 6.3
« Stream/Decoder.pm ↑ Summary Stream/Event/TimeCode.pm »
1 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package MIDI::Stream::Tables;
4  
5 # ABSTRACT: MIDI 1.0 look up tables and utility functions
6  
7  
8 13 our $VERSION = '0.005';
9  
10 13 ▶use parent 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 13 my %status; my %fstatus;
13 BEGIN {
14 13 ▶ %status = (
Subroutine BEGIN: called CC=1 SCAR=0.0
15 note_off => 0x80,
16 note_on => 0x90,
17 polytouch => 0xa0,
18 control_change => 0xb0,
19 program_change => 0xc0,
20 aftertouch => 0xd0,
21 pitch_bend => 0xe0,
22 );
23  
24 13 %fstatus = (
25 sysex => 0xf0,
26 timecode => 0xf1,
27 song_position => 0xf2,
28 song_select => 0xf3,
29 tune_request => 0xf6,
30 eox => 0xf7,
31 clock => 0xf8,
32 start => 0xfa,
33 continue => 0xfb,
34 stop => 0xfc,
35 active_sensing => 0xfe,
36 system_reset => 0xff,
37 );
38 }
39  
40 13 my %name = reverse %status;
41 13 my %fname = reverse %fstatus;
42  
43 # Not exactly ecstatic about this pattern, but an alternative has yet to
44 # occur to me. One alternative I thought about was having objects push their
45 # ordered keys to an array in the top-level class, but this means you need
46 # an object instance to get the ordering:
47 # $class->from_hashref( $event )->as_arrayref seemed a little perverse.
48 13 my $event_keys = {
49 note_off => [qw/ channel note velocity /],
50 note_on => [qw/ channel note velocity /],
51 polytouch => [qw/ channel note pressure /],
52 control_change => [qw/ channel control value /],
53 program_change => [qw/ channel program /],
54 aftertouch => [qw/ channel pressure /],
55 pitch_bend => [qw/ channel value /],
56 song_position => [qw/ position /],
57 song_select => [qw/ song /],
58 timecode => [qw/ byte /],
59 sysex => [qw/ msg /],
60 };
61  
62  
63 sub keys_for {
64 235 ▶ $event_keys->{ $_[0] } // [];
Subroutine keys_for: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
$$event_keys{$_[0]} // []
l!l
20728
MC/DC100%1/1
$$event_keys{$_[0]} // []
$$event_keys{$_[0]}
Truth table100%2/2
A
A= $$event_keys{$_[0]}
Aresult
11
00
65 }
66  
67  
68 sub status_name {
69 165 ▶ $name{ $_[0] & 0xf0 } // $fname{ $_[0] };
Subroutine status_name: called CC=2 SCAR=7.2
Pod documented
Condition66%2/3
$name{$_[0] & 240} // $fname{$_[0]}
l!l&&r!l&&!r
122430
MC/DC0%0/2
$name{$_[0] & 240} // $fname{$_[0]}
$name{$_[0] & 240} $fname{$_[0]}
Truth table66%2/3
A // B
A= $name{$_[0] & 240}B= $fname{$_[0]}
ABresult
1X1
011
000
70 }
71  
72  
73 292 ▶sub status_byte { $status{ $_[0] } // $fstatus{ $_[0] } }
Subroutine status_byte: called CC=2 SCAR=7.2
Pod documented
Condition66%2/3
$status{$_[0]} // $fstatus{$_[0]}
l!l&&r!l&&!r
258340
MC/DC0%0/2
$status{$_[0]} // $fstatus{$_[0]}
$status{$_[0]} $fstatus{$_[0]}
Truth table66%2/3
A // B
A= $status{$_[0]}B= $fstatus{$_[0]}
ABresult
1X1
011
000
74  
75  
76 196 ▶sub is_realtime { $_[0] > 0xf7 }
Subroutine is_realtime: called CC=1 SCAR=0.0
Pod documented
77  
78  
79 0 ▶sub is_single_byte { $_[0] > 0xf5 }
Subroutine is_single_byte: not called CC=1 SCAR=6.9
Pod documented
80  
81  
82 sub message_length {
83 400 ▶ my ( $status ) = @_;
Subroutine message_length: called CC=13 SCAR=25.8
Pod documented
84  
85 400 ▶ $status = status_byte( $status ) if ( length $status // 0 ) > 3;
Branch: 1 branch
BranchTrueFalseTotal
if (length $status // 0) > 3 81 319 400
Condition100%2/2
length $status // 0
l!l
3973
MC/DC100%1/1
length $status // 0
length $status
Truth table100%2/2
A
A= length $status
Aresult
11
00
86  
87 400 ▶ return 0 unless $status;
Branch: 1 branch
BranchTrueFalseTotal
unless $status 3 397 400
88  
89 397 ▶ return 0 if $status < 0x80;
Branch: 1 branch
BranchTrueFalseTotal
if $status < 128 0 397 397
90 397 ▶ return 3 if $status < 0xc0;
Branch: 1 branch
BranchTrueFalseTotal
if $status < 192 271 126 397
91 126 ▶ return 2 if $status < 0xe0;
Branch: 1 branch
BranchTrueFalseTotal
if $status < 224 42 84 126
92 84 ▶ return 3 if $status < 0xf0;
Branch: 1 branch
BranchTrueFalseTotal
if $status < 240 56 28 84
93  
94 28 ▶ return 0 if $status == 0xf0;
Branch: 1 branch
BranchTrueFalseTotal
if $status == 240 8 20 28
95 20 ▶ return 2 if $status == 0xf1;
Branch: 1 branch
BranchTrueFalseTotal
if $status == 241 0 20 20
96 20 ▶ return 3 if $status == 0xf2;
Branch: 1 branch
BranchTrueFalseTotal
if $status == 242 15 5 20
97 5 ▶ return 2 if $status == 0xf3;
Branch: 1 branch
BranchTrueFalseTotal
if $status == 243 0 5 5
98  
99 5 ▶ return 1 if $status > 0xf5;
Branch: 1 branch
BranchTrueFalseTotal
if $status > 245 5 0 5
100 }
101  
102  
103 0 ▶sub is_status_byte { $_[0] & 0x80 }
Subroutine is_status_byte: not called CC=1 SCAR=6.9
Pod documented
104  
105  
106 272 ▶sub has_channel { ( length $_[0] > 3 ? status_byte( $_[0] ) : $_[0] ) < 0xf0 }
Subroutine has_channel: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
length $_[0] > 3 ? : 98 174 272
107  
108  
109 sub is_cc {
110 171 ▶ ( $_[0] & 0xf0 ) == 0xb0;
Subroutine is_cc: called CC=1 SCAR=0.0
Pod documented
111 }
112  
113  
114 sub combine_bytes {
115 31 ▶ my ( $lsb, $msb ) = @_;
Subroutine combine_bytes: called CC=1 SCAR=0.0
Pod documented
116 31 $msb << 7 | $lsb & 0x7f;
117 }
118  
119  
120 sub split_bytes {
121 24 ▶ my ( $value ) = @_;
Subroutine split_bytes: called CC=1 SCAR=0.0
Pod documented
122 24 ( $value & 0x7f, $value >> 7 & 0x7f );
123 }
124  
125 use constant {
126 13 map { $_ => $_ } ( keys %fstatus, keys %status )
127 13 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
128  
129 13 our @EXPORT_OK = qw/
130 keys_for
131 status_name
132 status_byte
133 status_chr
134 is_realtime
135 is_single_byte
136 message_length
137 is_status_byte
138 has_channel
139 is_cc
140 is_pitch_bend
141 combine_bytes
142 split_bytes
143 /;
144 13 push @EXPORT_OK, keys %status, keys %fstatus;
145 13 our %EXPORT_TAGS = ( all => \@EXPORT_OK );
146  
147 __END__
« Stream/Decoder.pm ↑ Summary Stream/Event/TimeCode.pm »