]> git.xonotic.org Git - xonotic/xonotic.git/blobdiff - misc/tools/midichannels.pl
midichannels: support multiple inputs
[xonotic/xonotic.git] / misc / tools / midichannels.pl
index dcc7812b9913eb8496b2a1248d2e884f71bf7ff1..bcfe626512a3d63e0c2728f335af206fffa13542 100644 (file)
@@ -5,7 +5,7 @@ use warnings;
 use MIDI;
 use MIDI::Opus;
 
-my ($filename) = @ARGV;
+my ($filename, @others) = @ARGV;
 my $opus = MIDI::Opus->new({from_file => $filename});
 
 my %chanpos = (
@@ -42,6 +42,20 @@ sub clean(@)
        return reltime grep { ($isclean{$_->[0]} // sub { 0; })->(@$_) } abstime @_;
 }
 
+for(@others)
+{
+       my $opus2 = MIDI::Opus->new({from_file => $_});
+       if($opus2->ticks() != $opus->ticks())
+       {
+               my $tickfactor = $opus->ticks() / $opus2->ticks();
+               for($opus2->tracks())
+               {
+                       $_->events(reltime map { $_->[1] = int($_->[1] * $tickfactor + 0.5); $_; } abstime $_->events());
+               }
+       }
+       $opus->tracks($opus->tracks(), $opus2->tracks());
+}
+
 while(<STDIN>)
 {
        chomp;