| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
""" |
| 8 |
Serve one or more output ports. Every message received on any of the |
| 9 |
connected sockets will be sent to every output port. |
| 10 |
""" |
| 11 |
import argparse |
| 12 |
|
| 13 |
import mido |
| 14 |
from mido import sockets |
| 15 |
from mido.ports import MultiPort |
| 16 |
|
| 17 |
|
| 18 |
def parse_args(): |
| 19 |
parser = argparse.ArgumentParser(description=__doc__) |
| 20 |
arg = parser.add_argument |
| 21 |
|
| 22 |
arg('address', |
| 23 |
metavar='ADDRESS', |
| 24 |
help='host:port to serve on') |
| 25 |
|
| 26 |
arg('ports', |
| 27 |
metavar='PORT', |
| 28 |
nargs='+', |
| 29 |
help='output port to serve') |
| 30 |
|
| 31 |
return parser.parse_args() |
| 32 |
|
| 33 |
|
| 34 |
def main(): |
| 35 |
args = parse_args() |
| 36 |
|
| 37 |
try: |
| 38 |
out = MultiPort([mido.open_output(name) for name in args.ports]) |
| 39 |
|
| 40 |
(hostname, port) = sockets.parse_address(args.address) |
| 41 |
with sockets.PortServer(hostname, port) as server: |
| 42 |
for message in server: |
| 43 |
print(f'Received {message}') |
| 44 |
out.send(message) |
| 45 |
except KeyboardInterrupt: |
| 46 |
pass |
| 47 |
|
| 48 |
|
| 49 |
if __name__ == '__main__': |
| 50 |
main() |