changeset 3:5abb6a523d27 midifile

* set timebase, bpb from input
author cannam
date Thu, 11 Feb 2010 13:52:10 +0000
parents 1a4000271db6
children a98a66b43882
files midisort.pl
diffstat 1 files changed, 18 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/midisort.pl	Thu Feb 11 12:26:07 2010 +0000
+++ b/midisort.pl	Thu Feb 11 13:52:10 2010 +0000
@@ -3,7 +3,8 @@
 # read the output from midifile, sort it into "note column" groups
 
 my $timebase = 120;
-my $beatsperbar = 3;
+my $beatsperbar = 4;
+my $seentimesig = 0;
 
 sub fmtm { # function to convert time to bar number
     int($_[0] / ($timebase * $beatsperbar)) + 1;
@@ -32,6 +33,21 @@
 	$c = $2;
 	$d = $3;
 	$p = $4;
+    } elsif (/^Timing division: (\d+)/) {
+	$timebase = $1;
+	print STDERR "Set timebase to $timebase from input data\n";
+	next;
+    } elsif (/^(\d+): Time signature: (\d+)\//) {
+	if ($seentimesig != 0 && $beatsperbar != $2) {
+	    print STDERR "WARNING: File uses more than one time signature, not supported here\n";
+	}
+	$beatsperbar = $2;
+	$seentimesig++;
+	print STDERR "Set beat count per bar to $beatsperbar from input data\n";
+	next;
+    } elsif (/^SMPTE/) {
+	print STDERR "WARNING: File uses SMPTE timing, expect incorrect results\n";
+	next;
     } else {
 	next;
     }
@@ -77,7 +93,7 @@
 
     for my $ot (keys %noteoffs) {
 	# prune notes that have ended already or are ending now
-	if ($ot le $t) {
+	if ($ot <= $t) {
 	    delete $noteoffs{$ot};
 	}
     }