- commit
- 207552a0984ddbb2447983f34530215ebc00f128
- parent
- 2039436d10236e45aacaba1102d6171ed1f8c40e
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2023-09-19 15:09
add --debug option
Diffstat
| M | xi2.py | 19 | ++++++++++++------- |
1 files changed, 12 insertions, 7 deletions
diff --git a/xi2.py b/xi2.py
@@ -31,6 +31,8 @@ def parse_seq(t): 31 31 32 32 33 33 def expand_macros(s): -1 34 s = re.sub('[ \t]', '', s) -1 35 s = re.sub('#.*', '', s) 34 36 s = s.replace('\n', r'\n') 35 37 while re.search(r'(\[[^\]]*\]):(.*)', s): 36 38 match = re.search(r'(\[[^\]]*\]):(.*)', s) @@ -42,16 +44,12 @@ def expand_macros(s): 42 44 val = after.split(r'\n', 1)[0] 43 45 s = s.replace('%s:%s' % (key, val), '') 44 46 s = s.replace(key, val)45 -1 return s.replace(r'\n', '\n')-1 47 s = s.replace(r'\n', '\n') -1 48 s = s.strip('\n') -1 49 return re.sub('\n\n+', '\n\n', s) 46 50 47 51 48 52 def parse(s):49 -1 s = re.sub('[ \t]', '', s)50 -1 s = re.sub('#[^\n]*', '', s)51 -1 s = expand_macros(s)52 -1 s = s.strip('\n')53 -1 s = re.sub('\n\n+', '\n\n', s)54 -155 53 tracks = {} 56 54 for section in s.split('\n\n'): 57 55 length = max([len(t) for t in tracks.values()], default=0) @@ -73,6 +71,7 @@ def parse_args(): 73 71 parser = argparse.ArgumentParser() 74 72 parser.add_argument('-t', '--tempo', help='tempo in bpm', default=120, type=int) 75 73 parser.add_argument('-o', '--offset', help='key offset', default=60, type=int) -1 74 parser.add_argument('-d', '--debug', help='print normalized input and exit', action='store_true') 76 75 parser.add_argument('infile') 77 76 parser.add_argument('outfile') 78 77 return parser.parse_args() @@ -86,6 +85,12 @@ if __name__ == '__main__': 86 85 else: 87 86 with open(args.infile) as fh: 88 87 s = fh.read() -1 88 -1 89 s = expand_macros(s) -1 90 if args.debug: -1 91 print(s) -1 92 sys.exit(0) -1 93 89 94 tracks = parse(s) 90 95 91 96 # create first track with meta infos