8 my ($filename) = @ARGV;
9 my $opus = MIDI::Opus->new({from_file => $filename});
17 channel_after_touch => 2,
18 pitch_wheel_change => 2
24 my @arg = split /\s+/, $_;
26 print "Executing: $cmd @arg\n";
31 $opus->ticks($arg[0]);
35 print "Ticks: ", $opus->ticks(), "\n";
38 elsif($cmd eq 'tricks')
40 print "haha, very funny\n";
42 elsif($cmd eq 'tracks')
44 my $tracks = $opus->tracks_r();
48 my @t = ($tracks->[0]);
57 next if $taken{$_}++ and not $force;
58 push @t, $tracks->[$_];
72 for($tracks->[$_]->events())
74 $_->[0] = 'note_off' if $_->[0] eq 'note_on' and $_->[4] == 0;
76 my $p = $chanpos{$_->[0]};
82 ++$notes if $_->[0] eq 'note_on';
83 $notehash{$_->[2]}{$_->[3]} = $t if $_->[0] eq 'note_on';
84 $notehash{$_->[2]}{$_->[3]} = undef if $_->[0] eq 'note_off';
85 $name = $_->[2] if $_->[0] eq 'track_name';
87 my $channels = join " ", sort keys %channels;
89 while(my ($k1, $v1) = each %notehash)
91 while(my ($k2, $v2) = each %$v1)
93 push @stuck, sprintf "%d:%d@%.1f%%", $k1+1, $k2, $v2 * 100.0 / $t
97 print " $name" if defined $name;
98 print " (channel $channels)" if $channels ne "";
99 print " ($notes notes)" if $notes;
100 print " (notes @stuck stuck)" if @stuck;
105 elsif($cmd eq 'save')
107 $opus->write_to_file($arg[0]);
111 print "Unknown command, allowed commands: ticks, tricks, tracks, save\n";
113 print "Done with: $cmd @arg\n";