From: Rudolf Polzer Date: Thu, 22 Mar 2018 00:15:46 +0000 (-0700) Subject: midichannels.pl: fix program or control change on more than one channel X-Git-Tag: xonotic-v0.8.5~174 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=8bd4153e3ad8e4f6a6963ba06fa2553e0c35c236;p=xonotic%2Fxonotic.git midichannels.pl: fix program or control change on more than one channel The previous code emitted only a MIDI event for the first channel - but we need one for all. --- diff --git a/misc/tools/midichannels.pl b/misc/tools/midichannels.pl index 944cf022..4f47b9fd 100755 --- a/misc/tools/midichannels.pl +++ b/misc/tools/midichannels.pl @@ -118,11 +118,11 @@ while() { my $tracks = $opus->tracks_r(); my ($track, $channel, $program) = @arg; - for(($track eq '*') ? (0..@$tracks-1) : $track) + for my $t(($track eq '*') ? (0..@$tracks-1) : $track) { my @events = (); - my $added = 0; - for(abstime $tracks->[$_]->events()) + my %added = (); + for(abstime $tracks->[$t]->events()) { my $p = $chanpos{$_->[0]}; if(defined $p) @@ -132,28 +132,28 @@ while() { next if $_->[0] eq 'patch_change'; - if(!$added) + if(!$added{$t}{$c}) { push @events, ['patch_change', $_->[1], $c-1, $program-1] if $program; - $added = 1; + $added{$t}{$c} = 1; } } } push @events, $_; } - $tracks->[$_]->events_r([reltime @events]); + $tracks->[$t]->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) + for my $t(($track eq '*') ? (0..@$tracks-1) : $track) { my @events = (); - my $added = 0; - for(abstime $tracks->[$_]->events()) + my %added = (); + for(abstime $tracks->[$t]->events()) { my $p = $chanpos{$_->[0]}; if(defined $p) @@ -163,17 +163,17 @@ while() { next if $_->[0] eq 'control_change' && $_->[3] == $control; - if(!$added) + if(!$added{$t}{$c}) { push @events, ['control_change', $_->[1], $c-1, $control, $value] if $value ne ''; - $added = 1; + $added{$t}{$c} = 1; } } } push @events, $_; } - $tracks->[$_]->events_r([reltime @events]); + $tracks->[$t]->events_r([reltime @events]); } } elsif($cmd eq 'transpose')