-
Notifications
You must be signed in to change notification settings - Fork 3
/
styplay.py
37 lines (25 loc) · 1.38 KB
/
styplay.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python3
from style_codec import *
import argparse
parser = argparse.ArgumentParser(description='STY MIDI Player')
parser.add_argument('input', type=str, help='input sty')
parser.add_argument('-c', '--channels', type=str, default='8,9,10,11,12,13,14,15', help='channel numbers to play')
parser.add_argument('-l', '--list-midi-ports', action='store_true', help='lists midi ports and exits')
parser.add_argument('-p', '--midi-port', type=int, default=0, help='midi port number')
parser.add_argument('-s', '--section', type=str, default='Main A', help='name of section to play in a loop')
parser.add_argument('-t', '--tempo', type=int, default=120, help='tempo in beats per minute')
parser.add_argument('-k', '--key', type=str, default='c', help='key to play the style in')
parser.add_argument('-r', '--chord', type=str, default='Maj7', help='chord to play the style in')
args = parser.parse_args()
midiout = rtmidi.MidiOut()
if (args.list_midi_ports):
availablePorts = midiout.get_ports()
portIdx = 0
for port in availablePorts:
print('{}: {}'.format(portIdx, port))
portIdx += 1
del midiout
exit(0)
channels = [int(x) for x in args.channels.split(',')]
style = Style.fromSty(args.input)
style.play(channels=channels, trackSections=[args.section], tempo=args.tempo, midiPort=args.midi_port, key=args.key, chord=args.chord)