| 1 | #! perl | ||||||||||
| 2 | |||||||||||
| 3 | # Author : Johan Vromans | ||||||||||
| 4 | # Created On : Wed Aug 22 22:33:31 2007 | ||||||||||
| 5 | # Last Modified By: Johan Vromans | ||||||||||
| 6 | # Last Modified On: Tue Apr 19 16:24:17 2011 | ||||||||||
| 7 | # Update Count : 6 | ||||||||||
| 8 | # Status : Unknown, Use with caution! | ||||||||||
| 9 | |||||||||||
| 10 | package App::Music::PlayTab::NoteMap; | ||||||||||
| 11 | |||||||||||
| 12 | 7 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 7 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 7 | our $VERSION = "1.005"; | |||||||||
| 16 | |||||||||||
| 17 | 7 | ▶ | use base qw(Exporter); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 7 | our @EXPORT_OK; | |||||||||
| 19 | 7 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 7 | @EXPORT_OK = qw(@FNotes @SNotes note_to_key key_to_note); | |||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | # All notes, using sharps. | ||||||||||
| 24 | 7 | our @SNotes = | |||||||||
| 25 | # 0 1 2 3 4 5 6 7 8 9 10 11 | ||||||||||
| 26 | ('C', 'C#','D', 'D#','E', 'F', 'F#','G', 'G#','A', 'A#','B'); | ||||||||||
| 27 | |||||||||||
| 28 | # All notes, using flats. | ||||||||||
| 29 | 7 | our @FNotes = | |||||||||
| 30 | # 0 1 2 3 4 5 6 7 8 9 10 11 | ||||||||||
| 31 | ('C', 'Db','D', 'Eb','E', 'F', 'Gb','G', 'Ab','A', 'Bb','B'); | ||||||||||
| 32 | |||||||||||
| 33 | # The current mapping. This can be changed by set_flat/set_sharp. | ||||||||||
| 34 | 7 | my $Notes = \@SNotes; | |||||||||
| 35 | |||||||||||
| 36 | # Reverse mapping (plain notes only). | ||||||||||
| 37 | 7 | my %Notemap; | |||||||||
| 38 | 7 | ▶ | for ( my $i = 0; $i < @SNotes; $i++ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 84 | ▶ | $Notemap{$SNotes[$i]} = $i if length($SNotes[$i]) == 1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 0 | ▶ | sub set_flat { | ||||||||
|
Subroutine
set_flat: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 43 | 0 | my $Notes = \@FNotes; | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 0 | ▶ | sub set_sharp { | ||||||||
|
Subroutine
set_sharp: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 47 | 0 | my $Notes = \@SNotes; | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 699 | ▶ | sub note_to_key { | ||||||||
|
Subroutine
note_to_key: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 51 | 699 | $Notemap{uc shift()}; | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 819 | ▶ | sub key_to_note { | ||||||||
|
Subroutine
key_to_note: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 55 | 819 | my ($key, $flat) = @_; | |||||||||
| 56 | 819 | ▶ | return $Notes->[$key] unless defined $flat; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 381 | ▶ | return $FNotes[$key] if $flat; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | 96 | $SNotes[$key]; | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 7 | 1; | |||||||||
| 62 | |||||||||||
| 63 | __END__ | ||||||||||