--- a/segLibB40.py Tue May 26 11:43:51 2020 +0200
+++ b/segLibB40.py Thu Jun 08 09:40:19 2023 +0200
@@ -146,7 +146,7 @@
for p in g:
if p > 0: klinkt.append (p)
elif -p in klinkt: klinkt.remove (-p)
- else: print 'unmatched off-message'
+ else: print('unmatched off-message')
kgroep.append ((t, klinkt[:]))
return kgroep
@@ -167,7 +167,7 @@
return wtot
def analyseK (kgroep, debug=0):
- if debug: print 'aantal segmenten', len (kgroep)
+ if debug: print('aantal segmenten', len (kgroep))
#~ mkWeights (kgroep)
#~ mkTemplates ()
@@ -189,14 +189,14 @@
s01, acc01, xs01 = s012, acc012, xs012
else:
segs.append ((j0,j1,s0,acc0,xs0))
- if debug: print j0, j1, s0, acc0
+ if debug: print(j0, j1, s0, acc0)
j0, j1, j2 = j1, j2, j2 + 1
s0, acc0, xs0 = s1, acc1, xs1
s01, acc01, xs01 = s12, acc12, xs12
s1, acc1, xs1 = s2, acc2, xs2
if j0 < len (weights):
segs.append ((j0,j1,s0,acc0,xs0))
- if debug: print j0, j1, s0, acc0
+ if debug: print(j0, j1, s0, acc0)
return segs, kgroep
@@ -204,14 +204,14 @@
f = open ('mids/bwv539p.b40')
xs = f.readlines ()
f.close ()
- def toint (xs): return map (lambda x: int (x), xs)
- events = map (lambda x: toint (x.strip().split()), xs)
+ def toint (xs): return [int (x) for x in xs]
+ events = [toint (x.strip().split()) for x in xs]
kgroep = readEvents (events)
mkWeights (kgroep)
mkTemplates ()
segs, kgroep = analyseK (kgroep, debug=0)
- print '%d segs, %d groepen' % (len (segs), len (kgroep))
+ print('%d segs, %d groepen' % (len (segs), len (kgroep)))
for iseg, jseg, score, acc, rest in segs:
- print '---', acc, score
+ print('---', acc, score)
for t, ns in kgroep [iseg:jseg]:
- print t, ', '.join (map (b40nm, ns))
+ print(t, ', '.join (map (b40nm, ns)))
--- 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] <file1>')
+ parser = OptionParser (usage='%prog [-h] [-t TPQ] [--C5] [-w] <file1>')
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)
--- a/xmlChordAna.py Tue May 26 11:43:51 2020 +0200
+++ b/xmlChordAna.py Thu Jun 08 09:40:19 2023 +0200
@@ -1,7 +1,7 @@
-#!/usr/bin/env python
-# coding: latin-1
+#!/usr/bin/env python3
-import fractions, os, xml2b40
+import os, xml2b40
+import fractions as F
import segLibB40 as S
def keySeg (iseg,jseg):
@@ -31,13 +31,14 @@
percnt = 100. * score / totNotes
regels.append ('---- chord %s, score: %.0f%%' % (chord, percnt))
for tikken, noten in grpsInSeg:
- noten = ', '.join ([S.b40nm (n) + str(n / 40) for n in noten])
- x = fractions.Fraction (tikken, tikkenPerKwart)
- t = x.numerator / x.denominator
+ noten = ', '.join ([S.b40nm (n) + str(int (n / 40)) for n in noten])
+ x = F.Fraction (tikken, tikkenPerKwart)
+ n, d = x.numerator, x.denominator
+ t = int (n / d)
r = x - t
if r == 0: r = ''
regels.append ('%4d %3s %s' % (t, r, noten))
- return regels
+ return regels
if __name__ == '__main__':
from optparse import OptionParser
@@ -53,4 +54,4 @@
noten = xml2b40.xml2b40 (fnmext, options.t, options.C5)
regels = mkAna (noten, fnmext)
- print '\n'.join (regels)
+ print ('\n'.join (regels))