-
Notifications
You must be signed in to change notification settings - Fork 5
/
gestalt-file
55 lines (42 loc) · 1.62 KB
/
gestalt-file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env perl
use strict;
use warnings;
# Inspect the pitch and velocity boundaries for each channel
use MIDI;
use Music::Gestalt;
use Music::Note;
my $file = shift || die "Usage: perl $0 /some/file.mid\n";
my $opus = MIDI::Opus->new( { from_file => $file } );
my $i = 0;
# Convert tracks to score
for my $t ( $opus->tracks ) {
$i++;
my @events = $t->events;
my %seen;
for my $e ( @events ) {
if ($e->[0] eq 'note_on') {
push @{ $seen{ $e->[2] } }, $e; # Tally the channel events
}
}
next unless keys %seen;
for my $channel ( sort { $a <=> $b } keys %seen ) {
my $score_r = MIDI::Score::events_r_to_score_r( $seen{$channel} );
$score_r = MIDI::Score::sort_score_r($score_r);
my $ticks = MIDI::Score::score_r_time($score_r);
my $g = Music::Gestalt->new( score => $score_r );
my $note = Music::Note->new( $g->PitchLowest, 'midinum' );
my $low = $note->format('midi');
$note = Music::Note->new( $g->PitchHighest, 'midinum' );
my $high = $note->format('midi');
$note = Music::Note->new( $g->PitchMiddle, 'midinum' );
my $mid = $note->format('midi');
print "Track:\t\t$i\n",
"Channel:\t$channel\n",
"Events:\t\t", scalar( @{ $seen{$channel} } ), "\n",
"Ticks:\t\t$ticks\n",
"Pitch:\t\tRange: $low to $high\n",
"\t\tSpan: $mid ± ", $g->PitchRange, "\n",
"Velocity:\tRange: ", $g->VelocityLowest, ' to ', $g->VelocityHighest, "\n",
"\t\tSpan: ", $g->VelocityMiddle, ' ± ', $g->VelocityRange, "\n\n";
}
}