line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Async::OSC; |
2
|
1
|
|
|
1
|
|
752
|
use 5.020; |
|
1
|
|
|
|
|
4
|
|
3
|
1
|
|
|
1
|
|
601
|
use Moo 2; |
|
1
|
|
|
|
|
12359
|
|
|
1
|
|
|
|
|
6
|
|
4
|
1
|
|
|
1
|
|
1560
|
use feature 'signatures'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
128
|
|
5
|
1
|
|
|
1
|
|
8
|
no warnings 'experimental::signatures'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
6
|
1
|
|
|
1
|
|
6
|
use Carp 'croak'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
58
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Net::Async::OSC - send/receive OSC asynchronously |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $loop = IO::Async::Loop->new(); |
17
|
|
|
|
|
|
|
my $osc = Net::Async::OSC->new( |
18
|
|
|
|
|
|
|
loop => $loop, |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
$osc->connect('127.0.0.1', 4560)->get; |
22
|
|
|
|
|
|
|
$osc->send_osc( |
23
|
|
|
|
|
|
|
"/trigger/melody" => 'ii', |
24
|
|
|
|
|
|
|
1,0); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
1
|
|
570
|
use Protocol::OSC; |
|
1
|
|
|
|
|
1849
|
|
|
1
|
|
|
|
|
31
|
|
29
|
1
|
|
|
1
|
|
908
|
use IO::Async::Loop; |
|
1
|
|
|
|
|
29509
|
|
|
1
|
|
|
|
|
35
|
|
30
|
1
|
|
|
1
|
|
534
|
use IO::Async::Socket; |
|
1
|
|
|
|
|
32320
|
|
|
1
|
|
|
|
|
39
|
|
31
|
1
|
|
|
1
|
|
7
|
use Socket 'pack_sockaddr_in', 'inet_aton'; # IPv6 support?! |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
456
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has 'osc' => ( |
34
|
|
|
|
|
|
|
is => 'lazy', |
35
|
|
|
|
|
|
|
default => sub { return Protocol::OSC->new }, |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
has 'loop' => ( |
39
|
|
|
|
|
|
|
is => 'lazy', |
40
|
|
|
|
|
|
|
default => sub { return IO::Async::Loop->new }, |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
has 'socket' => ( |
44
|
|
|
|
|
|
|
is => 'rw', |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 METHODS |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 C<< ->connect >> |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$osc->connect('127.0.0.1', 4560)->get; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Connect to host/port. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
0
|
1
|
|
sub connect( $self, $host, $port ) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my $loop = $self->loop; |
59
|
0
|
|
|
|
|
|
my $pingback = IO::Async::Socket->new( |
60
|
0
|
|
|
0
|
|
|
on_recv => sub( $sock, $data, $addr, @rest ) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
warn "Reply: $data"; |
62
|
|
|
|
|
|
|
}, |
63
|
0
|
|
|
|
|
|
); |
64
|
0
|
|
|
|
|
|
$loop->add( $pingback ); |
65
|
|
|
|
|
|
|
# What about multihomed hosts?! |
66
|
0
|
|
|
|
|
|
return $pingback->connect( |
67
|
|
|
|
|
|
|
host => $host, |
68
|
|
|
|
|
|
|
service => $port, |
69
|
|
|
|
|
|
|
socktype => 'dgram' |
70
|
0
|
|
|
0
|
|
|
)->on_done(sub($socket) { |
|
0
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
$self->socket($socket) |
72
|
0
|
|
|
|
|
|
}); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head2 C<< ->send_osc >> |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$osc->send_osc( |
78
|
|
|
|
|
|
|
"/trigger/melody" => 'ii', |
79
|
|
|
|
|
|
|
1,0); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Sends an OSC message as a list. The list will be packed according to |
82
|
|
|
|
|
|
|
L. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
0
|
1
|
|
sub send_osc( $self, @message ) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
my $osc = $self->osc; |
88
|
0
|
|
|
|
|
|
my $socket = $self->socket; |
89
|
0
|
|
|
|
|
|
my $data = $osc->message(@message); # pack |
90
|
0
|
|
|
|
|
|
$self->send_osc_msg( $data ); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 C<< ->send_osc_msg >> |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $msg = $protocol->message( |
96
|
|
|
|
|
|
|
"/trigger/melody" => 'ii', |
97
|
|
|
|
|
|
|
1,0 |
98
|
|
|
|
|
|
|
); |
99
|
|
|
|
|
|
|
$osc->send_osc_msg($msg); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Sends an pre-packed OSC message. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
0
|
1
|
|
sub send_osc_msg( $self, $data ) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
#say join " , " , @{ $osc->parse( $data ) }; |
107
|
0
|
|
|
|
|
|
$self->socket->send( $data ); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 SEE ALSO |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
L |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |