| 1 | package Peta::MIDI::Device::Out; | ||||||||||||||||||||||
| 2 | # ABSTRACT: a MIDI output as MIDI::RtMidi::FFI::Device::Out has it | ||||||||||||||||||||||
| 3 | |||||||||||||||||||||||
| 4 | # A MIDI output as MIDI::RtMidi::FFI::Device::Out has it: messages as | ||||||||||||||||||||||
| 5 | # bytes, or events encoded (Peta::MIDI::Encoder: MIDI::Stream's names and | ||||||||||||||||||||||
| 6 | # MIDI::Event's), and a sender for each kind of event; RPN and NRPN, and a | ||||||||||||||||||||||
| 7 | # panic. Out of the device's port to whoever it is connected to. | ||||||||||||||||||||||
| 8 | |||||||||||||||||||||||
| 9 | 1 | ▶ | use v5.36; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 10 | 1 | ▶ | use parent 'Peta::MIDI::Device'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 11 | 1 | ▶ | use Carp qw(croak); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 12 | 1 | ▶ | use Peta::MIDI::Encoder; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 13 | |||||||||||||||||||||||
| 14 | 1 | our $VERSION = '0.2610180'; | |||||||||||||||||||||
| 15 | |||||||||||||||||||||||
| 16 | 0 | ▶ | sub _direction ($self) { return 'out' } | ||||||||||||||||||||
|
Subroutine
_direction: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 17 | |||||||||||||||||||||||
| 18 | 0 | ▶ | sub _build ($self, %arg) { | ||||||||||||||||||||
|
Subroutine
_build: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||
| 19 | $self->{encoder} = Peta::MIDI::Encoder->new( | ||||||||||||||||||||||
| 20 | enable_14bit_cc => $arg{enable_14bit_cc} // 0, | ||||||||||||||||||||||
| 21 | 0 | ▶ | enable_running_status => $arg{enable_running_status} // 0, | ||||||||||||||||||||
|
Condition0%0/4
$arg{"enable_14bit_cc"} // 0
$arg{"enable_running_status"} // 0
MC/DC0%0/1
$arg{"enable_14bit_cc"} // 0
$arg{"enable_14bit_cc"}
MC/DC0%0/1
$arg{"enable_running_status"} // 0
$arg{"enable_running_status"}
Truth table0%0/2
A
A= $arg{"enable_14bit_cc"}
Truth table0%0/2
A
A= $arg{"enable_running_status"}
| |||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||
| 23 | 0 | return; | |||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||
| 25 | |||||||||||||||||||||||
| 26 | # Messages, each its bytes. | ||||||||||||||||||||||
| 27 | 0 | ▶ | sub send_message ($self, @messages) { | ||||||||||||||||||||
|
Subroutine
send_message: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||
| 28 | 0 | ▶ | croak 'no port is open' if !defined $self->{port}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 29 | 0 | $self->{alsa}->send($self->{port}, $_) for @messages; | |||||||||||||||||||||
| 30 | 0 | return; | |||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||
| 32 | |||||||||||||||||||||||
| 33 | # An event's bytes, [ name, fields ... ] given flat or as lists of them. | ||||||||||||||||||||||
| 34 | 0 | ▶ | sub encode_message ($self, @event) { | ||||||||||||||||||||
|
Subroutine
encode_message: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||
| 35 | 0 | ▶ | return map { $self->encode_message(@$_) } @event if ref $event[0] eq 'ARRAY'; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 36 | 0 | return $self->{encoder}->encode([ $self->name_from_midi_event(shift @event), @event ]); | |||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||
| 38 | 0 | ▶ | sub encode ($self, @event) { return $self->encode_message(@event) } | ||||||||||||||||||||
|
Subroutine
encode: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 39 | |||||||||||||||||||||||
| 40 | 0 | ▶ | sub send_message_encoded ($self, @event) { return $self->send_message($self->encode_message(@event)) } | ||||||||||||||||||||
|
Subroutine
send_message_encoded: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 41 | 0 | ▶ | sub send_event ($self, @event) { return $self->send_message_encoded(@event) } | ||||||||||||||||||||
|
Subroutine
send_event: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 42 | |||||||||||||||||||||||
| 43 | # A sender for each kind of event, as send_event(name => @fields). | ||||||||||||||||||||||
| 44 | 1 | for my $name (qw(note_off note_on control_change patch_change key_after_touch channel_after_touch pitch_wheel_change | |||||||||||||||||||||
| 45 | sysex clock start stop continue)) { | ||||||||||||||||||||||
| 46 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 47 | 0 | ▶ | *$name = sub ($self, @fields) { return $self->send_event($name => @fields) }; | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||
| 49 | 0 | ▶ | sub cc ($self, @fields) { return $self->control_change(@fields) } | ||||||||||||||||||||
|
Subroutine
cc: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 50 | 0 | ▶ | sub program_change ($self, @fields) { return $self->patch_change(@fields) } | ||||||||||||||||||||
|
Subroutine
program_change: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 51 | 0 | ▶ | sub aftertouch ($self, @fields) { return $self->channel_after_touch(@fields) } | ||||||||||||||||||||
|
Subroutine
aftertouch: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 52 | 0 | ▶ | sub polytouch ($self, @fields) { return $self->key_after_touch(@fields) } | ||||||||||||||||||||
|
Subroutine
polytouch: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 53 | 0 | ▶ | sub pitch_bend ($self, @fields) { return $self->pitch_wheel_change(@fields) } | ||||||||||||||||||||
|
Subroutine
pitch_bend: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 54 | |||||||||||||||||||||||
| 55 | # A registered parameter set: its number and value of 14 bits each (or | ||||||||||||||||||||||
| 56 | # [ coarse, fine ]; a value [ coarse ] alone sends no fine part), then the | ||||||||||||||||||||||
| 57 | # null parameter. | ||||||||||||||||||||||
| 58 | 0 | ▶ | sub rpn ($self, $channel, $number, $value, $controllers = [ 101, 100 ]) { | ||||||||||||||||||||
|
Subroutine
rpn: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||
| 59 | 0 | ▶ | my ($number_coarse, $number_fine) = ref $number eq 'ARRAY' ? map { $_ // 0 } @$number[ 0, 1 ] : ($number >> 7, $number & 0x7f); | ||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$_ // 0
MC/DC0%0/1
$_ // 0
$_
Truth table0%0/2
A
A= $_
| |||||||||||||||||||||||
| 60 | 0 | ▶ | my ($coarse, $fine) = ref $value eq 'ARRAY' ? @$value : ($value >> 7, $value & 0x7f); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 61 | 0 | my @pairs = ($controllers->[0], $number_coarse, $controllers->[1], $number_fine, 6, $coarse); | |||||||||||||||||||||
| 62 | 0 | ▶ | push @pairs, 38, $fine if defined $fine; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 63 | 0 | push @pairs, 101, 127, 100, 127; | |||||||||||||||||||||
| 64 | 0 | return $self->cc($channel, @pairs); | |||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||
| 66 | |||||||||||||||||||||||
| 67 | 0 | ▶ | sub nrpn ($self, $channel, $number, $value) { return $self->rpn($channel, $number, $value, [ 99, 98 ]) } | ||||||||||||||||||||
|
Subroutine
nrpn: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 68 | |||||||||||||||||||||||
| 69 | # All notes off (controller 123), on a channel or on all. | ||||||||||||||||||||||
| 70 | 0 | ▶ | sub panic ($self, $channel = undef) { | ||||||||||||||||||||
|
Subroutine
panic: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||
| 71 | 0 | ▶ | $self->cc($_, 123, 0) for defined $channel ? $channel : 0 .. 15; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 72 | 0 | return; | |||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||
| 74 | |||||||||||||||||||||||
| 75 | # A note off for every key, on a channel or on all. | ||||||||||||||||||||||
| 76 | 0 | ▶ | sub PANIC ($self, $channel = undef) { | ||||||||||||||||||||
|
Subroutine
PANIC: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||
| 77 | 0 | ▶ | for my $ch (defined $channel ? $channel : 0 .. 15) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 78 | 0 | $self->note_off($ch, $_, 0) for 0 .. 127; | |||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||
| 80 | 0 | return; | |||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||
| 82 | |||||||||||||||||||||||
| 83 | 1 | 1; | |||||||||||||||||||||
| 84 | |||||||||||||||||||||||
| 85 | __END__ | ||||||||||||||||||||||