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
43
stt.py
43
stt.py
|
|
@ -42,9 +42,10 @@ def commandline():
|
|||
# option without argument via 'store_true'
|
||||
parser.add_argument("-V", "--version", help="show program version", action="store_true")
|
||||
# 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("--url", "-u", help="set input url")
|
||||
parser.add_argument("--exclude", "-x", help="exclude unused instruments", action="store_true")
|
||||
|
||||
# read arguments from the command line
|
||||
args = parser.parse_args()
|
||||
|
|
@ -56,6 +57,8 @@ def commandline():
|
|||
# check for --width
|
||||
if args.width:
|
||||
print("set output width to %s" % args.width)
|
||||
else:
|
||||
args.width = 2
|
||||
if args.url:
|
||||
print("url not handled yet %s" % args.width)
|
||||
if args.input and args.url:
|
||||
|
|
@ -108,6 +111,18 @@ def parse_instruments(jsondata):
|
|||
# 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 = {
|
||||
"Cr": [],
|
||||
"Hh": [],
|
||||
|
|
@ -145,17 +160,30 @@ def parse_instruments(jsondata):
|
|||
#print(measurecnt, inst, count)
|
||||
if inst != None:
|
||||
instruments[inst][-1][count] = marker
|
||||
used_instr[inst] = True
|
||||
else:
|
||||
print("Unhandled: " + note + " in measure " + str(measurecnt+1))
|
||||
print("Add: " + str(( note["string"] * 1000 ) + note["fret"]) + " to lookuptable")
|
||||
count += skip
|
||||
|
||||
return instruments
|
||||
return instruments, used_instr
|
||||
|
||||
def print_instruments(instruments):
|
||||
def print_instruments(instruments, used_instr):
|
||||
measuresnr = len(instruments["Cr"])
|
||||
width = int(args.width)
|
||||
|
||||
rows = ( measuresnr / width )
|
||||
count = 0
|
||||
while count < measuresnr:
|
||||
for instr in ["Cr", "Hh", "Ri", "HT", "MT", "Sn", "FT", "Bd", "Hf"]:
|
||||
for i in range(len(instruments["Cr"])):
|
||||
print(instr + " " + "".join(instruments[instr][i]))
|
||||
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()
|
||||
|
||||
|
|
@ -165,6 +193,5 @@ with open(args.input, 'r') as content_file:
|
|||
jsondata = get_json(content)
|
||||
print_meta(jsondata)
|
||||
|
||||
instr = parse_instruments(jsondata)
|
||||
print_instruments(instr)
|
||||
|
||||
instr, used_instr = parse_instruments(jsondata)
|
||||
print_instruments(instr, used_instr)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue