| 1 | package MIDI::Device; | ||||||||||||
| 2 | 3 | our $AUTHORITY = 'cpan:GENE'; | |||||||||||
| 3 | |||||||||||||
| 4 | # ABSTRACT: MIDI device metadata | ||||||||||||
| 5 | |||||||||||||
| 6 | 3 | our $VERSION = '0.0304'; | |||||||||||
| 7 | |||||||||||||
| 8 | 3 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 3 | ▶ | use strictures 2; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 3 | ▶ | use Carp qw(croak); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | # use Data::Dumper::Compact qw(ddc); | ||||||||||||
| 12 | 3 | ▶ | use File::ShareDir qw(dist_dir); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 3 | ▶ | use File::Spec (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | 3 | ▶ | use YAML::XS qw(LoadFile); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | 3 | ▶ | use namespace::clean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | |||||||||||||
| 17 | |||||||||||||
| 18 | 3 | has name => ( | |||||||||||
| 19 | is => 'ro', | ||||||||||||
| 20 | required => 1, | ||||||||||||
| 21 | ); | ||||||||||||
| 22 | |||||||||||||
| 23 | |||||||||||||
| 24 | 3 | has module => ( | |||||||||||
| 25 | is => 'ro', | ||||||||||||
| 26 | default => 'MIDI::Device', | ||||||||||||
| 27 | required => 1, | ||||||||||||
| 28 | ); | ||||||||||||
| 29 | |||||||||||||
| 30 | |||||||||||||
| 31 | 3 | has shared => ( | |||||||||||
| 32 | is => 'lazy', | ||||||||||||
| 33 | ); | ||||||||||||
| 34 | 13 | ▶ | sub _build_shared { | ||||||||||
|
Subroutine
_build_shared: called CC=3 SCAR=11.3
| |||||||||||||
| 35 | 13 | my ($self) = @_; | |||||||||||
| 36 | 13 | ▶ | my $shared = eval { dist_dir($self->module) } || './share/'; | ||||||||||
|
Condition50%1/2
eval {
do {
dist_dir($self->module)
}
} || './share/'
MC/DC0%0/1
eval {
do {
dist_dir($self->module)
}
} || './share/'
eval {
do {
dist_dir($self->module)
}
}
Truth table50%1/2
A
A= eval {
do {
dist_dir($self->module)
}
}
| |||||||||||||
| 37 | 13 | ▶ | croak "File $shared doesn't exist: $!" unless -e $shared; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 38 | 13 | return $shared; | |||||||||||
| 39 | } | ||||||||||||
| 40 | |||||||||||||
| 41 | has _device => ( | ||||||||||||
| 42 | is => 'rw', | ||||||||||||
| 43 | 25 | ▶ | default => sub { {} }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 44 | 3 | ); | |||||||||||
| 45 | |||||||||||||
| 46 | |||||||||||||
| 47 | 24 | ▶ | sub cc { | ||||||||||
|
Subroutine
cc: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 48 | 24 | my ($self) = @_; | |||||||||||
| 49 | 24 | ▶ | my $cc = $self->_device->{control_change} || []; | ||||||||||
|
Condition100%2/2
$self->_device->{'control_change'} || []
MC/DC100%1/1
$self->_device->{'control_change'} || []
$self->_device->{'control_change'}
Truth table100%2/2
A
A= $self->_device->{'control_change'}
| |||||||||||||
| 50 | 24 | return $cc; | |||||||||||
| 51 | } | ||||||||||||
| 52 | |||||||||||||
| 53 | |||||||||||||
| 54 | 16 | ▶ | sub manufacturer { | ||||||||||
|
Subroutine
manufacturer: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 55 | 16 | my ($self) = @_; | |||||||||||
| 56 | 16 | return $self->_device->{manufacturer}; | |||||||||||
| 57 | } | ||||||||||||
| 58 | |||||||||||||
| 59 | |||||||||||||
| 60 | 25 | ▶ | sub BUILD { | ||||||||||
|
Subroutine
BUILD: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||
| 61 | 25 | my ($self) = @_; | |||||||||||
| 62 | 25 | ▶ | return unless $self->name; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 63 | |||||||||||||
| 64 | 24 | my $file = File::Spec->catfile($self->shared, $self->name . '.yml'); | |||||||||||
| 65 | 24 | ▶ | croak "File $file doesn't exist: $!" unless -e $file; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 66 | |||||||||||||
| 67 | 22 | $self->_device(LoadFile($file)); | |||||||||||
| 68 | } | ||||||||||||
| 69 | |||||||||||||
| 70 | |||||||||||||
| 71 | 14 | ▶ | sub note_on { | ||||||||||
|
Subroutine
note_on: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 72 | 14 | my ($self) = @_; | |||||||||||
| 73 | 14 | return $self->_device->{note_on}; | |||||||||||
| 74 | } | ||||||||||||
| 75 | |||||||||||||
| 76 | |||||||||||||
| 77 | 2 | ▶ | sub pitch_bend { | ||||||||||
|
Subroutine
pitch_bend: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 78 | 2 | my ($self) = @_; | |||||||||||
| 79 | 2 | return $self->_device->{pitch_wheel_change}; | |||||||||||
| 80 | } | ||||||||||||
| 81 | |||||||||||||
| 82 | |||||||||||||
| 83 | 15 | ▶ | sub port_in { | ||||||||||
|
Subroutine
port_in: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 84 | 15 | my ($self) = @_; | |||||||||||
| 85 | 15 | return $self->_device->{port}{in}; | |||||||||||
| 86 | } | ||||||||||||
| 87 | |||||||||||||
| 88 | |||||||||||||
| 89 | 15 | ▶ | sub port_out { | ||||||||||
|
Subroutine
port_out: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 90 | 15 | my ($self) = @_; | |||||||||||
| 91 | 15 | return $self->_device->{port}{out}; | |||||||||||
| 92 | } | ||||||||||||
| 93 | |||||||||||||
| 94 | |||||||||||||
| 95 | 13 | ▶ | sub find { | ||||||||||
|
Subroutine
find: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||
| 96 | 13 | my ($self, $key, $value) = @_; | |||||||||||
| 97 | 13 | ▶ | return unless exists $self->_device->{$key}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 98 | 11 | my @found; | |||||||||||
| 99 | 11 | for my $i (@{ $self->_device->{$key} }) { | |||||||||||
| 100 | 154 | ▶ | push @found, $i if $i->{note} =~ /\Q$value\E/i; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 101 | } | ||||||||||||
| 102 | 11 | return \@found; | |||||||||||
| 103 | } | ||||||||||||
| 104 | |||||||||||||
| 105 | |||||||||||||
| 106 | 3 | 1; | |||||||||||
| 107 | |||||||||||||
| 108 | __END__ | ||||||||||||