def expandchannels(mfiles, outputdir):
  for f in mfiles:
    print 'Loading {0}'.format(f)
    mf = representation.MidiFile(f)
    if not mf: continue
    if not mf.format == 0:
      os.system('cp {0} {1}'.format(f, outputdir))
      continue
    newfile = mf['0'].channels2tracks()
    (name, version, track, singletrack) = files.parsename(mf.name)
    print 'Calling exportMidi("{0}")'.format('{0}{1}'.format(outputdir, files.generatefilename(name, version)))
    newfile.exportMidi('{0}{1}'.format(outputdir, files.generatefilename(name, version)))
def filtertracks(inputdir, outputdir):
  tracks = filter(files.paths(inputdir))
  import os
  if not os.path.exists(outputdir):
    os.mkdir(outputdir)
  
  for track in tracks:
    (name, version, t, singletrack) = files.parsename(track.midifile.name)
    f = '{0}{1}'.format(outputdir, files.generatefilename(name, version, track.n, True))
    print 'saving {0}'.format(f)
    track.save(f)