shiv.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # IV file viewer
  2. import xml.etree.ElementTree as ET
  3. import optparse
  4. import sys
  5. parser = optparse.OptionParser()
  6. parser.add_option('-n', '--number', dest='number', action='store_true', help='Show number of tracks')
  7. parser.add_option('-g', '--groups', dest='groups', action='store_true', help='Show group names')
  8. parser.add_option('-N', '--notes', dest='notes', action='store_true', help='Show number of notes')
  9. parser.add_option('-m', '--meta', dest='meta', action='store_true', help='Show meta track information')
  10. parser.add_option('-h', '--histogram', dest='histogram', action='store_true', help='Show a histogram distribution of pitches')
  11. parser.add_option('-H', '--histogram-tracks', dest='histogram_tracks', action='store_true', help='Show a histogram distribution of pitches per track')
  12. parser.add_option('-d', '--duration', dest='duration', action='store_true', help='Show the duration of the piece')
  13. parser.add_option('-D', '--duty-cycle', dest='duty_cycle', action='store_true', help='Show the duration of the notes within tracks, and as a percentage of the piece duration')
  14. parser.add_option('-a', '--almost-all', dest='almost_all', action='store_true', help='Show useful information')
  15. parser.add_option('-A', '--all', dest='all', action='store_true', help='Show everything')
  16. options, args = parser.parse_args()
  17. if options.almost_all or options.all:
  18. options.number = True
  19. options.groups = True
  20. options.notes = True
  21. options.histogram = True
  22. options.duration = True
  23. if options.all:
  24. options.meta = True
  25. options.histogram_tracks= True
  26. options.duty_cycle = True
  27. for fname in args:
  28. try:
  29. iv = ET.parse(fname).getroot()
  30. except IOError:
  31. import traceback
  32. traceback.print_exc()
  33. print 'Bad file :', fname, ', skipping...'
  34. continue
  35. print
  36. print 'File :', fname
  37. print '\t<computing...>'