| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
""" |
| 8 |
Forward all messages from one or more ports to server. |
| 9 |
""" |
| 10 |
import argparse |
| 11 |
|
| 12 |
import mido |
| 13 |
|
| 14 |
|
| 15 |
def parse_args(): |
| 16 |
parser = argparse.ArgumentParser(description=__doc__) |
| 17 |
arg = parser.add_argument |
| 18 |
|
| 19 |
arg('address', |
| 20 |
metavar='ADDRESS', |
| 21 |
help='host:port to connect to') |
| 22 |
|
| 23 |
arg('ports', |
| 24 |
metavar='PORT', |
| 25 |
nargs='+', |
| 26 |
help='input ports to listen to') |
| 27 |
|
| 28 |
return parser.parse_args() |
| 29 |
|
| 30 |
|
| 31 |
def main(): |
| 32 |
args = parse_args() |
| 33 |
|
| 34 |
try: |
| 35 |
hostname, port = mido.sockets.parse_address(args.address) |
| 36 |
ports = [mido.open_input(name) for name in args.ports] |
| 37 |
|
| 38 |
with mido.sockets.connect(hostname, port) as server_port: |
| 39 |
print('Connected.') |
| 40 |
for message in mido.ports.multi_receive(ports): |
| 41 |
print(f'Sending {message}') |
| 42 |
server_port.send(message) |
| 43 |
except KeyboardInterrupt: |
| 44 |
pass |
| 45 |
|
| 46 |
|
| 47 |
if __name__ == '__main__': |
| 48 |
main() |