]> git.xonotic.org Git - xonotic/xonotic.git/blobdiff - misc/tools/midichannels.pl
Allow remapping a channel to multiple channels (to duplicate notes).
[xonotic/xonotic.git] / misc / tools / midichannels.pl
index cebf7ec959a2561343716fbadb758e5750bc4563..5462bbb8ed97cdbe434d76a05e2911de207dc6ec 100755 (executable)
@@ -62,7 +62,11 @@ while(<STDIN>)
        my @arg = split /\s+/, $_;
        my $cmd = shift @arg;
        print "Executing: $cmd @arg\n";
-       if($cmd eq 'clean')
+       if($cmd eq '#')
+       {
+               # Just a comment.
+       }
+       elsif($cmd eq 'clean')
        {
                my $tracks = $opus->tracks_r();
                $tracks->[$_]->events_r([clean($tracks->[$_]->events())])
@@ -152,7 +156,7 @@ while(<STDIN>)
                                if(defined $p)
                                {
                                        my $c = $_->[$p] + 1;
-                                       if($channel eq '*' || $c == $channel)
+                                       if($channel eq '*' ? $c != 10 : $c == $channel)
                                        {
                                                if($_->[0] eq 'note_on' || $_->[0] eq 'note_off')
                                                {
@@ -173,15 +177,20 @@ while(<STDIN>)
                        for(abstime $tracks->[$_]->events())
                        {
                                my $p = $chanpos{$_->[0]};
-                               if(defined $p)
+                               if(!defined $p)
                                {
-                                       my $c = $_->[$p] + 1;
-                                       $c = $chanmap{$c} // $chanmap{'*'} // $c;
+                                       push @events, $_;
+                                       next;
+                               }
+                               my $c = $_->[$p] + 1;
+                               my @c = split /,/, ($chanmap{$c} // $chanmap{'*'} // $c);
+                               for my $c(@c) {
                                        next
                                                if $c == 0; # kill by setting channel to 0
-                                       $_->[$p] = $c - 1;
+                                       my @copy = @$_;
+                                       $copy[$p] = $c - 1;
+                                       push @events, \@copy;
                                }
-                               push @events, $_;
                        }
                        $tracks->[$_]->events_r([reltime @events]);
                }
@@ -250,6 +259,8 @@ while(<STDIN>)
                                my %notehash = ();
                                my $t = 0;
                                my $events = 0;
+                               my $min = undef;
+                               my $max = undef;
                                for($tracks->[$_]->events())
                                {
                                        ++$events;
@@ -269,6 +280,11 @@ while(<STDIN>)
                                        $notehash{$_->[2]}{$_->[3]} = $t if $_->[0] eq 'note_on';
                                        $notehash{$_->[2]}{$_->[3]} = undef if $_->[0] eq 'note_off';
                                        $name = $_->[2] if $_->[0] eq 'track_name';
+                                       if($_->[0] eq 'note_on')
+                                       {
+                                               $min = $_->[3] if !defined $min || $_->[3] < $min;
+                                               $max = $_->[3] if !defined $max || $_->[3] > $max;
+                                       }
                                }
                                my $channels = join " ", map { sprintf "%s(%s)", $_, join ",", sort { $a <=> $b } keys %{$channels{$_}} } sort { $a <=> $b } keys %channels;
                                my @stuck = ();
@@ -283,7 +299,7 @@ while(<STDIN>)
                                print " $name" if defined $name;
                                print " (channel $channels)" if $channels ne "";
                                print " ($events events)" if $events;
-                               print " ($notes notes)" if $notes;
+                               print " ($notes notes [$min-$max])" if $notes;
                                print " (notes @stuck stuck)" if @stuck;
                                print "\n";
                        }