stuff Repository

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