diff -r 377c84f956dc -r 193999e56a90 xml2b40.py --- a/xml2b40.py Tue May 26 11:43:51 2020 +0200 +++ b/xml2b40.py Thu Jun 08 09:40:19 2023 +0200 @@ -12,10 +12,11 @@ ''' import operator, sys, os import xml.etree.ElementTree as E +from functools import reduce b40List = ['Cbb','Cb','C','C#','C##','-','Dbb','Db','D','D#','D##','-','Ebb','Eb','E','E#','E##','Fbb','Fb','F', 'F#','F##','-','Gbb','Gb','G','G#','G##','-','Abb','Ab','A','A#','A##','-','Bbb','Bb','B','B#','B##'] -b40Dict = dict (zip (b40List, range (len (b40List)))) +b40Dict = dict (list (zip(b40List, range(len (b40List))))) gtikkenPerKwart = 384 # ticks per quarter note gC5 = False # central C == C5 if gC5 else C4 @@ -69,7 +70,7 @@ global tijd t = vtimes [v] if tijd > t: voices [v].append ([tijd - t, t, 'z']) - if tijd < t: raise 'kenniet' + if tijd < t: raise Exception ('kenniet') voices [v].append ([dur, tijd, noot]) tijd += int (dur) vtimes[v] = tijd @@ -86,8 +87,8 @@ def outMaat (i, mbuf, ns): for nx in mbuf: - dur = nx[0] * gTikkenPerKwart / durUnit - tijd = nx[1] * gTikkenPerKwart / durUnit + dur = int (nx[0] * gTikkenPerKwart / durUnit) + tijd = int (nx[1] * gTikkenPerKwart / durUnit) if not dur: continue # alleen echte noten for noot in nx[2:]: # de noot of noten in chord if 'z' in noot: continue # skip rusten @@ -105,7 +106,7 @@ noten.append ((tieBufTijd [noot], noot, tieBufDur[noot])) tieBufTijd [noot] = tijd # alle noten vast houden voor evt. volgende tie tieBufDur [noot] = dur - for noot, dur in tieBufDur.iteritems (): # alle vastgehouden noten nu uitvoeren + for noot, dur in tieBufDur.items (): # alle vastgehouden noten nu uitvoeren noten.append ((tieBufTijd[noot], noot, dur)) def outVoices (vceCnt): # output alle stemmen in een part, nummering begint bij vceCnt @@ -144,7 +145,7 @@ for p in parts: maten = p.findall ('measure') for maat in maten: - es = maat.getchildren () + es = list (maat) # alle kinderen van maat for e in es: if e.tag == 'note': doNote (e) elif e.tag == 'attributes': doAttr (e) @@ -169,7 +170,7 @@ if __name__ == '__main__': from optparse import OptionParser - parser = OptionParser (usage='%prog [-h] [-g TPQ] [--C5] ') + parser = OptionParser (usage='%prog [-h] [-t TPQ] [--C5] [-w] ') parser.add_option ("-t", action="store", type="int", help="ticks per quarternote", default=120, metavar='TPQ') parser.add_option ("--C5", action="store_true", help="central C is C5", default=False) parser.add_option ("-w", action="store_true", help="write .b40 file", default=False) @@ -184,6 +185,6 @@ g = file (fnm + '.b40', 'w') for tijd, noot in noten: g.write ('%d %s\n' % (tijd, noot)) g.close () - print fnm + '.b40 written' + print(fnm + '.b40 written') else: - for tijd, noot in noten: print tijd, noot + for tijd, noot in noten: print(tijd, noot)