File Coverage

blib/lib/Types/MIDI.pm
Criterion Covered Total %
statement 20 20 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod n/a
total 27 27 100.0


line stmt bran cond sub pod time code
1             ## no critic (TestingAndDebugging::RequireUseStrict)
2             ## no critic (TestingAndDebugging::RequireUseWarnings)
3             package Types::MIDI;
4             our $AUTHORITY = 'cpan:MJGARDNER';
5             ## use critic (TestingAndDebugging::RequireUseStrict)
6             ## use critic (TestingAndDebugging::RequireUseWarnings)
7              
8 3     3   686214 use 5.016;
  3         30  
9 3     3   18 use strict;
  3         19  
  3         77  
10 3     3   14 use warnings;
  3         4  
  3         336  
11              
12             # ABSTRACT: Type library for MIDI
13              
14             #<<<
15             our $VERSION = 'v0.601.0';
16             #>>>
17              
18 3         41 use Type::Library 2.000000 -extends => [ qw(
19             Types::Common::Numeric
20             Types::Common::String
21             ) ],
22             -declare => qw(
23             Channel
24             Velocity
25             Note
26             PercussionNote
27 3     3   1757 );
  3         152477  
28 3     3   679367 use Type::Utils 2.000000 -all;
  3         77  
  3         40  
29 3     3   14815 use MIDI;
  3         35745  
  3         157  
30 3     3   2084 use Readonly;
  3         16642  
  3         1414  
