fix printing and add option to hide unused instruments
This commit is contained in:
parent
78ab87cfbf
commit
756cf79423
1 changed files with 36 additions and 9 deletions
45
stt.py
45
stt.py
|
|
@ -42,9 +42,10 @@ def commandline():
|
||||||
# option without argument via 'store_true'
|
# option without argument via 'store_true'
|
||||||
parser.add_argument("-V", "--version", help="show program version", action="store_true")
|
parser.add_argument("-V", "--version", help="show program version", action="store_true")
|
||||||
# option with argument
|
# option with argument
|
||||||
parser.add_argument("--width", "-w", help="set output width in measures")
|
parser.add_argument("--width", "-w", help="set output width in measures (default: 2)")
|
||||||
parser.add_argument("--input", "-i", help="set input file")
|
parser.add_argument("--input", "-i", help="set input file")
|
||||||
parser.add_argument("--url", "-u", help="set input url")
|
parser.add_argument("--url", "-u", help="set input url")
|
||||||
|
parser.add_argument("--exclude", "-x", help="exclude unused instruments", action="store_true")
|
||||||
|
|
||||||
# read arguments from the command line
|
# read arguments from the command line
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
@ -56,6 +57,8 @@ def commandline():
|
||||||
# check for --width
|
# check for --width
|
||||||
if args.width:
|
if args.width:
|
||||||
print("set output width to %s" % args.width)
|
print("set output width to %s" % args.width)
|
||||||
|
else:
|
||||||
|
args.width = 2
|
||||||
if args.url:
|
if args.url:
|
||||||
print("url not handled yet %s" % args.width)
|
print("url not handled yet %s" % args.width)
|
||||||
if args.input and args.url:
|
if args.input and args.url:
|
||||||
|
|
@ -108,6 +111,18 @@ def parse_instruments(jsondata):
|
||||||
# That'll make for easy printing
|
# That'll make for easy printing
|
||||||
|
|
||||||
|
|
||||||
|
used_instr = {
|
||||||
|
"Cr": False,
|
||||||
|
"Hh": False,
|
||||||
|
"Ri": False,
|
||||||
|
"HT": False,
|
||||||
|
"MT": False,
|
||||||
|
"Sn": False,
|
||||||
|
"FT": False,
|
||||||
|
"Bd": False,
|
||||||
|
"Hf": False
|
||||||
|
}
|
||||||
|
|
||||||
instruments = {
|
instruments = {
|
||||||
"Cr": [],
|
"Cr": [],
|
||||||
"Hh": [],
|
"Hh": [],
|
||||||
|
|
@ -145,17 +160,30 @@ def parse_instruments(jsondata):
|
||||||
#print(measurecnt, inst, count)
|
#print(measurecnt, inst, count)
|
||||||
if inst != None:
|
if inst != None:
|
||||||
instruments[inst][-1][count] = marker
|
instruments[inst][-1][count] = marker
|
||||||
|
used_instr[inst] = True
|
||||||
else:
|
else:
|
||||||
print("Unhandled: " + note + " in measure " + str(measurecnt+1))
|
print("Unhandled: " + note + " in measure " + str(measurecnt+1))
|
||||||
print("Add: " + str(( note["string"] * 1000 ) + note["fret"]) + " to lookuptable")
|
print("Add: " + str(( note["string"] * 1000 ) + note["fret"]) + " to lookuptable")
|
||||||
count += skip
|
count += skip
|
||||||
|
|
||||||
return instruments
|
return instruments, used_instr
|
||||||
|
|
||||||
def print_instruments(instruments):
|
def print_instruments(instruments, used_instr):
|
||||||
for instr in ["Cr", "Hh", "Ri", "HT", "MT", "Sn", "FT", "Bd", "Hf"]:
|
measuresnr = len(instruments["Cr"])
|
||||||
for i in range(len(instruments["Cr"])):
|
width = int(args.width)
|
||||||
print(instr + " " + "".join(instruments[instr][i]))
|
|
||||||
|
rows = ( measuresnr / width )
|
||||||
|
count = 0
|
||||||
|
while count < measuresnr:
|
||||||
|
for instr in ["Cr", "Hh", "Ri", "HT", "MT", "Sn", "FT", "Bd", "Hf"]:
|
||||||
|
if not args.exclude or used_instr[instr]:
|
||||||
|
sys.stdout.write(instr + " |")
|
||||||
|
for i in range(count, count+width):
|
||||||
|
if i < measuresnr:
|
||||||
|
sys.stdout.write("".join(instruments[instr][i]) + "|")
|
||||||
|
print("")
|
||||||
|
print("")
|
||||||
|
count += width
|
||||||
|
|
||||||
args = commandline()
|
args = commandline()
|
||||||
|
|
||||||
|
|
@ -165,6 +193,5 @@ with open(args.input, 'r') as content_file:
|
||||||
jsondata = get_json(content)
|
jsondata = get_json(content)
|
||||||
print_meta(jsondata)
|
print_meta(jsondata)
|
||||||
|
|
||||||
instr = parse_instruments(jsondata)
|
instr, used_instr = parse_instruments(jsondata)
|
||||||
print_instruments(instr)
|
print_instruments(instr, used_instr)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue