#/usr/bin/perl -w

use strict;
use warnings;
use Time::HiRes qw( sleep );
use Getopt::Long;

	##### PARAMS #######
# temp - bits per minute
# type - [step / tune]
# guitar_trainer.pl -temp 50 -type tune

my $temp = 60;	
my $type = 'tune';
GetOptions ('temp=i' => \$temp, 'type=s' => \$type);
my $sleep = 60/$temp;


if ($type eq 'tune') {
	get_tune($sleep);
} else {
	get_step($sleep);
}

sub get_tune {
	my $sleep = shift;
	my $prev = 0;
	my %tones = ( 
		0 => 'ДО',
		1 => 'РЕ',
		2 => 'МИ',
		3 => 'ФА',
		4 => 'СОЛЬ',
		5 => 'ЛЯ',
		6 => 'СИ'
	);
	while (1) {
		my $i = int(rand(7));
		unless ($i == $prev) {
			print $tones{$i}."\n";
			sleep($sleep);
			print ".\n";	
			sleep($sleep);
			print "x \n";	
			sleep($sleep);
			print ". \n";	
			sleep($sleep);
			$prev = $i;
		}
	}
}

sub get_step {
	my $sleep = shift;
	my $prev = 0;
	while (1) {
		my $i = int(rand(7)) + 1;
		unless ($i == $prev) {
			print $i."\n";
			sleep($sleep);
			print ". \n";
			sleep($sleep);
			print "x \n";	
			sleep($sleep);
			print ". \n";	
			sleep($sleep);
			$prev = $i;
		}
	}
}


