| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#! perl |
|
2
|
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
67860
|
use strict; |
|
|
5
|
|
|
|
|
11
|
|
|
|
5
|
|
|
|
|
162
|
|
|
4
|
5
|
|
|
5
|
|
25
|
use warnings; |
|
|
5
|
|
|
|
|
10
|
|
|
|
5
|
|
|
|
|
183
|
|
|
5
|
5
|
|
|
5
|
|
24
|
use utf8; |
|
|
5
|
|
|
|
|
14
|
|
|
|
5
|
|
|
|
|
31
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package Music::ChordBot::Opus; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Music::ChordBot::Opus - API for generating ChordBot songs. |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=cut |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = 0.01; |
|
16
|
|
|
|
|
|
|
|
|
17
|
5
|
|
|
5
|
|
4347
|
use parent 'Music::ChordBot::Opus::Base'; |
|
|
5
|
|
|
|
|
1720
|
|
|
|
5
|
|
|
|
|
28
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use Music::ChordBot::Opus; |
|
22
|
|
|
|
|
|
|
my $song = Music::ChordBot::Opus->new; |
|
23
|
|
|
|
|
|
|
$song->name("Perl Song"); |
|
24
|
|
|
|
|
|
|
$song->tempo(120); |
|
25
|
|
|
|
|
|
|
$song->add_section(...); |
|
26
|
|
|
|
|
|
|
print $song->json, "\n"; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 METHODS |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head2 new [ args ] |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Creates a new Music::ChordBot::Opus object. |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Initial attributes may be passed as a hash. |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Attributes: |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=over 4 |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=item name |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
The name of the song. |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=item editMode |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Zero if the song has a single style, one if some sections have their |
|
47
|
|
|
|
|
|
|
own styles. |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=item tempo |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
The tempo in beats per minute. |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=item fileType |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
This must be the literal string 'chordbot-song'. |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=back |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=cut |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub new { |
|
62
|
5
|
|
|
5
|
1
|
38
|
my ( $pkg, %init ) = @_; |
|
63
|
5
|
100
|
|
|
|
34
|
$init{songName} = delete $init{name} if exists $init{name}; |
|
64
|
5
|
|
|
|
|
39
|
my $data = { fileType => "chordbot-song", |
|
65
|
|
|
|
|
|
|
editMode => 0, |
|
66
|
|
|
|
|
|
|
tempo => 80, |
|
67
|
|
|
|
|
|
|
sections => [], |
|
68
|
|
|
|
|
|
|
%init }; |
|
69
|
5
|
|
|
|
|
34
|
bless { data => $data }, $pkg; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 name [ value ] |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Sets or gets the name of the song. |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
|
77
|
|
|
|
|
|
|
|
|
78
|
2
|
|
|
2
|
1
|
14
|
sub name { shift->_setget( "songName", @_ ) } |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 tempo [ value ] |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Sets or gets the tempo of the song. |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
|
85
|
|
|
|
|
|
|
|
|
86
|
3
|
|
|
3
|
1
|
31
|
sub tempo { shift->_setget( "tempo", @_ ) } |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 editmode [ value ] |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Sets or gets attribute editMode. This is not normally necessary since |
|
91
|
|
|
|
|
|
|
it is dealt with automatically. |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
|
94
|
|
|
|
|
|
|
|
|
95
|
2
|
|
|
2
|
1
|
7
|
sub editmode { shift->_setget( "editMode", @_ ) } |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 add_section section |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Adds a new section to the song. See L |
|
100
|
|
|
|
|
|
|
for details on sections. |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub add_section { |
|
105
|
6
|
|
|
6
|
1
|
12
|
my ( $self, $section ) = @_; |
|
106
|
6
|
|
|
|
|
10
|
push( @{$self->{data}->{sections}}, $section->{data} ); |
|
|
6
|
|
|
|
|
51
|
|
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# head2 _wrapup |
|
110
|
|
|
|
|
|
|
# |
|
111
|
|
|
|
|
|
|
# Internal helper to fix some attributes. |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub _wrapup { |
|
114
|
8
|
|
|
8
|
|
15
|
my ( $self ) = @_; |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# If there are more than one sections with a style associated, |
|
117
|
|
|
|
|
|
|
# editMode most be set to 1. |
|
118
|
8
|
|
|
|
|
13
|
my $styles = 0; |
|
119
|
8
|
|
|
|
|
12
|
foreach ( @{ $self->{data}->{sections} } ) { |
|
|
8
|
|
|
|
|
33
|
|
|
120
|
10
|
50
|
|
|
|
47
|
if ( exists $_->{style} ) { |
|
121
|
10
|
100
|
|
|
|
52
|
if ( ++$styles > 1 ) { |
|
122
|
2
|
|
|
|
|
7
|
$self->editmode(1); |
|
123
|
2
|
|
|
|
|
6
|
last; |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 export [ dumpname ] |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Produces a string representing the song, in Data::Dumper format. |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub export { |
|
136
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $pretty ) = @_; |
|
137
|
0
|
|
|
|
|
0
|
$self->_wrapup; |
|
138
|
5
|
|
|
5
|
|
9158
|
use Data::Dumper (); |
|
|
5
|
|
|
|
|
69914
|
|
|
|
5
|
|
|
|
|
531
|
|
|
139
|
0
|
|
0
|
|
|
0
|
Data::Dumper->Dump( [ $self->{data} ], [ $pretty || "opus" ] ); |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head2 json [ pretty ] |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Produces a string representing the song, in JSON format, suitable |
|
145
|
|
|
|
|
|
|
for import into the ChordBot app. |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
If argument is true, the JSON is pretty-printed for readability. |
|
148
|
|
|
|
|
|
|
ChordBot doesn't mind. |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub json { |
|
153
|
8
|
|
|
8
|
1
|
20
|
my ( $self, $pretty ) = @_; |
|
154
|
8
|
|
|
|
|
32
|
$self->_wrapup; |
|
155
|
5
|
|
|
5
|
|
5880
|
use JSON (); |
|
|
5
|
|
|
|
|
103961
|
|
|
|
5
|
|
|
|
|
691
|
|
|
156
|
8
|
|
|
|
|
61
|
my $json = JSON->new; |
|
157
|
8
|
|
|
|
|
56
|
$json->canonical(1); |
|
158
|
8
|
50
|
|
|
|
31
|
$json = $json->pretty if $pretty; |
|
159
|
8
|
|
|
|
|
1032
|
$json->encode($self->{data}); |
|
160
|
|
|
|
|
|
|
} |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
1; |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
L for general information. |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
L for an easy to use API. |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 DISCLAIMER |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
There is currently NO VALIDATION of argument values. Illegal values |
|
173
|
|
|
|
|
|
|
will result in program crashes and songs that cannot be imported, or |
|
174
|
|
|
|
|
|
|
played, by ChordBot. |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 AUTHOR, COPYRIGHT & LICENSE |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
See L. |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=cut |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
1; |