1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
if __name__ == "__main__":
import argparse, sys, os
parser = argparse.ArgumentParser(description="Convert Laborejo Collections(.lbj) and Score (.lbjs) files to Midi/SMF.")
parser.add_argument('infiles', help="One or more lbj or lbjs files to convert to Midi/SMF.", nargs="*")
parser.add_argument("-o", "--out", help="Directory for Midi/SFM files. Default is the working directory", type=str)
parser.add_argument("-j", "--jack", help="Export Midis with Jack Settings instead Simple midi settings.", action="store_true")
parser.add_argument("-t", "--type", help="Export as type: 'file': Each Laborejo Track as midi file. 'port': All matching jack ports in one file. Default: All tracks in one file.", type=str)
parser.add_argument("-p", "--parts", help="Export multiple files, splitted by a track property. Most likely 'exportExtractPart'. Other reasonable choices: 'group', 'uniqueContainerName' (by track), 'shortInstrumentName'", default=None, type=str)
args = parser.parse_args()
import laborejocore as api #This starts the backend and automatically creates a session. But not score/tracks.
if args.out:
outdir = os.path.join(os.path.abspath(args.out), "")
else:
outdir = os.path.join(os.path.abspath(os.curdir), "")
if not os.path.isdir(outdir):
os.makedirs(outdir)
for filename in args.infiles:
filename = os.path.abspath(filename)
if filename.endswith("lbjs"):
api.load(filename)
basename = os.path.basename(filename) #Collections must have a filename. So we can depend on that
onlyfile = os.path.splitext(basename)[0]
midiname = onlyfile + ".mid"
api.exportMidi(os.path.join(outdir, midiname), jackMode = args.jack, parts = args.parts)
elif filename.endswith("lbj"):
api.load(filename)
api.exportMidi(os.path.join(outdir, os.path.basename(filename)), jackMode = args.jack, parts = args.parts)
sys.exit()
|