Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for midititl.pl

(view source code of midititl.pl as plain text)

  1. #! perl
  2.  
  3. # Store help text in a variable
  4. $syntax = "\nMidiTitl.pl,  Version 0.50 BETA\n";
  5. $syntax = $syntax."Display titles of specified MIDI file(s)\n\n";
  6. $syntax = $syntax."Usage:  MIDITITL.PL   filespec.mid\n\n";
  7. $syntax = $syntax."Where:  filespec.mid  is a (list of) MIDI file(s);\n";
  8. $syntax = $syntax."                      (wildcards allowed)\n\n";
  9. $syntax = $syntax."Written by Rob van der Woude\nhttp://www.robvanderwoude.com\n";
  10.  
  11. # Check command line argument(s), open specified MIDI file
  12. if ( !@ARGV[0] or @ARGV[1] ) {
  13. 	die( $syntax );
  14. } else {
  15. 	$midi = @ARGV[0];
  16. 	open( STDIN, "< $midi" ) or die "\nCannot open file $midi\n    $!\n    $^E\n\n$syntax";
  17. }
  18.  
  19. # Read MIDI file
  20. $line = "";
  21. while ( <STDIN> ) {
  22. 	$line = "$line $_";
  23. }
  24.  
  25. # Close MIDI file
  26. close STDIN;
  27.  
  28. # Remove excess white space
  29. $line =~ s/\s\s/ /g;
  30.  
  31. # Filter relevant output
  32. $string = "";
  33. $count  = 0;
  34. while ( $line ) {
  35. 	$count = $count + 1;
  36. 	if ( $line =~ m/([-_A-Z0-9\/\.,\s\(\)]{5,})(.*)$/i ) {
  37. 		chomp( $string = "$string $1" );
  38. 		$line = $2;
  39. 	}
  40. 	# Abort after 1000 iterations
  41. 	if ( $count > 1000 ) {
  42. 		$line = undef;
  43. 	}
  44. }
  45.  
  46. # Remove everything before first tab
  47. if ( $string =~ m/\t(.*)/ ) {
  48. 	$string = $1;
  49. }
  50.  
  51. # Display output
  52. print "\n$string\n";
  53.  

page last uploaded: 2017-04-06, 13:33