File Coverage

blib/lib/POE/Framework/MIDI/Utility.pm
Criterion Covered Total %
statement 12 20 60.0
branch 0 2 0.0
condition n/a
subroutine 4 6 66.6
pod 2 2 100.0
total 18 30 60.0


line stmt bran cond sub pod time code
1             # $Id: Utility.pm,v 1.1.1.1 2004/11/22 17:52:11 root Exp $
2              
3             package POE::Framework::MIDI::Utility;
4 10     10   61 use strict;
  10         20  
  10         476  
5 10     10   53 use vars '$VERSION'; $VERSION = '0.02';
  10         17  
  10         451  
6 10     10   158 use base 'Exporter';
  10         20  
  10         1046  
7 10     10   50 use vars qw(@EXPORT @EXPORT_OK);
  10         18  
  10         4637  
8             @EXPORT = @EXPORT_OK = qw(
9             %Volume %Length %Note @Note
10             name_to_number
11             number_to_name
12             );
13              
14             # These lists are copied directly from Sean Burke's MIDI::Simple.
15             #
16             my %Volume = (
17             'ppp' => 1, # pianississimo
18             'pp' => 12, # pianissimo
19             'p' => 24, # piano
20             'mp' => 48, # mezzopiano
21             'm' => 64, # mezzo / medio / meta / middle / whatever
22             'mezzo' => 64,
23             'mf' => 80, # mezzoforte
24             'f' => 96, # forte
25             'ff' => 112, # fortissimo
26             'fff' => 127, # fortississimo
27             );
28             my %Length = (
29             'wn' => 4, 'dwn' => 6, 'ddwn' => 7, 'twn' => (8/3),
30             'hn' => 2, 'dhn' => 3, 'ddhn' => 3.5, 'thn' => (4/3),
31             'qn' => 1, 'dqn' => 1.5, 'ddqn' => 1.75, 'tqn' => (2/3),
32             'en' => .5, 'den' => .75, 'dden' => .75, 'ten' => (1/3),
33             'sn' => .25, 'dsn' => .375, 'ddsn' => .4375, 'tsn' => (1/6),
34             );
35             my %Note = (
36             'C' => 0,
37             'Cs' => 1, 'Csharp' => 1, 'Df' => 1, 'Dflat' => 1,
38             'D' => 2,
39             'Ds' => 3, 'Dsharp' => 3, 'Ef' => 3, 'Eflat' => 3,
40             'E' => 4,
41             'F' => 5,
42             'Fs' => 6, 'Fsharp' => 6, 'Gf' => 6, 'Gflat' => 6,
43             'G' => 7,
44             'Gs' => 8, 'Gsharp' => 8, 'Af' => 8, 'Aflat' => 8,
45             'A' => 9,
46             'As' => 10, 'Asharp' => 10, 'Bf' => 10, 'Bflat' => 10,
47             'B' => 11,
48             );
49              
50             # Keep an ordered list too, y'know.
51             # NOTE: # (Get it? "Note"? Haha *cough*) These must be keys of %Note.
52             my @Note = qw( C Df D Ef E F Gf G Af A Bf B );
53              
54             sub name_to_number {
55 0     0 1   return $Note{shift};
56             }
57              
58             sub number_to_name {
59 0     0 1   my $n = shift;
60 0 0         die $n . ' is out of bounds. Notes are numbered 0 to 11.'
61             if $n > 11;
62              
63             # Flip the Note hash into a HoL.
64 0           my %name;
65 0           while (my ($k, $v) = each %Note) {
66 0           push @{ $name{$k} }, $v;
  0            
67             }
68              
69             # Return the note name array reference.
70 0           return $name{$n};
71             }
72              
73             1;
74              
75             __END__