Revision 3:5abb6a523d27 midisort.pl
| midisort.pl | ||
|---|---|---|
| 3 | 3 |
# read the output from midifile, sort it into "note column" groups |
| 4 | 4 |
|
| 5 | 5 |
my $timebase = 120; |
| 6 |
my $beatsperbar = 3; |
|
| 6 |
my $beatsperbar = 4; |
|
| 7 |
my $seentimesig = 0; |
|
| 7 | 8 |
|
| 8 | 9 |
sub fmtm { # function to convert time to bar number
|
| 9 | 10 |
int($_[0] / ($timebase * $beatsperbar)) + 1; |
| ... | ... | |
| 32 | 33 |
$c = $2; |
| 33 | 34 |
$d = $3; |
| 34 | 35 |
$p = $4; |
| 36 |
} elsif (/^Timing division: (\d+)/) {
|
|
| 37 |
$timebase = $1; |
|
| 38 |
print STDERR "Set timebase to $timebase from input data\n"; |
|
| 39 |
next; |
|
| 40 |
} elsif (/^(\d+): Time signature: (\d+)\//) {
|
|
| 41 |
if ($seentimesig != 0 && $beatsperbar != $2) {
|
|
| 42 |
print STDERR "WARNING: File uses more than one time signature, not supported here\n"; |
|
| 43 |
} |
|
| 44 |
$beatsperbar = $2; |
|
| 45 |
$seentimesig++; |
|
| 46 |
print STDERR "Set beat count per bar to $beatsperbar from input data\n"; |
|
| 47 |
next; |
|
| 48 |
} elsif (/^SMPTE/) {
|
|
| 49 |
print STDERR "WARNING: File uses SMPTE timing, expect incorrect results\n"; |
|
| 50 |
next; |
|
| 35 | 51 |
} else {
|
| 36 | 52 |
next; |
| 37 | 53 |
} |
| ... | ... | |
| 77 | 93 |
|
| 78 | 94 |
for my $ot (keys %noteoffs) {
|
| 79 | 95 |
# prune notes that have ended already or are ending now |
| 80 |
if ($ot le $t) {
|
|
| 96 |
if ($ot <= $t) {
|
|
| 81 | 97 |
delete $noteoffs{$ot};
|
| 82 | 98 |
} |
| 83 | 99 |
} |
Also available in: Unified diff