| 1 | #! perl | ||||||||||
| 2 | |||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | package Music::ChordBot::Opus::Section; | ||||||||||
| 7 | |||||||||||
| 8 | =head1 NAME | ||||||||||
| 9 | |||||||||||
| 10 | Music::ChordBot::Opus::Section - ChordBot song section. | ||||||||||
| 11 | |||||||||||
| 12 | =cut | ||||||||||
| 13 | |||||||||||
| 14 | 5 | our $VERSION = 0.01; | |||||||||
| 15 | |||||||||||
| 16 | 5 | ▶ | use parent 'Music::ChordBot::Opus::Base'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | 5 | ▶ | use Music::ChordBot::Opus::Section::Chord; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 5 | ▶ | use Music::ChordBot::Opus::Section::Style; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | |||||||||||
| 21 | =head1 SYNOPSIS | ||||||||||
| 22 | |||||||||||
| 23 | use Music::ChordBot::Opus::Section; | ||||||||||
| 24 | my $sect = Music::ChordBot::Opus::Section->new; | ||||||||||
| 25 | $sect->name("First movement"); | ||||||||||
| 26 | $sect->set_style("Kubiac"); | ||||||||||
| 27 | $sect->add_chord(...); | ||||||||||
| 28 | $sect->add_chord(...); | ||||||||||
| 29 | |||||||||||
| 30 | =cut | ||||||||||
| 31 | |||||||||||
| 32 | #### TODO: Repeat sections. | ||||||||||
| 33 | # | ||||||||||
| 34 | # A repeat section has a name, optionally a style, and no chords. The | ||||||||||
| 35 | # field 'repeat' contains the index of the original section that is to | ||||||||||
| 36 | # be repeated. This can be tricky when inserting/deleting sections. | ||||||||||
| 37 | |||||||||||
| 38 | =head1 METHODS | ||||||||||
| 39 | |||||||||||
| 40 | =head2 new [ args ] | ||||||||||
| 41 | |||||||||||
| 42 | Creates a new Music::ChordBot::Opus::Section object. | ||||||||||
| 43 | |||||||||||
| 44 | Initial attributes may be passed as a hash. | ||||||||||
| 45 | |||||||||||
| 46 | Attributes: | ||||||||||
| 47 | |||||||||||
| 48 | =over 4 | ||||||||||
| 49 | |||||||||||
| 50 | =item name | ||||||||||
| 51 | |||||||||||
| 52 | The name of the section. | ||||||||||
| 53 | |||||||||||
| 54 | =item chords | ||||||||||
| 55 | |||||||||||
| 56 | An arrayref containing Music::ChordBot::Opus::Section::Chord objects, | ||||||||||
| 57 | more commonly known as 'chords', | ||||||||||
| 58 | |||||||||||
| 59 | =item style | ||||||||||
| 60 | |||||||||||
| 61 | A hashref representing the attributes of a style. See | ||||||||||
| 62 | L<Music::ChordBot::Opus::Section::Style>. | ||||||||||
| 63 | |||||||||||
| 64 | =cut | ||||||||||
| 65 | |||||||||||
| 66 | 6 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 67 | 6 | my $pkg = shift; | |||||||||
| 68 | 6 | my $data = { name => "Section 1", | |||||||||
| 69 | chords => [], | ||||||||||
| 70 | style => { chorus => 4, reverb => 8, | ||||||||||
| 71 | tracks => [ { volume => 7, id => 95 } ] }, | ||||||||||
| 72 | @_ }; | ||||||||||
| 73 | 6 | bless { data => $data }, $pkg; | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | =head2 name [ I<value> ] | ||||||||||
| 77 | |||||||||||
| 78 | Sets or gets the name of the section. | ||||||||||
| 79 | |||||||||||
| 80 | =cut | ||||||||||
| 81 | |||||||||||
| 82 | 2 | ▶ | sub name { shift->_setget( "name", @_ ) } | ||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 83 | |||||||||||
| 84 | =head2 add_chord I<chord> | ||||||||||
| 85 | |||||||||||
| 86 | Adds a chord to the section. | ||||||||||
| 87 | |||||||||||
| 88 | I<chord> must be a Music::ChordBot::Opus::Section::Chord object, or a | ||||||||||
| 89 | string denoting a chord, e.g. "C Maj 4". For convenience, the three | ||||||||||
| 90 | elements may also be passed separately, e.g., C<add_chord("C", "Maj", | ||||||||||
| 91 | 4)>. | ||||||||||
| 92 | |||||||||||
| 93 | A bass note can be specified by adding the note to the key, separated | ||||||||||
| 94 | by a slash, e.g., C<"C/B">. | ||||||||||
| 95 | |||||||||||
| 96 | =cut | ||||||||||
| 97 | |||||||||||
| 98 | 52 | ▶ | sub add_chord { | ||||||||
|
Subroutine
add_chord: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 99 | 52 | my ( $self, $chord ) = @_; | |||||||||
| 100 | 52 | my $ok = 0; | |||||||||
| 101 | 52 | eval { push( @{$self->{data}->{chords}}, $chord->{data} ); $ok = 1 }; | |||||||||
| 102 | 52 | ▶ | return if $ok; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 103 | 48 | shift; | |||||||||
| 104 | 48 | push( @{$self->{data}->{chords}}, | |||||||||
| 105 | Music::ChordBot::Opus::Section::Chord->new(@_)->data ); | ||||||||||
| 106 | } | ||||||||||
| 107 | |||||||||||
| 108 | 0 | ▶ | sub chords { | ||||||||
|
Subroutine
chords: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 109 | wantarray | ||||||||||
| 110 | 0 | ? @{ $_[0]->{data}->{chords} } | |||||||||
| 111 | 0 | ▶ | : $_[0]->{data}->{chords}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 112 | } | ||||||||||
| 113 | |||||||||||
| 114 | =head2 no_style | ||||||||||
| 115 | |||||||||||
| 116 | A newly created Music::ChordBot::Opus::Section object has a default | ||||||||||
| 117 | style associated. Calling this method removes the style from the | ||||||||||
| 118 | section. | ||||||||||
| 119 | |||||||||||
| 120 | =cut | ||||||||||
| 121 | |||||||||||
| 122 | 0 | ▶ | sub no_style { | ||||||||
|
Subroutine
no_style: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 123 | 0 | delete $_[0]->{data}->{style}; | |||||||||
| 124 | } | ||||||||||
| 125 | |||||||||||
| 126 | =head2 set_style [ I<style> ] | ||||||||||
| 127 | |||||||||||
| 128 | Sets the style for the section. | ||||||||||
| 129 | |||||||||||
| 130 | I<style> must be a Music::ChordBot::Opus::Section::Style object, or the | ||||||||||
| 131 | name of a predefined (preset) style. | ||||||||||
| 132 | |||||||||||
| 133 | If I<style> is omitted, the current style is removed from the section. | ||||||||||
| 134 | |||||||||||
| 135 | =cut | ||||||||||
| 136 | |||||||||||
| 137 | 6 | ▶ | sub set_style { | ||||||||
|
Subroutine
set_style: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 138 | 6 | my ( $self, $style ) = @_; | |||||||||
| 139 | 6 | ▶ | $self->no_style, return unless defined $style; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 140 | 6 | my $ok = 0; | |||||||||
| 141 | 6 | eval { $self->{data}->{style} = $style->{data}; $ok = 1 }; | |||||||||
| 142 | 6 | ▶ | return if $ok; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 143 | $self->{data}->{style} = | ||||||||||
| 144 | 5 | Music::ChordBot::Opus::Section::Style->preset($style)->data; | |||||||||
| 145 | } | ||||||||||
| 146 | |||||||||||
| 147 | =head1 AUTHOR, COPYRIGHT & LICENSE | ||||||||||
| 148 | |||||||||||
| 149 | See L<Music::ChordBot>. | ||||||||||
| 150 | |||||||||||
| 151 | =cut | ||||||||||
| 152 | |||||||||||
| 153 | 5 | 1; | |||||||||