lessons/reading: guitar_trainer.pl
File guitar_trainer.pl, 1.1 KB (added by kgushin, 7 years ago) |
---|
Line | |
---|---|
1 | #/usr/bin/perl -w |
2 | |
3 | use strict; |
4 | use warnings; |
5 | use Time::HiRes qw( sleep ); |
6 | use Getopt::Long; |
7 | |
8 | ##### PARAMS ####### |
9 | # temp - bits per minute |
10 | # type - [step / tune] |
11 | # guitar_trainer.pl -temp 50 -type tune |
12 | |
13 | my $temp = 60; |
14 | my $type = 'tune'; |
15 | GetOptions ('temp=i' => \$temp, 'type=s' => \$type); |
16 | my $sleep = 60/$temp; |
17 | |
18 | |
19 | if ($type eq 'tune') { |
20 | get_tune($sleep); |
21 | } else { |
22 | get_step($sleep); |
23 | } |
24 | |
25 | sub get_tune { |
26 | my $sleep = shift; |
27 | my $prev = 0; |
28 | my %tones = ( |
29 | 0 => 'ÐÐ', |
30 | 1 => 'Ð Ð', |
31 | 2 => 'ÐÐ', |
32 | 3 => 'ЀÐ', |
33 | 4 => 'СÐÐЬ', |
34 | 5 => 'ÐЯ', |
35 | 6 => 'СÐ' |
36 | ); |
37 | while (1) { |
38 | my $i = int(rand(7)); |
39 | unless ($i == $prev) { |
40 | print $tones{$i}."\n"; |
41 | sleep($sleep); |
42 | print ".\n"; |
43 | sleep($sleep); |
44 | print "x \n"; |
45 | sleep($sleep); |
46 | print ". \n"; |
47 | sleep($sleep); |
48 | $prev = $i; |
49 | } |
50 | } |
51 | } |
52 | |
53 | sub get_step { |
54 | my $sleep = shift; |
55 | my $prev = 0; |
56 | while (1) { |
57 | my $i = int(rand(7)) + 1; |
58 | unless ($i == $prev) { |
59 | print $i."\n"; |
60 | sleep($sleep); |
61 | print ". \n"; |
62 | sleep($sleep); |
63 | print "x \n"; |
64 | sleep($sleep); |
65 | print ". \n"; |
66 | sleep($sleep); |
67 | $prev = $i; |
68 | } |
69 | } |
70 | } |
71 | |
72 |