| 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.006'; | |||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 13 | ▶ | use parent 'Exporter'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 13 | my %status; my %fstatus; | |||||||||||||||||||
| 13 | 13 | ▶ | BEGIN { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 13 | %status = ( | |||||||||||||||||||
| 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 | 13 | ▶ | sub event_desc { $event_keys } | ||||||||||||||||||
|
Subroutine
event_desc: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 239 | ▶ | sub keys_for { | ||||||||||||||||||
|
Subroutine
keys_for: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 67 | 239 | ▶ | $event_keys->{ $_[0] } // []; | ||||||||||||||||||
|
Condition100%2/2
$$event_keys{$_[0]} // []
MC/DC100%1/1
$$event_keys{$_[0]} // []
$$event_keys{$_[0]}
Truth table100%2/2
A
A= $$event_keys{$_[0]}
| |||||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 179 | ▶ | sub status_name { | ||||||||||||||||||
|
Subroutine
status_name: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||
| 72 | 179 | ▶ | $name{ $_[0] & 0xf0 } // $fname{ $_[0] }; | ||||||||||||||||||
|
Condition66%2/3
$name{$_[0] & 240} // $fname{$_[0]}
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]}
| |||||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 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]}
MC/DC0%0/2
$status{$_[0]} // $fstatus{$_[0]}
$status{$_[0]}
$fstatus{$_[0]}
Truth table66%2/3
A // B
A= $status{$_[0]}B= $fstatus{$_[0]}
| |||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 210 | ▶ | sub is_realtime { $_[0] > 0xf7 } | ||||||||||||||||||
|
Subroutine
is_realtime: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 0 | ▶ | sub is_single_byte { $_[0] > 0xf5 } | ||||||||||||||||||
|
Subroutine
is_single_byte: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 432 | ▶ | sub message_length { | ||||||||||||||||||
|
Subroutine
message_length: called CC=13 SCAR=25.8
Pod
documented
| |||||||||||||||||||||
| 86 | 432 | my ( $status ) = @_; | |||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 432 | ▶ | $status = status_byte( $status ) if ( length $status // 0 ) > 3; | ||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
length $status // 0
MC/DC100%1/1
length $status // 0
length $status
Truth table100%2/2
A
A= length $status
| |||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 432 | ▶ | return 0 unless $status; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 429 | ▶ | return 0 if $status < 0x80; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 93 | 429 | ▶ | return 3 if $status < 0xc0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 94 | 134 | ▶ | return 2 if $status < 0xe0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 95 | 92 | ▶ | return 3 if $status < 0xf0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | 30 | ▶ | return 0 if $status == 0xf0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 98 | 22 | ▶ | return 2 if $status == 0xf1; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 99 | 22 | ▶ | return 3 if $status == 0xf2; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 100 | 7 | ▶ | return 2 if $status == 0xf3; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | 7 | ▶ | return 1 if $status > 0xf5; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 103 | } | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | 0 | ▶ | sub is_status_byte { $_[0] & 0x80 } | ||||||||||||||||||
|
Subroutine
is_status_byte: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | 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
| |||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | 185 | ▶ | sub is_cc { | ||||||||||||||||||
|
Subroutine
is_cc: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 113 | 185 | ( $_[0] & 0xf0 ) == 0xb0; | |||||||||||||||||||
| 114 | } | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | 33 | ▶ | sub combine_bytes { | ||||||||||||||||||
|
Subroutine
combine_bytes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 118 | 33 | my ( $lsb, $msb ) = @_; | |||||||||||||||||||
| 119 | 33 | $msb << 7 | $lsb & 0x7f; | |||||||||||||||||||
| 120 | } | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | 24 | ▶ | sub split_bytes { | ||||||||||||||||||
|
Subroutine
split_bytes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 124 | 24 | my ( $value ) = @_; | |||||||||||||||||||
| 125 | 24 | ( $value & 0x7f, $value >> 7 & 0x7f ); | |||||||||||||||||||
| 126 | } | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | 13 | ▶ | use constant { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 129 | 13 | map { $_ => $_ } ( keys %fstatus, keys %status ) | |||||||||||||||||||
| 130 | 13 | }; | |||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | 13 | our @EXPORT_OK = qw/ | |||||||||||||||||||
| 133 | event_desc | ||||||||||||||||||||
| 134 | keys_for | ||||||||||||||||||||
| 135 | status_name | ||||||||||||||||||||
| 136 | status_byte | ||||||||||||||||||||
| 137 | status_chr | ||||||||||||||||||||
| 138 | is_realtime | ||||||||||||||||||||
| 139 | is_single_byte | ||||||||||||||||||||
| 140 | message_length | ||||||||||||||||||||
| 141 | is_status_byte | ||||||||||||||||||||
| 142 | has_channel | ||||||||||||||||||||
| 143 | is_cc | ||||||||||||||||||||
| 144 | is_pitch_bend | ||||||||||||||||||||
| 145 | combine_bytes | ||||||||||||||||||||
| 146 | split_bytes | ||||||||||||||||||||
| 147 | /; | ||||||||||||||||||||
| 148 | 13 | push @EXPORT_OK, keys %status, keys %fstatus; | |||||||||||||||||||
| 149 | 13 | our %EXPORT_TAGS = ( all => \@EXPORT_OK ); | |||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | __END__ | ||||||||||||||||||||