1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
| sub compareToneSequences
{
my $baseCount = @baseTones;
my $countMatch = 0; # record how many tones matched
for my $toneFromFile ( keys %toneHash )
{
my @confTones = split " ", $toneHash{$toneFromFile}{tones};
my @confTimes = split " ", $toneHash{$toneFromFile}{times};
my $confCount = @confTones;
next unless( $confCount == $baseCount );
# as a learning aid, the matching and non matching portions of the
# comparison are printed out, so at least you can see what is going
# wrong while trying to remember your tone codes
my $pos =0;
my $toneMatchFail = 0;
for( @baseTones )
{
my $tonDiff = abs($confTones[$pos] - $baseTones[$pos]);
my $tonStr = "t $pos b $baseTones[$pos] ".
"c $confTones[$pos] \n";
my $timeDiff = abs($confTimes[$pos] - $baseTimes[$pos]);
my $timStr = "t $pos b $baseTimes[$pos] ".
"c $confTimes[$pos] d $timeDiff\n";
if( $tonDiff > $MAX_TONE_DEV )
{
$toneMatchFail = 1;
if( $option ){ print "NOTE DISSONANCE $tonStr" }
}else
{
if( $option ){ print "NOTE MATCH $tonStr" }
}#if tone detected outside of deviation
# if it's an exact match, increment the matching counter
if( $timeDiff < $MAX_TIME_DEV ){
if( $option ){ print "TIME MATCH $timStr" }
$countMatch++;
}else{
if( $option ){ print "TIME DISSONANCE $timStr" }
last;
}# deviation check
$pos++;
}# for each tone to check
if( $countMatch == $confCount && $toneMatchFail == 0 )
{
my $cmd = $toneHash{$toneFromFile}{ cmd };
if( $option ){ print "run: $cmd\n" }
$cmd =`$cmd`;
if( $option ){ print "result: $cmd\n" }
last;
# otherwise, make the count of matches zero, in order to not reset
}else
{
$countMatch = 0;
}
}#for each tone in tone file
# if the match count is zero, exit and don't reset variables so a longer
# tone sequence can be entered and checked
if( $countMatch == 0 ){ return() }
# if a match occured, reset the variables so it won't match another pattern
$toneCount = 0;
@baseTones = ();
@baseTimes = ();
}#compareToneSeqeunces
|