blib/lib/MIDI/RtController/Filter/Drums.pm

filter: Statementstmt 81.8% 9 / 11 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 86.6% 13 / 15 CC 1 SCAR 0.7
CC
1
Cov
82%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary
1 package MIDI::RtController::Filter::Drums;
2 our $AUTHORITY = 'cpan:GENE';
3  
4 # ABSTRACT: Generic RtController drum filter
5  
6 2 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 our $VERSION = '0.0402';
9  
10 2 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use MIDI::Drummer::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 0 ▶use MIDI::RtMidi::ScorePlayer ();
Subroutine BEGIN: called CC=1 SCAR=2.6
13 use Moo;
14 use Types::Common::Numeric qw(PositiveInt);
15 use Types::Standard qw(CodeRef HashRef);
16 use namespace::clean;
17  
18 extends 'MIDI::RtController::Filter';
19  
20  
21  
22 has bars => (
23 is => 'rw',
24 isa => PositiveInt,
25 default => sub { 1 },
26 );
27  
28  
29 has bpm => (
30 is => 'rw',
31 isa => PositiveInt,
32 default => sub { 120 },
33 );
34  
35  
36 has phrase => (
37 is => 'rw',
38 isa => CodeRef,
39 builder => 1,
40 );
41  
42 sub _build_phrase {
43 return sub {
44 my (%args) = @_;
45 $args{drummer}->metronome4;
46 };
47 }
48  
49  
50 has common => (
51 is => 'rw',
52 isa => HashRef,
53 default => sub { {} },
54 );
55  
56  
57 sub _drum_part ($self) {
58 return $self->phrase;
59 }
60 sub drums ($self, $device, $dt, $event) {
61 my ($ev, $chan, $note, $val) = $event->@*;
62  
63 return 0 unless $ev eq 'note_on'
64 || ($ev eq 'control_change' && defined $self->value && defined $val && $val == $self->value);
65  
66 return 0 if $ev eq 'note_on' && defined $self->trigger && $note != $self->trigger;
67  
68 my $part = $self->_drum_part;
69  
70 my $d = MIDI::Drummer::Tiny->new(
71 bpm => $self->bpm,
72 bars => $self->bars,
73 );
74  
75 my $common = $self->common;
76 $common = { %$common, drummer => $d };
77  
78 MIDI::RtMidi::ScorePlayer->new(
79 device => $self->rtc->midi_out,
80 score => $d->score,
81 common => $common,
82 parts => [ $part ],
83 sleep => 0,
84 infinite => 0,
85 )->play_async->retain;
86  
87 return $self->continue;
88 }
89  
90 1;
91  
92 __END__
↑ Summary