#! /usr/bin/perl ######################################################################### # This Perl script is Copyright (c) 2006, Peter J Billam # # c/o P J B Computing, GPO Box 669, Hobart TAS 7001, Australia # # # # This script is free software; you can redistribute it and/or # # modify it under the same terms as Perl itself. # ######################################################################### eval 'require MIDI'; if ($@) { die "you'll need to install the MIDI::Perl module from www.cpan.org\n"; } import MIDI; eval 'require Term::Clui'; if ($@) { die "you'll need to install the Term::Clui module from www.cpan.org\n"; } import Term::Clui; my $Version = '1.2'; while ($ARGV[$[] =~ /^-(\w)/) { if ($1 eq 'c') { shift; } else { my $n = $0; $n =~ s#^.*/([^/]+)$#$1#; print <new({ 'from_file' => $ARGV[$[]}); open(SAVEOUT, ">&STDOUT") || die "couldn't dup STDOUT: $!"; close STDOUT; if (! open(STDOUT, ">$tmp")) { die "can't open $tmp: $!\n"; } print "# see perldoc MIDI::Event\n\$newopus = "; $opus->dump({'dump_tracks'=>1}); close STDOUT; while (1) { open(STDOUT, ">&SAVEOUT") || die "couldn't dup SAVEOUT: $!"; &edit ($tmp); unless ($return = do $tmp) { warn "couldn't parse $tmp: $@\n" if $@; warn "couldn't do $tmp: $!\n" unless defined $return; warn "couldn't run $tmp\n" unless $return; } last if $newopus; last unless &confirm("MIDI::Opus syntax error. OK to re-edit ?"); } unlink $tmp; $Debug=0; if ($Debug) { $newopus->dump({'dump_tracks'=>1}); exit; } $newopus->write_to_file( $ARGV[$[] ); =pod =head1 NAME midiedit - Edits a MIDI file in a text format provided by MIDI::Perl =head1 SYNOPSIS midiedit filename.mid =head1 DESCRIPTION Edits a MIDI file in the human-readable text-format provided by I's $opus->dump function. The text format representing the MIDI is executable Perl source, so as you edit, you should preserve valid Perl syntax. If the edited file has syntax errors, you will be asked if you want to re-edit it, and if you reply No then the original file will not get over-written. If you've changed the text, and then decide you want to quit without overwriting the MIDI file, then you have to deliberately mess up the Perl syntax (e.g. make sure the brackets are unbalanced). Assuming you've installed MIDI::Perl, then C should document the format in which the various MIDI-events are represented. This is midiedit version 1.2 =head1 AUTHOR Peter J Billam http://www.pjb.com.au/comp/contact.html =head1 CREDITS Based on Sean Burke's I CPAN module; also uses Peter Billam's I CPAN module. =head1 SEE ALSO http://search.cpan.org/~sburke http://search.cpan.org/~pjb http://www.pjb.com.au/muscript http://www.pjb.com.au/midi =cut