stuff Repository

view midi/depedal.pl @ 69:325147465130

Updated buffer.h from GGGGC.
author Gregor Richards <Richards@codu.org>
date Fri Sep 03 11:25:37 2010 -0400 (5 days ago)
parents
children
line source
1 #!/usr/bin/perl -w
2 use strict;
4 # Copyright (C) 2010 Gregor Richards
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 # THE SOFTWARE.
24 my $pedal = 0;
25 my %offkeys = ();
26 my $offkey;
28 while (my $line = <STDIN>) {
29 chomp $line;
30 my @elems = split / /, $line;
32 # check the type
33 if ($#elems >= 4 && $elems[1] eq "Par" && $elems[3] eq "c=64") {
34 # damper
35 my $v = int(substr($elems[4], 2));
36 if ($v > 64) {
37 # on
38 $pedal = 1;
40 } else {
41 # off
42 $pedal = 0;
44 # turn off keys
45 foreach $offkey (keys %offkeys) {
46 if ($offkeys{$offkey}) {
47 print $elems[0] . " Off ch=1 n=" . $offkey . " v=127\n";
48 }
49 }
50 %offkeys = ();
52 }
54 } elsif ($pedal && $#elems >= 3 && $elems[1] eq "On") {
55 # if this is a key that's supposedly off, need to put the off now
56 my $n = int(substr($elems[3], 2));
57 if ($offkeys{$n}) {
58 print $elems[0] . " Off ch=1 n=" . $n . " v=127\n";
59 $offkeys{$n} = 0;
60 }
61 print join(" ", @elems) . "\n";
63 } elsif ($pedal && $#elems >= 3 && $elems[1] eq "Off") {
64 # lifting a key while the pedal is depressed
65 $offkeys{int(substr($elems[3], 2))} = 1;
67 } else {
68 print join(" ", @elems) . "\n";
70 }
71 }