File Coverage

blib/lib/MIDI/Drummer/Tiny/SwingFills.pm
Criterion Covered Total %
statement 12 196 6.1
branch n/a
condition 0 3 0.0
subroutine 4 28 14.2
pod 1 1 100.0
total 17 228 7.4


line stmt bran cond sub pod time code
1             package MIDI::Drummer::Tiny::SwingFills;
2             $MIDI::Drummer::Tiny::SwingFills::VERSION = '0.7002';
3             our $AUTHORITY = 'cpan:GENE';
4              
5 1     1   348658 use Moo;
  1         9934  
  1         6  
6 1     1   1988 use strictures 2;
  1         1694  
  1         68  
7 1     1   1160 use MIDI::Util qw(dura_size);
  1         31462  
  1         66  
8 1     1   405 use namespace::clean;
  1         14225  
  1         6  
9              
10             #pod =head1 SYNOPSIS
11             #pod
12             #pod use MIDI::Drummer::Tiny;
13             #pod use MIDI::Drummer::Tiny::SwingFills;
14             #pod
15             #pod my $d = MIDI::Drummer::Tiny->new;
16             #pod my $f = MIDI::Drummer::Tiny::SwingFills->new;
17             #pod
18             #pod for my $i (1 .. $d->beats * $d->bars) {
19             #pod my $remainder = $d->beats * $d->bars - $i;
20             #pod my $fill = $f->get_fill($d, $d->ride2);
21             #pod if ($remainder == $fill->{dura}) {
22             #pod $fill->{fill}->();
23             #pod last;
24             #pod }
25             #pod else {
26             #pod $d->note($d->quarter, $d->open_hh, $_ % 2 ? $d->kick : $d->snare);
27             #pod }
28             #pod }
29             #pod
30             #pod =head1 DESCRIPTION
31             #pod
32             #pod TBD
33             #pod
34             #pod =cut
35              
36             #pod =head1 METHODS
37             #pod
38             #pod =head2 new
39             #pod
40             #pod $f = MIDI::Drummer::Tiny::Fills->new;
41             #pod
42             #pod Return a new C object.
43             #pod
44             #pod =head2 get_fill
45             #pod
46             #pod $fill = $f->get_fill($drummer_obj, $cymbal);
47             #pod
48             #pod Return a random fill given a B and an optional
49             #pod B.
50             #pod
51             #pod The fill that is returned is a hash reference with keys: C - a
52             #pod code reference, and C - the numerical duration of the fill.
53             #pod
54             #pod =cut
55              
56             sub get_fill {
57 0     0 1   my ($self, $drummer, $cymbal) = @_;
58 0           my $fills = $self->_fills($drummer, $cymbal);
59 0           my @keys = keys %$fills;
60 0           my $fill = $keys[ int rand @keys ];
61 0           return $fills->{$fill};
62             }
63              
64             sub _fills {
65 0     0     my ($self, $d, $cymbal) = @_;
66 0   0       $cymbal ||= $d->closed_hh;
67             my %fills = (
68              
69             1 => {
70             fill => sub {
71 0     0     $d->note($d->dotted_eighth, $d->kick, $cymbal);
72 0           $d->note($d->sixteenth, $d->snare);
73 0           $d->note($d->triplet_eighth, $d->kick, $d->snare);
74 0           $d->note($d->triplet_eighth, $d->snare);
75 0           $d->note($d->triplet_eighth, $d->snare);
76             },
77             dura => dura_size($d->half),
78             },
79              
80             2 => {
81             fill => sub {
82 0     0     $d->note($d->dotted_eighth, $d->kick, $cymbal);
83 0           $d->note($d->sixteenth, $d->snare);
84 0           $d->note($d->dotted_eighth, $d->snare);
85 0           $d->note($d->sixteenth, $d->kick, $cymbal);
86             },
87             dura => dura_size($d->half),
88             },
89              
90             3 => {
91             fill => sub {
92 0     0     $d->note($d->eighth, $d->kick, $cymbal);
93 0           $d->note($d->triplet_sixteenth, $d->snare);
94 0           $d->note($d->triplet_sixteenth, $d->snare);
95 0           $d->note($d->triplet_sixteenth, $d->snare);
96 0           $d->note($d->dotted_eighth, $d->snare);
97 0           $d->note($d->sixteenth, $d->kick, $cymbal);
98             },
99             dura => dura_size($d->half),
100             },
101              
102             4 => {
103             fill => sub {
104 0     0     $d->note($d->dotted_eighth, $d->kick, $cymbal);
105 0           $d->note($d->sixteenth, $d->snare);
106 0           $d->note($d->triplet_eighth, $d->kick, $d->snare);
107 0           $d->note($d->triplet_eighth, $d->snare);
108 0           $d->note($d->triplet_eighth, $d->snare);
109 0           $d->note($d->triplet_eighth, $d->kick, $d->snare);
110 0           $d->note($d->triplet_eighth, $d->snare);
111 0           $d->note($d->triplet_eighth, $d->snare);
112 0           $d->note($d->triplet_eighth, $d->kick, $d->snare);
113 0           $d->note($d->triplet_eighth, $d->snare);
114 0           $d->note($d->triplet_eighth, $d->snare);
115             },
116             dura => dura_size($d->whole),
117             },
118              
119             5 => {
120             fill => sub {
121 0     0     $d->note($d->dotted_eighth, $d->kick, $d->snare, $cymbal);
122 0           $d->note($d->sixteenth, $cymbal);
123 0           $d->note($d->eighth, $d->kick, $cymbal);
124 0           $d->note($d->sixteenth, $d->snare);
125 0           $d->note($d->sixteenth, $d->snare);
126 0           $d->note($d->dotted_eighth, $d->snare);
127 0           $d->note($d->sixteenth, $d->kick, $cymbal);
128             },
129             dura => dura_size($d->dotted_half),
130             },
131              
132             6 => {
133             fill => sub {
134 0     0     $d->note($d->dotted_eighth, $d->kick, $d->snare, $cymbal);
135 0           $d->note($d->sixteenth, $cymbal);
136 0           $d->note($d->dotted_eighth, $d->kick, $cymbal);
137 0           $d->note($d->sixteenth, $d->snare);
138 0           $d->note($d->dotted_eighth, $d->snare);
139 0           $d->note($d->sixteenth, $d->kick);
140             },
141             dura => dura_size($d->dotted_half),
142             },
143              
144             7 => {
145             fill => sub {
146 0     0     $d->note($d->dotted_eighth, $d->snare, $cymbal);
147 0           $d->note($d->sixteenth, $d->snare, $cymbal);
148 0           $d->note($d->quarter, $d->snare, $cymbal);
149 0           $d->note($d->dotted_eighth, $d->kick, $cymbal);
150 0           $d->note($d->sixteenth, $d->kick);
151             },
152             dura => dura_size($d->dotted_half),
153             },
154              
155             8 => {
156             fill => sub {
157 0     0     $d->note($d->dotted_eighth, $d->snare, $cymbal);
158 0           $d->note($d->sixteenth, $d->kick, $cymbal);
159 0           $d->note($d->quarter, $d->kick, $cymbal);
160 0           $d->note($d->dotted_eighth, $d->snare, $cymbal);
161 0           $d->note($d->sixteenth, $d->kick, $cymbal);
162             },
163             dura => dura_size($d->dotted_half),
164             },
165              
166             9 => {
167             fill => sub {
168 0     0     my $initial = 49;
169 0           my $range = 39;
170 0           my $step = sprintf '%.0f', $range / 9;
171 0           my $n = 0;
172 0           $d->note($d->dotted_eighth, $d->kick, $cymbal);
173 0           $d->note($d->sixteenth, $d->snare);
174 0           $d->note($d->triplet_eighth, $d->kick, $d->snare, 'v' . ($initial + ($n++ * $step)));
175 0           $d->note($d->triplet_eighth, $d->snare, 'v' . ($initial + ($n++ * $step)));
176 0           $d->note($d->triplet_eighth, $d->snare, 'v' . ($initial + ($n++ * $step)));
177 0           $d->note($d->triplet_eighth, $d->kick, $d->snare, 'v' . ($initial + ($n++ * $step)));
178 0           $d->note($d->triplet_eighth, $d->snare, 'v' . ($initial + ($n++ * $step)));
179 0           $d->note($d->triplet_eighth, $d->snare, 'v' . ($initial + ($n++ * $step)));
180 0           $d->note($d->triplet_eighth, $d->kick, $d->snare, 'v' . ($initial + ($n++ * $step)));
181 0           $d->note($d->triplet_eighth, $d->snare, 'v' . ($initial + ($n++ * $step)));
182 0           $d->note($d->triplet_eighth, $d->snare, 'v' . ($initial + ($n++ * $step)));
183             },
184             dura => dura_size($d->whole),
185             },
186              
187             10 => {
188             fill => sub {
189 0     0     $d->note($d->dotted_eighth, $d->kick, $cymbal);
190 0           $d->note($d->sixteenth, $d->snare);
191 0           $d->note($d->dotted_eighth, $d->snare, $cymbal);
192 0           $d->note($d->sixteenth, $d->kick, $cymbal);
193 0           $d->note($d->dotted_eighth, $d->snare, $cymbal);
194 0           $d->note($d->sixteenth, $d->snare);
195 0           $d->note($d->dotted_eighth, $d->kick, $cymbal);
196 0           $d->note($d->sixteenth, $cymbal);
197             },
198             dura => dura_size($d->whole),
199             },
200              
201             11 => {
202             fill => sub {
203 0     0     $d->note($d->dotted_eighth, $d->kick, $cymbal);
204 0           $d->note($d->sixteenth, $d->snare);
205 0           $d->note($d->dotted_eighth, $d->snare, $cymbal);
206 0           $d->note($d->sixteenth, $d->kick, $cymbal);
207 0           $d->note($d->dotted_eighth, $d->kick, $cymbal);
208 0           $d->note($d->sixteenth, $d->snare);
209 0           $d->note($d->dotted_eighth, $d->snare, $cymbal);
210 0           $d->note($d->sixteenth, $d->kick, $cymbal);
211             },
212             dura => dura_size($d->whole),
213             },
214              
215             12 => {
216             fill => sub {
217 0     0     $d->note($d->dotted_eighth, $d->snare, $cymbal);
218 0           $d->note($d->sixteenth, $d->kick);
219 0           $d->note($d->dotted_eighth, $cymbal);
220 0           $d->note($d->sixteenth, $d->snare, $cymbal);
221 0           $d->note($d->quarter, $d->kick, $cymbal);
222 0           $d->note($d->dotted_eighth, $d->kick, $cymbal);
223 0           $d->note($d->sixteenth, $cymbal);
224             },
225             dura => dura_size($d->whole),
226             },
227              
228             13 => {
229             fill => sub {
230 0     0     $d->note($d->dotted_eighth, $d->kick, $cymbal);
231 0           $d->note($d->sixteenth, $d->snare);
232 0           $d->note($d->triplet_eighth, $d->snare);
233 0           $d->note($d->triplet_eighth, $d->snare);
234 0           $d->note($d->triplet_eighth, $d->snare);
235 0           $d->note($d->dotted_eighth, $d->snare);
236 0           $d->note($d->sixteenth, $d->kick);
237 0           $d->note($d->quarter, $d->kick);
238             },
239             dura => dura_size($d->whole),
240             },
241              
242             14 => {
243             fill => sub {
244 0     0     $d->note($d->dotted_eighth, $d->kick, $cymbal);
245 0           $d->note($d->sixteenth, $d->snare);
246 0           $d->note($d->dotted_eighth, $cymbal);
247 0           $d->note($d->sixteenth, $d->snare, $cymbal);
248 0           $d->note($d->dotted_eighth, $cymbal);
249 0           $d->note($d->sixteenth, $d->kick);
250 0           $d->note($d->dotted_eighth, $cymbal);
251 0           $d->note($d->sixteenth, $d->kick);
252             },
253             dura => dura_size($d->whole),
254             },
255              
256             15 => {
257             fill => sub {
258 0     0     $d->note($d->dotted_eighth, $d->kick, $cymbal);
259 0           $d->note($d->sixteenth, $d->snare);
260 0           $d->note($d->dotted_eighth, $d->kick, $cymbal);
261 0           $d->note($d->sixteenth, $d->snare, $cymbal);
262 0           $d->note($d->quarter, $d->kick, $cymbal);
263 0           $d->note($d->dotted_eighth, $d->kick, $cymbal);
264 0           $d->note($d->sixteenth, $d->snare, $cymbal);
265             },
266             dura => dura_size($d->whole),
267             },
268              
269             16 => {
270             fill => sub {
271 0     0     $d->note($d->triplet_eighth, $d->kick, $d->snare, $cymbal);
272 0           $d->rest($d->triplet_eighth);
273 0           $d->note($d->triplet_eighth, $cymbal);
274 0           $d->note($d->triplet_eighth, $d->kick, $cymbal);
275 0           $d->rest($d->triplet_eighth);
276 0           $d->note($d->triplet_eighth, $d->snare);
277 0           $d->note($d->triplet_eighth, $d->kick, $cymbal);
278 0           $d->note($d->triplet_eighth, $d->snare);
279 0           $d->note($d->triplet_eighth, $d->snare, $cymbal);
280             },
281             dura => dura_size($d->dotted_half),
282             },
283              
284             17 => {
285             fill => sub {
286 0     0     $d->note($d->dotted_eighth, $d->kick, $d->snare, $cymbal);
287 0           $d->note($d->sixteenth, $cymbal);
288 0           $d->note($d->quarter, $d->kick, $cymbal);
289 0           $d->note($d->triplet_sixteenth, $d->snare);
290 0           $d->note($d->triplet_sixteenth, $d->snare);
291 0           $d->note($d->triplet_sixteenth, $d->snare);
292 0           $d->note($d->dotted_eighth, $d->snare);
293 0           $d->note($d->sixteenth, $d->kick);
294             },
295             dura => dura_size($d->dotted_half),
296             },
297              
298             18 => {
299             fill => sub {
300 0     0     $d->note($d->triplet_eighth, $d->kick, $cymbal);
301 0           $d->note($d->triplet_eighth, $d->snare);
302 0           $d->rest($d->triplet_eighth);
303 0           $d->note($d->triplet_eighth, $d->snare, $cymbal);
304 0           $d->rest($d->triplet_eighth);
305 0           $d->note($d->triplet_eighth, $d->snare, $cymbal);
306 0           $d->note($d->triplet_eighth, $d->snare, $cymbal);
307 0           $d->note($d->triplet_eighth, $d->kick);
308 0           $d->rest($d->triplet_eighth);
309 0           $d->note($d->triplet_eighth, $d->kick, $cymbal);
310 0           $d->rest($d->triplet_eighth);
311 0           $d->note($d->triplet_eighth, $d->kick, $cymbal);
312             },
313             dura => dura_size($d->dotted_half),
314             },
315              
316             19 => {
317             fill => sub {
318 0     0     $d->note($d->dotted_eighth, $d->kick, $cymbal);
319 0           $d->note($d->sixteenth, $d->snare);
320 0           $d->note($d->dotted_eighth, $d->kick, $cymbal);
321 0           $d->note($d->sixteenth, $cymbal);
322 0           $d->note($d->dotted_eighth, $d->kick, $cymbal);
323 0           $d->note($d->sixteenth, $d->snare);
324 0           $d->note($d->dotted_eighth, $d->kick, $cymbal);
325 0           $d->note($d->sixteenth, $d->snare, $cymbal);
326             },
327             dura => dura_size($d->whole),
328             },
329              
330             20 => {
331             fill => sub {
332 0     0     $d->flam($d->triplet_eighth, $d->snare);
333 0           $d->note($d->triplet_eighth, $d->kick);
334 0           $d->note($d->triplet_eighth, $d->kick);
335 0           $d->flam($d->triplet_eighth, $d->snare);
336 0           $d->note($d->triplet_eighth, $d->kick);
337 0           $d->note($d->triplet_eighth, $d->kick);
338             },
339             dura => dura_size($d->half),
340             },
341              
342             21 => {
343             fill => sub {
344 0     0     $d->note($d->triplet_eighth, $d->kick);
345 0           $d->flam($d->triplet_eighth, $d->snare);
346 0           $d->note($d->triplet_eighth, $d->kick);
347 0           $d->flam($d->triplet_eighth, $d->snare);
348 0           $d->note($d->triplet_eighth, $d->kick);
349 0           $d->flam($d->triplet_eighth, $d->snare);
350 0           $d->note($d->triplet_eighth, $d->kick);
351 0           $d->flam($d->triplet_eighth, $d->snare);
352 0           $d->note($d->triplet_eighth, $d->kick);
353 0           $d->flam($d->triplet_eighth, $d->snare);
354 0           $d->note($d->triplet_eighth, $d->kick);
355 0           $d->note($d->triplet_eighth, $d->kick);
356             },
357             dura => dura_size($d->whole),
358             },
359              
360             22 => {
361             fill => sub {
362 0     0     $d->note($d->dotted_eighth, $d->kick, $cymbal);
363 0           $d->note($d->sixteenth, $d->snare);
364 0           $d->flam($d->triplet_eighth, $d->kick, $d->snare);
365 0           $d->flam($d->triplet_eighth, $d->snare);
366 0           $d->flam($d->triplet_eighth, $d->snare);
367 0           $d->note($d->dotted_eighth, $d->kick, $d->snare);
368 0           $d->note($d->sixteenth, $d->hi_tom);
369 0           $d->flam($d->triplet_eighth, $d->kick, $d->hi_tom);
370 0           $d->flam($d->triplet_eighth, $d->hi_tom);
371 0           $d->flam($d->triplet_eighth, $d->hi_tom);
372             },
373 0           dura => dura_size($d->whole),
374             },
375              
376             );
377 0           return \%fills;
378             }
379              
380             1;
381              
382             __END__