segLibB40.py
changeset 6 193999e56a90
parent 1 7fd6cac1a69d
equal deleted inserted replaced
5:377c84f956dc 6:193999e56a90
   144     kgroep = []
   144     kgroep = []
   145     for t, g in merged:
   145     for t, g in merged:
   146         for p in g:
   146         for p in g:
   147             if p > 0: klinkt.append (p)
   147             if p > 0: klinkt.append (p)
   148             elif -p in klinkt: klinkt.remove (-p)
   148             elif -p in klinkt: klinkt.remove (-p)
   149             else: print 'unmatched off-message'
   149             else: print('unmatched off-message')
   150         kgroep.append ((t, klinkt[:]))
   150         kgroep.append ((t, klinkt[:]))
   151     return kgroep
   151     return kgroep
   152 
   152 
   153 def mkWeights (kgroep):
   153 def mkWeights (kgroep):
   154     global weights
   154     global weights
   165         for i, w in enumerate (ws):
   165         for i, w in enumerate (ws):
   166             wtot [i] += w
   166             wtot [i] += w
   167     return wtot
   167     return wtot
   168 
   168 
   169 def analyseK (kgroep, debug=0):
   169 def analyseK (kgroep, debug=0):
   170     if debug: print 'aantal segmenten', len (kgroep)
   170     if debug: print('aantal segmenten', len (kgroep))
   171 
   171 
   172     #~ mkWeights (kgroep)
   172     #~ mkWeights (kgroep)
   173     #~ mkTemplates ()
   173     #~ mkTemplates ()
   174 
   174 
   175     j0, j1, j2 = 0,1,2
   175     j0, j1, j2 = 0,1,2
   187             j1, j2 = j2, j2 + 1
   187             j1, j2 = j2, j2 + 1
   188             s0, acc0, xs0 = s01, acc01, xs01
   188             s0, acc0, xs0 = s01, acc01, xs01
   189             s01, acc01, xs01 = s012, acc012, xs012
   189             s01, acc01, xs01 = s012, acc012, xs012
   190         else:
   190         else:
   191             segs.append ((j0,j1,s0,acc0,xs0))
   191             segs.append ((j0,j1,s0,acc0,xs0))
   192             if debug: print j0, j1, s0, acc0
   192             if debug: print(j0, j1, s0, acc0)
   193             j0, j1, j2 = j1, j2, j2 + 1
   193             j0, j1, j2 = j1, j2, j2 + 1
   194             s0, acc0, xs0 = s1, acc1, xs1
   194             s0, acc0, xs0 = s1, acc1, xs1
   195             s01, acc01, xs01 = s12, acc12, xs12
   195             s01, acc01, xs01 = s12, acc12, xs12
   196         s1, acc1, xs1 = s2, acc2, xs2
   196         s1, acc1, xs1 = s2, acc2, xs2
   197     if j0 < len (weights):
   197     if j0 < len (weights):
   198         segs.append ((j0,j1,s0,acc0,xs0))
   198         segs.append ((j0,j1,s0,acc0,xs0))
   199         if debug: print j0, j1, s0, acc0
   199         if debug: print(j0, j1, s0, acc0)
   200 
   200 
   201     return segs, kgroep
   201     return segs, kgroep
   202 
   202 
   203 if __name__ == '__main__':
   203 if __name__ == '__main__':
   204     f = open ('mids/bwv539p.b40')
   204     f = open ('mids/bwv539p.b40')
   205     xs = f.readlines ()
   205     xs = f.readlines ()
   206     f.close ()
   206     f.close ()
   207     def toint (xs): return map (lambda x: int (x), xs)
   207     def toint (xs): return [int (x) for x in xs]
   208     events = map (lambda x: toint (x.strip().split()), xs)
   208     events = [toint (x.strip().split()) for x in xs]
   209     kgroep = readEvents (events)
   209     kgroep = readEvents (events)
   210     mkWeights (kgroep)
   210     mkWeights (kgroep)
   211     mkTemplates ()
   211     mkTemplates ()
   212     segs, kgroep = analyseK (kgroep, debug=0)
   212     segs, kgroep = analyseK (kgroep, debug=0)
   213     print '%d segs, %d groepen' % (len (segs), len (kgroep))
   213     print('%d segs, %d groepen' % (len (segs), len (kgroep)))
   214     for iseg, jseg, score, acc, rest in segs:
   214     for iseg, jseg, score, acc, rest in segs:
   215         print '---', acc, score
   215         print('---', acc, score)
   216         for t, ns in kgroep [iseg:jseg]:
   216         for t, ns in kgroep [iseg:jseg]:
   217             print t, ', '.join (map (b40nm, ns))
   217             print(t, ', '.join (map (b40nm, ns)))