xi2

a plain text language that compiles to MIDI
git clone https://git.ce9e.org/xi2.git

commit
2039436d10236e45aacaba1102d6171ed1f8c40e
parent
7f35c1c2c7b44e3ccff23dd6696db324f31c29eb
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2023-09-19 14:34
allow input output from stdin/stdout

Diffstat

M xi2.py 15 +++++++++++----

1 files changed, 11 insertions, 4 deletions


diff --git a/xi2.py b/xi2.py

@@ -2,6 +2,7 @@
    2     2 
    3     3 import argparse
    4     4 import re
   -1     5 import sys
    5     6 
    6     7 import midi
    7     8 from renderer import render
@@ -80,8 +81,11 @@ def parse_args():
   80    81 if __name__ == '__main__':
   81    82     args = parse_args()
   82    83 
   83    -1     with open(args.infile) as fh:
   84    -1         s = fh.read()
   -1    84     if args.infile == '-':
   -1    85         s = sys.stdin.read()
   -1    86     else:
   -1    87         with open(args.infile) as fh:
   -1    88             s = fh.read()
   85    89     tracks = parse(s)
   86    90 
   87    91     # create first track with meta infos
@@ -101,5 +105,8 @@ if __name__ == '__main__':
  101   105         render(tracks[name], m, ch=ch, offset=args.offset)
  102   106         midi_tracks.append(m)
  103   107 
  104    -1     with open(args.outfile, 'wb') as fh:
  105    -1         midi.write_file(fh, midi_tracks)
   -1   108     if args.outfile == '-':
   -1   109         midi.write_file(sys.stdout.buffer, midi_tracks)
   -1   110     else:
   -1   111         with open(args.outfile, 'wb') as fh:
   -1   112             midi.write_file(fh, midi_tracks)