From 8bd4153e3ad8e4f6a6963ba06fa2553e0c35c236 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Wed, 21 Mar 2018 17:15:46 -0700 Subject: [PATCH] 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. --- misc/tools/midichannels.pl | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) 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') -- 2.39.2