]> git.xonotic.org Git - xonotic/xonotic.git/commitdiff
handle MIDI files with "late start"
authorRudolf Polzer <divverent@xonotic.org>
Sat, 10 Dec 2011 11:32:09 +0000 (12:32 +0100)
committerRudolf Polzer <divverent@xonotic.org>
Sat, 10 Dec 2011 11:32:09 +0000 (12:32 +0100)
misc/tools/midi2cfg-ng.pl

index c2c3f47f09b50182676ff27d034cf53acc0ee713..83550b007787d3fcb26cc17e543539cb96f84480 100755 (executable)
@@ -800,8 +800,20 @@ sub ConvertMIDI($$)
                }
        }
 
+       # sort events
        @allmidievents = sort { $a->[1] <=> $b->[1] or $a->[2] <=> $b->[2] } @allmidievents;
 
+       # find the first interesting event
+       my $shift = [grep { $_->[0] eq 'note_on' } @allmidievents]->[0][1];
+       die "No notes!"
+               unless defined $shift;
+
+       # shift times by first event, no boring waiting
+       $_->[0] = ($_->[0] < $shift ? 0 : $_->[0] - $shift) for @tempi;
+       $_->[1] = ($_->[1] < $shift ? 0 : $_->[1] - $shift) for @allmidievents;
+
+       # fix event list
+
        my %midinotes = ();
        my $notes_stuck = 0;
        my %notes_seen = ();