31              
32             #pod =head1 SYNOPSIS
33             #pod
34             #pod use Moo;
35             #pod use Types::MIDI -all;
36             #pod
37             #pod has volume => (
38             #pod is => 'ro',
39             #pod isa => Velocity,
40             #pod default => 100,
41             #pod );
42             #pod has a440 => (
43             #pod is => 'ro',
44             #pod isa => Note,
45             #pod default => 69,
46             #pod );
47             #pod has electric_snare => (
48             #pod is => 'ro',
49             #pod isa => PercussionNote,
50             #pod coerce => 1,
51             #pod default => 'Electric Snare',
52             #pod );
53             #pod
54             #pod =head1 DESCRIPTION
55             #pod
56             #pod This is a type constraint library intended to be useful for those
57             #pod developing music software using the MIDI (Musical Instrument Digital
58             #pod Interface) specification.
59             #pod
60             #pod It is a work in progress driven by real-world usage, and as such
61             #pod B. Once it reaches
62             #pod version 1.0, though, the author does not intend to introduce any
63             #pod breaking changes without a corresponding increase in the major version
64             #pod number.
65             #pod
66             #pod =head1 OVERVIEW
67             #pod
68             #pod Because this leverages L, it should be usable in a
69             #pod variety of Perl object systems, including L and L. By
70             #pod default, it exports nothing into the consumer's namespace; however, in
71             #pod addition to specifying individual functions in the L
72             #pod statement, you can also provide or combine the following tags to export
73             #pod groups of functions:
74             #pod
75             #pod =over
76             #pod
77             #pod =item C
78             #pod
79             #pod Exports all types by name into the namespace.
80             #pod
81             #pod =item C
82             #pod
83             #pod Exports all CI functions into the namespace.
84             #pod
85             #pod =item C
86             #pod
87             #pod Exports all CI functions into the namespace.
88             #pod
89             #pod =item C
90             #pod
91             #pod Exports all CI functions into the namespace.
92             #pod
93             #pod =item CIC<);>
94             #pod
95             #pod Exports I and all related functions into the namespace.
96             #pod
97             #pod =item C
98             #pod
99             #pod Exports everything.
100             #pod
101             #pod =back
102             #pod
103             #pod This library also inherits from L; consult
104             #pod L for ways to customize how functions
105             #pod are imported, such as renaming or omitting certain names.
106             #pod
107             #pod Also note that the tags listed above may be preceded with a C<->
108             #pod (hyphen) instead of a C<:> (colon); Perl's auto-quoting of barewords
109             #pod thus enables you to import a tag group of functions like so:
110             #pod
111             #pod use Types::MIDI -all;
112             #pod
113             #pod =cut
114              
115             ## no critic (ValuesAndExpressions::ProhibitMagicNumbers)
116              
117             #pod =type Channel
118             #pod
119             #pod An L 0 to 15 corresponding
120             #pod to a MIDI Channel.
121             #pod
122             #pod =func is_Channel
123             #pod
124             #pod Returns true if the passed value can be used as a L.
125             #pod
126             #pod =func assert_Channel
127             #pod
128             #pod Returns the passed value if and only if it can be used as a L;
129             #pod otherwise it throws an exception.
130             #pod
131             #pod =cut
132              
133             declare Channel, as IntRange [ 0, 15 ];
134              
135             #pod =type Velocity
136             #pod
137             #pod An L 0 to 127 corresponding
138             #pod to a MIDI velocity.
139             #pod
140             #pod =func is_Velocity
141             #pod
142             #pod Returns true if the passed value can be used as a L.
143             #pod
144             #pod =func assert_Velocity
145             #pod
146             #pod Returns the passed value if and only if it can be used as a
147             #pod L; otherwise it throws an exception.
148             #pod
149             #pod =cut
150              
151             declare Velocity, as IntRange [ 0, 127 ];
152              
153             #pod =type Note
154             #pod
155             #pod An L 0 to 127 corresponding
156             #pod to a MIDI note number.
157             #pod
158             #pod =func is_Note
159             #pod
160             #pod Returns true if the passed value can be used as a L.
161             #pod
162             #pod =func assert_Note
163             #pod
164             #pod Returns the passed value if and only if it can be used as a L;
165             #pod otherwise it throws an exception.
166             #pod
167             #pod =cut
168              
169             declare Note, as IntRange [ 0, 127 ];
170              
171             #pod =type PercussionNote
172             #pod
173             #pod A L from 27 through 87, corresponding to a L number in the
174             #pod General MIDI 2 Percussion Sound Set.
175             #pod
176             #pod This type can also coerce case-insensitive
177             #pod Ls of instrument names in the
178             #pod General MIDI 2 Percussion Sound Set, returning the corresponding
179             #pod L.
180             #pod
181             #pod =func is_PercussionNote
182             #pod
183             #pod Returns true if the passed value can be used as a L.
184             #pod
185             #pod =func assert_PercussionNote
186             #pod
187             #pod Returns the passed value if and only if it can be used as a
188             #pod L; otherwise it throws an exception.
189             #pod
190             #pod =func to_PercussionNote
191             #pod
192             #pod Coerces the passed value to a L.
193             #pod
194             #pod =cut
195              
196             my %notenum2percussion = %MIDI::notenum2percussion; ## no critic (Variables::ProhibitPackageVars)
197             @notenum2percussion{ 27 .. 34, 82 .. 87 } = (
198             'High Q',
199             'Slap',
200             'Scratch Push',
201             'Scratch Pull',
202             'Sticks',
203             'Square Click',
204             'Metronome Click',
205             'Metronome Bell',
206              
207             'Shaker',
208             'Jingle Bell',
209             'Bell Tree',
210             'Castanets',
211             'Mute Surdo',
212             'Open Surdo',
213             );
214             Readonly my %NOTENUM2PERCUSSION_FC =>
215             map { fc $notenum2percussion{$_} => $_ } keys %notenum2percussion;
216              
217             declare PercussionNote, as Note,
218             where { exists $notenum2percussion{$_} };
219             coerce PercussionNote, from NonEmptySimpleStr,
220             via { $NOTENUM2PERCUSSION_FC{"\F$_"} };
221              
222             #pod =head1 SEE ALSO
223             #pod
224             #pod =over
225             #pod
226             #pod =item *
227             #pod
228             #pod I,
229             #pod revised February 1996 by the MIDI Manufacturers Association:
230             #pod L
231             #pod
232             #pod =item *
233             #pod
234             #pod B in
235             #pod I,
236             #pod published February 6, 2007 by the MIDI Manufacturers Association:
237             #pod L
238             #pod
239             #pod =back
240             #pod
241             #pod =cut
242              
243             1;
244              
245             __END__