# HG changeset patch # User wim # Date 1590402841 -7200 # Node ID 775a1d0d3be6f28def37deb571e7139358c16cc3 # Parent 7fd6cac1a69d822e478a1ffb11600f8e5e246fce - add commandline interface diff -r 7fd6cac1a69d -r 775a1d0d3be6 .hgignore --- a/.hgignore Mon May 25 10:39:18 2020 +0200 +++ b/.hgignore Mon May 25 12:34:01 2020 +0200 @@ -0,0 +1,3 @@ +syntax: glob +*.pyc +*.xml diff -r 7fd6cac1a69d -r 775a1d0d3be6 xmlChordAna.py --- a/xmlChordAna.py Mon May 25 10:39:18 2020 +0200 +++ b/xmlChordAna.py Mon May 25 12:34:01 2020 +0200 @@ -1,5 +1,7 @@ -import fractions as F -import xml2b40 +#!/usr/bin/env python +# coding: latin-1 + +import fractions, os, xml2b40 import segLibB40 as S def keySeg (iseg,jseg): @@ -30,16 +32,25 @@ 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 = F.Fraction (tikken, tikkenPerKwart) - n, d = x.numerator, x.denominator - t = n / d + x = fractions.Fraction (tikken, tikkenPerKwart) + t = x.numerator / x.denominator r = x - t if r == 0: r = '' regels.append ('%4d %3s %s' % (t, r, noten)) return regels if __name__ == '__main__': - fnm = 'mids/bwv539p_arr.xml' - noten = xml2b40.xml2b40 (fnm) - regels = mkAna (noten, fnm) - print '\n'.join (regels) \ No newline at end of file + from optparse import OptionParser + parser = OptionParser (usage='%prog [-h] [-g TPQ] [--C5] ') + parser.add_option ("-t", action="store", type="int", help="ticks per quarternote", default=384, metavar='TPQ') + parser.add_option ("--C5", action="store_true", help="central C is C5", default=False) + options, args = parser.parse_args () + if len (args) < 1: parser.error ('file argument needed') + fnmext = args [0] + fnm, ext = os.path.splitext (fnmext) + if ext != '.xml': parser.error ('.xml file needed file needed') + if not os.path.exists (fnmext): parser.error ('%s does not exist' % fnmext) + + noten = xml2b40.xml2b40 (fnmext, options.t, options.C5) + regels = mkAna (noten, fnmext) + print '\n'.join (regels)