8 my ($filename, @others) = @ARGV;
9 my $opus = MIDI::Opus->new({from_file => $filename});
17 channel_after_touch => 2,
18 pitch_wheel_change => 2
22 set_tempo => sub { 1; },
23 note_off => sub { 1; },
24 note_on => sub { 1; },
25 control_change => sub { $_[3] == 64; },
31 return map { [$_->[0], $t += $_->[1], @{$_}[2..(@$_-1)]]; } @_;
37 return map { my $tsave = $t; $t = $_->[1]; [$_->[0], $t - $tsave, @{$_}[2..(@$_-1)]]; } @_;
42 return reltime grep { ($isclean{$_->[0]} // sub { 0; })->(@$_) } abstime @_;
47 my $opus2 = MIDI::Opus->new({from_file => $_});
48 if($opus2->ticks() != $opus->ticks())
50 my $tickfactor = $opus->ticks() / $opus2->ticks();
53 $_->events(reltime map { $_->[1] = int($_->[1] * $tickfactor + 0.5); $_; } abstime $_->events());
56 $opus->tracks($opus->tracks(), $opus2->tracks());
62 my @arg = split /\s+/, $_;
64 print "Executing: $cmd @arg\n";
67 my $tracks = $opus->tracks_r();
68 $tracks->[$_]->events_r([clean($tracks->[$_]->events())])
73 print $opus->dump({ dump_tracks => 1 });
75 elsif($cmd eq 'ticks')
79 $opus->ticks($arg[0]);
83 print "Ticks: ", $opus->ticks(), "\n";
86 elsif($cmd eq 'tricks')
88 print "haha, very funny\n";
90 elsif($cmd eq 'tracks')
92 my $tracks = $opus->tracks_r();
105 next if $taken{$_}++ and not $force;
106 push @t, $tracks->[$_];
108 $opus->tracks_r(\@t);
121 for($tracks->[$_]->events())
124 $_->[0] = 'note_off' if $_->[0] eq 'note_on' and $_->[4] == 0;
126 my $p = $chanpos{$_->[0]};
129 my $c = $_->[$p] + 1;
132 ++$notes if $_->[0] eq 'note_on';
133 $notehash{$_->[2]}{$_->[3]} = $t if $_->[0] eq 'note_on';
134 $notehash{$_->[2]}{$_->[3]} = undef if $_->[0] eq 'note_off';
135 $name = $_->[2] if $_->[0] eq 'track_name';
137 my $channels = join " ", sort keys %channels;
139 while(my ($k1, $v1) = each %notehash)
141 while(my ($k2, $v2) = each %$v1)
143 push @stuck, sprintf "%d:%d@%.1f%%", $k1+1, $k2, $v2 * 100.0 / $t
147 print " $name" if defined $name;
148 print " (channel $channels)" if $channels ne "";
149 print " ($events events)" if $events;
150 print " ($notes notes)" if $notes;
151 print " (notes @stuck stuck)" if @stuck;
156 elsif($cmd eq 'save')
158 $opus->write_to_file($arg[0]);
162 print "Unknown command, allowed commands: ticks, tracks, clean, save\n";
164 print "Done with: $cmd @arg\n";