This snippet takes MIDI filenames on the command line and reads them in and dumps the necessary Perl code to recreate the MIDI file.

Updated! Now creates a complete Perl script.

#!/perl/bin/perl -w use strict; use MIDI; for my $midi (@ARGV) { open(*STDOUT, ">", "$midi.pl"); print <<'EOP'; #!/usr/bin/perl -w use MIDI; my $opus = EOP my $opus = MIDI::Opus->new({ 'from_file' => $midi, 'no_parse' => 1 } +); $opus->dump( { dump_tracks => 1 } ); print "\$opus->write_to_file('$midi');\n"; }

Replies are listed 'Best First'.
Re: Dump MIDI as Perl Code
by zentara (Cardinal) on Feb 18, 2003 at 17:11 UTC
    Well to save Mr. Muskrat some time, I will post the method he gave me to reconstruct a midi file from a mididump.txt.
    #put a "use MIDI;" at the top of the dump #and assign a variable $opus use MIDI; $opus=MIDI::Opus->new({ 'format' => 1, 'ticks' => 96, 'tracks' => [ # 3 tracks... ...... ...... ...... #then as the last line $opus->write_to_file('mynew.mid');
Re: Dump MIDI as Perl Code
by zentara (Cardinal) on Feb 18, 2003 at 15:34 UTC
    Works great. But what can you do with the midi.txt files?

      The txt file contains a snippet of Perl code that can be used to recreate the original MIDI file.

      I use it to verifiy that I have correctly added all of the approriate events to whatever MIDI I am working on.