Re: MIDI::Score
[email protected] (Dave Turner) Fri, 23 May 2003 21:16:30 +0000
| Newsgroups | perl.midi |
|---|---|
| Message-ID | <a05100300baf427533b3d@[81.174.193.37]> |
The listing below now works and prints out the score for westminster
chimes.mid as shown in the MIDI::Score documentation.
Large midi files fill up the MacPerl output window so "sub dump_score" became
"sub dump_score_to_file" and I got it working at the third attempt.
Thanks Sean, but remember, Monkey See Monkey Do.
Leave 4 lines of code out of your POD and it gives Perl newbies like
me a real headache!
Do I write proper documentation for my own stuff, and also for what I
do at work?
Yes!
DaveT
I did the change suggested by Sean, and it worked. Hurray!
Then I went back to my original and added "use strict".
The error returned was:-
# Global symbol "@opus" requires explicit package name.
It took a good half hour of shuffling to and fro through The Camel
Book before I saw anything that looked like the answer given by Sean.
(in Chapter 12:Objects)
#!perl
# mp-score this attempts to list the midi track as a score
# using MacPerl 5.6.1r2 for Mac OS 9.2.2
use warnings;
use strict;
use MIDI;
my $DRIVE = 'Stuff:';
my $PATH = 'temptemp:';
my $MIDI = 'westminster_chimes4.mid';
my $IN_FILE = $DRIVE.$PATH.$MIDI;
my $opus = MIDI::Opus->new({ 'from_file' => $IN_FILE });
print "$IN_FILE has ", scalar( $opus->tracks ), " tracks\n";
# my $event_r = \@opus; # this does NOT work
# my $event_r = ( $opus->tracks ) [0]->events_r; # THIS WORKS!!!!
my $event_r = $opus->tracks_r->[0]->events_r; # THIS WORKS TOO!!!!
my $score_r = MIDI::Score::events_r_to_score_r($event_r);
MIDI::Score::dump_score( $score_r);
exit;