stuff Repository

diff midi/depedal.pl @ 94:779015292fac

Yet more log format improvements.
author Gregor Richards <Richards@codu.org>
date Thu, 07 Apr 2011 23:38:12 -0400
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/midi/depedal.pl	Thu Apr 07 23:38:12 2011 -0400
     1.3 @@ -0,0 +1,71 @@
     1.4 +#!/usr/bin/perl -w
     1.5 +use strict;
     1.6 +
     1.7 +#  Copyright (C) 2010 Gregor Richards
     1.8 +# 
     1.9 +#  Permission is hereby granted, free of charge, to any person obtaining a copy
    1.10 +#  of this software and associated documentation files (the "Software"), to deal
    1.11 +#  in the Software without restriction, including without limitation the rights
    1.12 +#  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    1.13 +#  copies of the Software, and to permit persons to whom the Software is
    1.14 +#  furnished to do so, subject to the following conditions:
    1.15 +# 
    1.16 +#  The above copyright notice and this permission notice shall be included in
    1.17 +#  all copies or substantial portions of the Software.
    1.18 +# 
    1.19 +#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    1.20 +#  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    1.21 +#  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    1.22 +#  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    1.23 +#  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    1.24 +#  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    1.25 +#  THE SOFTWARE.
    1.26 +
    1.27 +my $pedal = 0;
    1.28 +my %offkeys = ();
    1.29 +my $offkey;
    1.30 +
    1.31 +while (my $line = <STDIN>) {
    1.32 +    chomp $line;
    1.33 +    my @elems = split / /, $line;
    1.34 +
    1.35 +    # check the type
    1.36 +    if ($#elems >= 4 && $elems[1] eq "Par" && $elems[3] eq "c=64") {
    1.37 +        # damper
    1.38 +        my $v = int(substr($elems[4], 2));
    1.39 +        if ($v > 64) {
    1.40 +            # on
    1.41 +            $pedal = 1;
    1.42 +
    1.43 +        } else {
    1.44 +            # off
    1.45 +            $pedal = 0;
    1.46 +
    1.47 +            # turn off keys
    1.48 +            foreach $offkey (keys %offkeys) {
    1.49 +                if ($offkeys{$offkey}) {
    1.50 +                    print $elems[0] . " Off ch=1 n=" . $offkey . " v=127\n";
    1.51 +                }
    1.52 +            }
    1.53 +            %offkeys = ();
    1.54 +
    1.55 +        }
    1.56 +
    1.57 +    } elsif ($pedal && $#elems >= 3 && $elems[1] eq "On") {
    1.58 +        # if this is a key that's supposedly off, need to put the off now
    1.59 +        my $n = int(substr($elems[3], 2));
    1.60 +        if ($offkeys{$n}) {
    1.61 +            print $elems[0] . " Off ch=1 n=" . $n . " v=127\n";
    1.62 +            $offkeys{$n} = 0;
    1.63 +        }
    1.64 +        print join(" ", @elems) . "\n";
    1.65 +
    1.66 +    } elsif ($pedal && $#elems >= 3 && $elems[1] eq "Off") {
    1.67 +        # lifting a key while the pedal is depressed
    1.68 +        $offkeys{int(substr($elems[3], 2))} = 1;
    1.69 +
    1.70 +    } else {
    1.71 +        print join(" ", @elems) . "\n";
    1.72 +
    1.73 +    }
    1.74 +}