From e631e5cde3e2a5ceabf1aef98a48874f2ad68112 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Wed, 21 Mar 2018 17:04:21 -0700 Subject: [PATCH] midichannels.pl: Support overriding controller values too. --- misc/tools/midichannels.pl | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) 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"; -- 2.39.2