Changeset 26114
- Timestamp:
- 12/08/08 16:34:57 (4 years ago)
- Location:
- lang/perl/Music-Chord-Note/trunk
- Files:
-
- 4 modified
-
Changes (modified) (1 diff)
-
META.yml (modified) (2 diffs)
-
lib/Music/Chord/Note.pm (modified) (4 diffs)
-
t/01.rehearsal.t (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Music-Chord-Note/trunk/Changes
r25526 r26114 1 1 Revision history for Music-Chord-Note 2 2 3 0.0.3 mon Dec 08 16:16:16 2008 4 add scale func & test 5 3 6 0.0.2 mon Dec 01 12:12:12 2008 4 7 fixed chord list. -
lang/perl/Music-Chord-Note/trunk/META.yml
r25526 r26114 1 1 --- 2 2 name: Music-Chord-Note 3 version: 0.0. 23 version: 0.0.3 4 4 author: 5 5 - 'Dai Okabayashi <bayashi@cpan.org>' … … 14 14 Music::Chord::Note: 15 15 file: lib/Music/Chord/Note.pm 16 version: 0.0. 216 version: 0.0.3 17 17 generated_by: Module::Build version 0.3 18 18 meta-spec: -
lang/perl/Music-Chord-Note/trunk/lib/Music/Chord/Note.pm
r25526 r26114 5 5 use Carp qw( croak ); 6 6 7 our $VERSION = '0.0. 2';7 our $VERSION = '0.0.3'; 8 8 9 9 my @tone_list = ('C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B', … … 79 79 }; 80 80 81 sub new { 81 sub new 82 { 82 83 my $class = shift; 83 84 bless {}, $class; 84 85 } 85 86 86 sub chord { 87 sub chord 88 { 87 89 my ($self, $chord_name) = @_; 90 88 91 croak "No CHORD_NAME!" unless $chord_name; 89 92 my ($tonic, $kind) = ($chord_name =~ /([A-G][b#]?)(.+)?/); 90 croak ("unknown chord $chord_name")unless defined $tonic;93 croak "unknown chord $chord_name" unless defined $tonic; 91 94 $kind = 'base' unless $kind; 92 95 my $scalic = $scalic_value->{$tonic}; 93 croak("undefined kind of chord $kind($chord_name)") unless defined $base_chord_list->{$kind}; 96 croak "undefined kind of chord $kind($chord_name)" 97 unless defined $base_chord_list->{$kind}; 98 94 99 my @keys; 95 for my $scale ( split (/\,/, $base_chord_list->{$kind})){100 for my $scale ( split /\,/, $base_chord_list->{$kind} ){ 96 101 my $note = $scale + $scalic; 97 102 $note = int($note % 24) + 12 if $note > 23; 98 push (@keys, $tone_list[$note]);103 push @keys, $tone_list[$note]; 99 104 } 105 100 106 return @keys; 107 } 108 109 sub scale 110 { 111 my $self = shift; 112 my $note = shift || return; 113 114 $note =~ s/^([a-g])/uc($1)/e; 115 croak "wrong note ($note)" if $note !~ /^[A-G](?:[#b])?$/; 116 117 return $scalic_value->{$note}; 101 118 } 102 119 … … 121 138 print "@tone"; # C E G B 122 139 140 my $note = $cn->scale('D#'); 141 142 print "$note"; # 3 143 123 144 124 145 =head1 METHOD … … 133 154 134 155 get tone list from chord name 156 157 =item scale($note) 158 159 get scalic value from C (C=0, B=11) 135 160 136 161 =back -
lang/perl/Music-Chord-Note/trunk/t/01.rehearsal.t
r25526 r26114 1 1 use strict; 2 2 3 use Test::More tests => 22;3 use Test::More tests => 31; 4 4 5 5 use Music::Chord::Note; … … 52 52 53 53 54 my $no_note = $cn->scale(''); 55 is($no_note, undef, "No Note"); 54 56 57 eval { my $wrong_note = $cn->scale('H'); }; 58 like($@, qr/wrong note/, "Wrong Note H"); 59 60 eval { my $wrong_note = $cn->scale('C+'); }; 61 like($@, qr/wrong note/, "Wrong Note C+"); 62 63 eval { my $wrong_note = $cn->scale('D-'); }; 64 like($@, qr/wrong note/, "Wrong Note D-"); 65 66 my $sv = $cn->scale('C'); 67 is($sv, 0, 'Scalic Value C'); 68 69 my $sv1 = $cn->scale('A'); 70 is($sv1, 9, 'Scalic Value A'); 71 72 my $sv2 = $cn->scale('A#'); 73 is($sv2, 10, 'Scalic Value A#'); 74 75 my $sv3 = $cn->scale('Eb'); 76 is($sv3, 3, 'Scalic Value Eb'); 77 78 my $sv4 = $cn->scale('gb'); 79 is($sv4, 6, 'Scalic Value gb');
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)