From: Rudolf Polzer Date: Thu, 22 Mar 2018 00:04:21 +0000 (-0700) Subject: midichannels.pl: Support overriding controller values too. X-Git-Tag: xonotic-v0.8.5~176 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=e631e5cde3e2a5ceabf1aef98a48874f2ad68112;p=xonotic%2Fxonotic.git midichannels.pl: Support overriding controller values too. --- diff --git a/misc/tools/midichannels.pl b/misc/tools/midichannels.pl index 5462bbb8..f437733d 100755 --- a/misc/tools/midichannels.pl +++ b/misc/tools/midichannels.pl @@ -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() $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() print " ticks [value]\n"; print " retrack\n"; print " program \n"; + print " control \n"; print " transpose \n"; print " channel [ ...]\n"; print " percussion [ ...]\n";