]> git.rm.cloudns.org Git - xonotic/xonotic.git/commitdiff
midichannels.pl: Support overriding controller values too.
authorRudolf Polzer <divVerent@xonotic.org>
Thu, 22 Mar 2018 00:04:21 +0000 (17:04 -0700)
committerRudolf Polzer <divVerent@xonotic.org>
Thu, 22 Mar 2018 00:45:53 +0000 (17:45 -0700)
misc/tools/midichannels.pl

index 5462bbb8ed97cdbe434d76a05e2911de207dc6ec..f437733d81ea4fc99f653328689999b5ccd96e6c 100755 (executable)
@@ -2,8 +2,9 @@
 
 use strict;
 use warnings;
-use MIDI;
+use MIDI::Event;
 use MIDI::Opus;
+use MIDI::Track;
 
 my ($filename, @others) = @ARGV;
 my $opus = MIDI::Opus->new({from_file => $filename});
@@ -144,6 +145,37 @@ while(<STDIN>)
                        $tracks->[$_]->events_r([reltime @events]);
                }
        }
+       elsif($cmd eq 'control')
+       {
+               my $tracks = $opus->tracks_r();
+               my ($track, $channel, $control, $value) = @arg;
+               for(($track eq '*') ? (0..@$tracks-1) : $track)
+               {
+                       my @events = ();
+                       my $added = 0;
+                       for(abstime $tracks->[$_]->events())
+                       {
+                               my $p = $chanpos{$_->[0]};
+                               if(defined $p)
+                               {
+                                       my $c = $_->[$p] + 1;
+                                       if($channel eq '*' || $c == $channel)
+                                       {
+                                               next
+                                                       if $_->[0] eq 'control_change' && $_->[3] == $control;
+                                               if(!$added)
+                                               {
+                                                       push @events, ['control_change', $_->[1], $c-1, $control, $value]
+                                                               if $value ne '';
+                                                       $added = 1;
+                                               }
+                                       }
+                               }
+                               push @events, $_;
+                       }
+                       $tracks->[$_]->events_r([reltime @events]);
+               }
+       }
        elsif($cmd eq 'transpose')
        {
                my $tracks = $opus->tracks_r();
@@ -317,6 +349,7 @@ while(<STDIN>)
                print "  ticks [value]\n";
                print "  retrack\n";
                print "  program <track|*> <channel|*> <program (1-based)>\n";
+               print "  control <track|*> <channel|*> <control> <value>\n";
                print "  transpose <track|*> <channel|*> <delta>\n";
                print "  channel <track|*> <channel|*> <channel> [<channel> <channel> ...]\n";
                print "  percussion <track|*> <channel|*> <from> <to> [<from> <to> ...]\n";