line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#! perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Data::iRealPro::Input -- parse iRealPro data |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# Author : Johan Vromans |
6
|
|
|
|
|
|
|
# Created On : Tue Sep 6 16:09:10 2016 |
7
|
|
|
|
|
|
|
# Last Modified By: Johan Vromans |
8
|
|
|
|
|
|
|
# Last Modified On: Wed Nov 14 21:35:40 2018 |
9
|
|
|
|
|
|
|
# Update Count : 82 |
10
|
|
|
|
|
|
|
# Status : Unknown, Use with caution! |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
################ Common stuff ################ |
13
|
|
|
|
|
|
|
|
14
|
11
|
|
|
11
|
|
584059
|
use strict; |
|
11
|
|
|
|
|
108
|
|
|
11
|
|
|
|
|
319
|
|
15
|
11
|
|
|
11
|
|
60
|
use warnings; |
|
11
|
|
|
|
|
23
|
|
|
11
|
|
|
|
|
262
|
|
16
|
11
|
|
|
11
|
|
56
|
use Carp; |
|
11
|
|
|
|
|
21
|
|
|
11
|
|
|
|
|
667
|
|
17
|
11
|
|
|
11
|
|
5117
|
use utf8; |
|
11
|
|
|
|
|
139
|
|
|
11
|
|
|
|
|
61
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
package Data::iRealPro::Input; |
20
|
|
|
|
|
|
|
|
21
|
11
|
|
|
11
|
|
4049
|
use Data::iRealPro::URI; |
|
11
|
|
|
|
|
31
|
|
|
11
|
|
|
|
|
377
|
|
22
|
11
|
|
|
11
|
|
4525
|
use Data::iRealPro::Input::Text; |
|
11
|
|
|
|
|
27
|
|
|
11
|
|
|
|
|
365
|
|
23
|
11
|
|
|
11
|
|
76
|
use Encode qw ( decode_utf8 ); |
|
11
|
|
|
|
|
22
|
|
|
11
|
|
|
|
|
532
|
|
24
|
11
|
|
|
11
|
|
67
|
use File::Basename (); |
|
11
|
|
|
|
|
22
|
|
|
11
|
|
|
|
|
10022
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub new { |
27
|
9
|
|
|
9
|
0
|
1183
|
my ( $pkg, $options ) = @_; |
28
|
|
|
|
|
|
|
|
29
|
9
|
|
|
|
|
41
|
my $self = bless( { variant => "irealpro" }, $pkg ); |
30
|
|
|
|
|
|
|
|
31
|
9
|
|
|
|
|
42
|
for ( qw( trace debug verbose output variant transpose |
32
|
|
|
|
|
|
|
neatify select suppress-upbeat suppress-text |
33
|
|
|
|
|
|
|
musescore override-alt condense ) ) { |
34
|
117
|
100
|
|
|
|
276
|
$self->{$_} = $options->{$_} if exists $options->{$_}; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
9
|
|
|
|
|
29
|
for ( qw( playlist catalog ) ) { |
38
|
18
|
50
|
|
|
|
53
|
$self->{$_} = decode_utf8($options->{$_}) if exists $options->{$_}; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
9
|
|
|
|
|
31
|
return $self; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub parsefile { |
45
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $file ) = @_; |
46
|
|
|
|
|
|
|
|
47
|
0
|
0
|
|
|
|
0
|
open( my $fd, '<:utf8', $file ) or die("$file: $!\n"); |
48
|
0
|
|
|
|
|
0
|
my $data = do { local $/; <$fd> }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
49
|
0
|
|
|
|
|
0
|
my $u = $self->parsedata($data); |
50
|
0
|
0
|
|
|
|
0
|
$u->{playlist}->{name} = $self->{playlist} if $self->{playlist}; |
51
|
0
|
|
|
|
|
0
|
return $u; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub parsefiles { |
55
|
0
|
|
|
0
|
0
|
0
|
my ( $self, @files ) = @_; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
0
|
my $all; |
58
|
0
|
|
|
|
|
0
|
my $plname = $self->{playlist}; |
59
|
0
|
|
|
|
|
0
|
foreach my $file ( @files ) { |
60
|
0
|
0
|
|
|
|
0
|
warn("Parsing: $file...\n") if $self->{verbose}; |
61
|
0
|
|
|
|
|
0
|
my $u = $self->parsefile($file); |
62
|
0
|
0
|
|
|
|
0
|
unless ( $all ) { |
63
|
0
|
|
|
|
|
0
|
$all = $u; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
else { |
66
|
0
|
|
|
|
|
0
|
$all->{playlist}->add_songs( $u->{playlist}->songs ); |
67
|
|
|
|
|
|
|
} |
68
|
0
|
0
|
|
|
|
0
|
unless ( $plname ) { |
69
|
0
|
|
|
|
|
0
|
$plname = $all->{playlist}->{name}; |
70
|
0
|
0
|
|
|
|
0
|
$plname = "" if $plname eq ""; |
71
|
|
|
|
|
|
|
} |
72
|
0
|
0
|
|
|
|
0
|
unless ( $plname ) { |
73
|
0
|
|
|
|
|
0
|
my @p = File::Basename::fileparse( $file, qr/\.[^.]*/ ); |
74
|
0
|
|
|
|
|
0
|
$plname = $p[0]; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
0
|
$all->{playlist}->{name} = $plname if $plname; |
79
|
0
|
|
|
|
|
0
|
$self->apply_selection($all); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub parsedata { |
83
|
12
|
|
|
12
|
0
|
13195
|
my ( $self, $data ) = @_; |
84
|
|
|
|
|
|
|
|
85
|
12
|
|
|
|
|
24
|
my $all; |
86
|
12
|
100
|
|
|
|
28
|
if ( eval { $data->[0] } ) { |
|
12
|
|
|
|
|
128
|
|
87
|
1
|
|
|
|
|
3
|
foreach my $d ( @$data ) { |
88
|
2
|
|
|
|
|
7
|
my $u = $self->parsedata($d); |
89
|
2
|
100
|
|
|
|
5
|
if ( $all ) { |
90
|
1
|
|
|
|
|
4
|
$all->{playlist}->add_songs( $u->{playlist}->songs ); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
else { |
93
|
1
|
|
|
|
|
1
|
$all = $u; |
94
|
1
|
|
50
|
|
|
7
|
$all->{playlist}->{name} ||= "NoName"; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
1
|
50
|
|
|
|
5
|
$all->{playlist}->{name} = $self->{playlist} if $self->{playlist}; |
98
|
1
|
|
|
|
|
4
|
$self->apply_selection($all); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
else { |
102
|
11
|
100
|
|
|
|
87
|
if ( $data =~ /^Song( \d+)?:/ ) { |
|
|
50
|
|
|
|
|
|
103
|
9
|
|
|
|
|
52
|
$all = Data::iRealPro::Input::Text::encode( $self, $data ); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
elsif ( $data =~ /^(?:<\?xml.*?>\s*)?
|
106
|
0
|
|
|
|
|
0
|
require Data::iRealPro::Input::MusicXML; |
107
|
0
|
|
|
|
|
0
|
$all = Data::iRealPro::Input::MusicXML::encode( $self, $data ); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
else { |
110
|
|
|
|
|
|
|
# Extract URL. |
111
|
2
|
|
|
|
|
66
|
$data =~ s;^.*?(irealb(?:ook)?://.*?)(?:$|\").*;$1;s; |
112
|
2
|
50
|
|
|
|
12
|
$data = "irealbook://" . $data |
113
|
|
|
|
|
|
|
unless $data =~ m;^(irealb(?:ook)?://.*?);; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
$all = Data::iRealPro::URI->new( data => $data, |
116
|
|
|
|
|
|
|
debug => $self->{debug}, |
117
|
|
|
|
|
|
|
transpose => $self->{transpose}, |
118
|
2
|
|
|
|
|
20
|
); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
12
|
50
|
|
|
|
46
|
$all->{playlist}->{name} = $self->{playlist} if $self->{playlist}; |
123
|
12
|
|
|
|
|
46
|
return $all; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# Since input can be collected from different sources in spearate calls, |
127
|
|
|
|
|
|
|
# we need to apply a selection manually. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub apply_selection { |
130
|
1
|
|
|
1
|
0
|
3
|
my ( $self, $u ) = @_; |
131
|
|
|
|
|
|
|
|
132
|
1
|
|
|
|
|
2
|
my $i = $self->{select}; |
133
|
1
|
50
|
|
|
|
3
|
return $u unless $i; |
134
|
|
|
|
|
|
|
|
135
|
0
|
0
|
0
|
|
|
|
if ( $i > 0 && $i <= @{ $u->{playlist}->songs } ) { |
|
0
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
$u->{playlist}->{songs} = |
137
|
0
|
|
|
|
|
|
[ $u->{playlist}->songs->[$i-1] ]; |
138
|
0
|
|
|
|
|
|
$u->{playlist}->{songs}->[0]->{songindex} = $i; |
139
|
0
|
|
|
|
|
|
$u->{playlist}->{name} = ""; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
else { |
142
|
0
|
|
|
|
|
|
Carp::croak("Invalid value in select"); |
143
|
|
|
|
|
|
|
} |
144
|
0
|
|
|
|
|
|
return $u; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
1; |