| 1 | #! perl | ||||||||||
| 2 | |||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 6 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 6 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | package Music::ChordBot::Opus::Section::Style; | ||||||||||
| 8 | |||||||||||
| 9 | =head1 NAME | ||||||||||
| 10 | |||||||||||
| 11 | Music::ChordBot::Opus::Section::Style- ChordBot styles. | ||||||||||
| 12 | |||||||||||
| 13 | =cut | ||||||||||
| 14 | |||||||||||
| 15 | 6 | our $VERSION = 0.01; | |||||||||
| 16 | |||||||||||
| 17 | 6 | ▶ | use parent 'Music::ChordBot::Opus::Base'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | |||||||||||
| 19 | =head1 SYNOPSIS | ||||||||||
| 20 | |||||||||||
| 21 | use Music::ChordBot::Opus::Section::Style; | ||||||||||
| 22 | $style = Music::ChordBot::Section::Style->new; | ||||||||||
| 23 | $style->preset("Hammered"); | ||||||||||
| 24 | |||||||||||
| 25 | =cut | ||||||||||
| 26 | |||||||||||
| 27 | 6 | ▶ | use Music::ChordBot::Opus::Section::Style::Track; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | |||||||||||
| 29 | =head1 METHODS | ||||||||||
| 30 | |||||||||||
| 31 | =head2 new [ I<args> ] | ||||||||||
| 32 | |||||||||||
| 33 | Creates a new Music::ChordBot::Opus::Section::Style object. | ||||||||||
| 34 | |||||||||||
| 35 | Initial attributes can be passed to the constructor as a hash. | ||||||||||
| 36 | |||||||||||
| 37 | Attributes: | ||||||||||
| 38 | |||||||||||
| 39 | =over 4 | ||||||||||
| 40 | |||||||||||
| 41 | =item reverb | ||||||||||
| 42 | |||||||||||
| 43 | The level of reverb effect. | ||||||||||
| 44 | |||||||||||
| 45 | =item chorus | ||||||||||
| 46 | |||||||||||
| 47 | The level of chorus effect. | ||||||||||
| 48 | |||||||||||
| 49 | =item tracks | ||||||||||
| 50 | |||||||||||
| 51 | A list (array ref) of Track objects. See | ||||||||||
| 52 | L<Music::ChordBot::Opus::Section::Style::Track> for details about | ||||||||||
| 53 | tracks. | ||||||||||
| 54 | |||||||||||
| 55 | =item beats | ||||||||||
| 56 | |||||||||||
| 57 | The number of beats per measure. | ||||||||||
| 58 | |||||||||||
| 59 | =item divider | ||||||||||
| 60 | |||||||||||
| 61 | The divider for the measure. | ||||||||||
| 62 | |||||||||||
| 63 | =back | ||||||||||
| 64 | |||||||||||
| 65 | Default is 4/4. | ||||||||||
| 66 | |||||||||||
| 67 | =cut | ||||||||||
| 68 | |||||||||||
| 69 | 335 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 70 | 335 | my $pkg = shift; | |||||||||
| 71 | 335 | my $data = { chorus => 4, reverb => 8, tracks => [], @_ }; | |||||||||
| 72 | 335 | bless { data => $data }, $pkg; | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | =head2 chorus reverb beats divider tracks | ||||||||||
| 76 | |||||||||||
| 77 | Accessors can be used to set and/or get these attributes. | ||||||||||
| 78 | |||||||||||
| 79 | =cut | ||||||||||
| 80 | |||||||||||
| 81 | 333 | ▶ | sub chorus { shift->_setget( "chorus", @_ ) } | ||||||||
|
Subroutine
chorus: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 82 | 333 | ▶ | sub reverb { shift->_setget( "reverb", @_ ) } | ||||||||
|
Subroutine
reverb: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 83 | 171 | ▶ | sub legacy { shift->_setget( "legacy", @_ ) } | ||||||||
|
Subroutine
legacy: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 84 | 16 | ▶ | sub beats { shift->_setget( "beats", @_ ) } | ||||||||
|
Subroutine
beats: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 85 | 16 | ▶ | sub divider { shift->_setget( "divider", @_ ) } | ||||||||
|
Subroutine
divider: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 86 | |||||||||||
| 87 | =head2 add_track I<track> | ||||||||||
| 88 | |||||||||||
| 89 | Adds a track object to the style. | ||||||||||
| 90 | |||||||||||
| 91 | =cut | ||||||||||
| 92 | |||||||||||
| 93 | 745 | ▶ | sub add_track { | ||||||||
|
Subroutine
add_track: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 94 | 745 | my ( $self, $track ) = @_; | |||||||||
| 95 | 745 | push( @{$self->{data}->{tracks}}, $track->data ); | |||||||||
| 96 | } | ||||||||||
| 97 | |||||||||||
| 98 | =head2 preset I<name> | ||||||||||
| 99 | |||||||||||
| 100 | Sets the style to one of the built-in preset values. For a list of | ||||||||||
| 101 | preset values and their descriptions, see | ||||||||||
| 102 | L<http://chordbot.com/style-lookup.php>. | ||||||||||
| 103 | |||||||||||
| 104 | =cut | ||||||||||
| 105 | |||||||||||
| 106 | 6 | my %presets; | |||||||||
| 107 | 6 | ▶ | sub preset { | ||||||||
|
Subroutine
preset: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||
| 108 | 6 | ▶ | return $presets{$_[1]} if %presets; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 109 | |||||||||||
| 110 | 6 | ▶ | use JSON (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 111 | 5 | my $json = JSON->new; | |||||||||
| 112 | 5 | ▶ | while ( <DATA> ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 113 | 330 | my $data = $json->decode($_); | |||||||||
| 114 | 330 | my $preset = __PACKAGE__->new; | |||||||||
| 115 | 330 | ▶ | $preset->chorus( $data->{chorus} ) if exists $data->{chorus}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 116 | 330 | ▶ | $preset->reverb( $data->{reverb} ) if exists $data->{reverb}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 117 | 330 | ▶ | $preset->legacy( $data->{legacy} ) if exists $data->{legacy}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 118 | 330 | ▶ | $preset->beats( $data->{beats} ) if exists $data->{beats}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 119 | 330 | ▶ | $preset->divider($data->{divider}) if exists $data->{divider}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 120 | |||||||||||
| 121 | 330 | my $tracks = $data->{tracks}; | |||||||||
| 122 | 330 | foreach my $t ( @$tracks ) { | |||||||||
| 123 | 740 | $preset->add_track | |||||||||
| 124 | ( Music::ChordBot::Opus::Section::Style::Track->new | ||||||||||
| 125 | ( id => $t->[0], volume => $t->[1] ) ) | ||||||||||
| 126 | } | ||||||||||
| 127 | 330 | $presets{ $data->{name} } = $preset; | |||||||||
| 128 | } | ||||||||||
| 129 | |||||||||||
| 130 | 5 | $presets{$_[1]} | |||||||||
| 131 | } | ||||||||||
| 132 | |||||||||||
| 133 | =head1 AUTHOR, COPYRIGHT & LICENSE | ||||||||||
| 134 | |||||||||||
| 135 | See L<Music::ChordBot>. | ||||||||||
| 136 | |||||||||||
| 137 | =cut | ||||||||||
| 138 | |||||||||||
| 139 | 6 | 1; | |||||||||
| 140 | |||||||||||
| 141 | __DATA__ | ||||||||||