-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelativize.pl
executable file
·65 lines (52 loc) · 1.22 KB
/
relativize.pl
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
#!/usr/bin/perl
use strict; use warnings;
# Changes the file to make it more edible for an LSTM,
# In particular, changes times from absolute to deltas
use Path::Class;
use autodie; # die if problem reading or writing a file
#my $outfile = file("$ARGV[0].rel")->openw();
my $previous = 0;
my $abs_num = 0;
my $to_replace = 0;
while (my $line = <>)
{
if ($line =~ /^\d+/)
{
($abs_num) = $line =~ /^(\d+)/; # 123
$to_replace = $abs_num - $previous;
# can be negative
$previous = $abs_num;
$line =~ s/^\d+/$to_replace/;
}
if ($line =~ / On /)
{
$line =~ s/ On /Y/;
}
if ($line =~ / Off /)
{
$line =~ s/ Off /N/;
}
if ($line =~ / Par ch=1 c=\d+/)
{
$line =~ s/ Par ch=1 c=\d+/P/;
}
if ($line =~ /ch=1 n=/)
{
$line =~ s/ch=1 n=/n/;
}
if ($line =~ /MFile \d \d /)
{
$line =~ s/MFile \d \d /M/;
}
if ($line =~ / v=\d+/)
{
$line =~ s/ v=80/+/;
$line =~ s/ v=0/-/;
$line =~ s/ v=127/*/;
$line =~ s/ v=1/:/;
}
$line =~ s/([a-g])\#/uc($1)/e;
$line =~ s/TrkEnd/}/;
$line =~ s/MTrk/{/;
print($line);
}