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

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