]> git.rm.cloudns.org Git - xonotic/xonotic.git/commitdiff
midichannels script: more commands
authorRudolf Polzer <divverent@xonotic.org>
Thu, 25 Oct 2012 12:52:55 +0000 (14:52 +0200)
committerRudolf Polzer <divverent@xonotic.org>
Thu, 25 Oct 2012 12:52:55 +0000 (14:52 +0200)
misc/tools/midichannels.pl

index 4df6978be9bb2cb790d4d5523d80feed46b7979d..cebf7ec959a2561343716fbadb758e5750bc4563 100755 (executable)
@@ -112,8 +112,8 @@ while(<STDIN>)
        elsif($cmd eq 'program')
        {
                my $tracks = $opus->tracks_r();
-               my ($channel, $program) = @arg;
-               for(0..@$tracks-1)
+               my ($track, $channel, $program) = @arg;
+               for(($track eq '*') ? (0..@$tracks-1) : $track)
                {
                        my @events = ();
                        my $added = 0;
@@ -123,7 +123,7 @@ while(<STDIN>)
                                if(defined $p)
                                {
                                        my $c = $_->[$p] + 1;
-                                       if($c == $channel)
+                                       if($channel eq '*' || $c == $channel)
                                        {
                                                next
                                                        if $_->[0] eq 'patch_change';
@@ -163,11 +163,34 @@ while(<STDIN>)
                        }
                }
        }
+       elsif($cmd eq 'channel')
+       {
+               my $tracks = $opus->tracks_r();
+               my ($track, %chanmap) = @arg;
+               for(($track eq '*') ? (0..@$tracks-1) : $track)
+               {
+                       my @events = ();
+                       for(abstime $tracks->[$_]->events())
+                       {
+                               my $p = $chanpos{$_->[0]};
+                               if(defined $p)
+                               {
+                                       my $c = $_->[$p] + 1;
+                                       $c = $chanmap{$c} // $chanmap{'*'} // $c;
+                                       next
+                                               if $c == 0; # kill by setting channel to 0
+                                       $_->[$p] = $c - 1;
+                               }
+                               push @events, $_;
+                       }
+                       $tracks->[$_]->events_r([reltime @events]);
+               }
+       }
        elsif($cmd eq 'percussion')
        {
                my $tracks = $opus->tracks_r();
-               my %map = @arg;
-               for(0..@$tracks-1)
+               my ($track, $channel, %map) = @arg;
+               for(($track eq '*') ? (0..@$tracks-1) : $track)
                {
                        my @events = ();
                        for(abstime $tracks->[$_]->events())
@@ -176,7 +199,7 @@ while(<STDIN>)
                                if(defined $p)
                                {
                                        my $c = $_->[$p] + 1;
-                                       if($c == 10)
+                                       if($channel eq '*' || $c == $channel)
                                        {
                                                if($_->[0] eq 'note_on' || $_->[0] eq 'note_off')
                                                {
@@ -277,9 +300,10 @@ while(<STDIN>)
                print "  dump\n";
                print "  ticks [value]\n";
                print "  retrack\n";
-               print "  program <channel> <program (1-based)>\n";
+               print "  program <track|*> <channel|*> <program (1-based)>\n";
                print "  transpose <track|*> <channel|*> <delta>\n";
-               print "  percussion <from> <to> [<from> <to> ...]\n";
+               print "  channel <track|*> <channel|*> <channel> [<channel> <channel> ...]\n";
+               print "  percussion <track|*> <channel|*> <from> <to> [<from> <to> ...]\n";
                print "  tracks [trackno] [trackno] ...\n";
        }
        print "Done with: $cmd @arg\n";