git.s-ol.nu hw/0x33.board/firmware / f94176c
simulator: make rtmidi optional s-ol 20 days ago
1 changed file(s) with 24 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
00 import displayio
1 import rtmidi
21 from io import BytesIO
32 from math import sqrt
43 from base64 import b64encode
1716 from websockets.exceptions import ConnectionClosed
1817 from http.server import BaseHTTPRequestHandler, HTTPServer
1918
19 try:
20 import rtmidi
21
22 rtmidi_api = rtmidi.API_UNSPECIFIED
23 if rtmidi.API_UNIX_JACK in rtmidi.get_compiled_api():
24 rtmidi_api = rtmidi.API_UNIX_JACK
25 except:
26 rtmidi = None
27
2028 from .. import Keyboard as BaseKeyboard
21
22 rtmidi_api = rtmidi.API_UNSPECIFIED
23 if rtmidi.API_UNIX_JACK in rtmidi.get_compiled_api():
24 rtmidi_api = rtmidi.API_UNIX_JACK
2529
2630
2731 class MIDI:
5256
5357
5458 def create_midi_usb(board):
55 inp = rtmidi.MidiIn(rtmidi_api, "0x33.board sim")
56 out = rtmidi.MidiOut(rtmidi_api, "0x33.board sim")
57 inp.open_virtual_port("USB in")
58 out.open_virtual_port("USB out")
59 inp.ignore_types(sysex=False)
59 if rtmidi:
60 inp = rtmidi.MidiIn(rtmidi_api, "0x33.board sim")
61 out = rtmidi.MidiOut(rtmidi_api, "0x33.board sim")
62 inp.open_virtual_port("USB in")
63 out.open_virtual_port("USB out")
64 inp.ignore_types(sysex=False)
65 else:
66 inp, out = None, None
67
6068 return MIDI(inp, out)
6169
6270
6371 def create_midi_trs(board):
64 out = rtmidi.MidiOut(rtmidi_api, "0x33.board sim")
65 out.open_virtual_port("TRS out")
72 if rtmidi:
73 out = rtmidi.MidiOut(rtmidi_api, "0x33.board sim")
74 out.open_virtual_port("TRS out")
75 else:
76 out = None
6677 return MIDI(None, out)
6778
6879
396407 def run_http(self):
397408 try:
398409 with HTTPServer(("", 8000), HTTPHandler(self)) as server:
410 print("web server running at {0}:{1}".format(*server.server_address))
399411 server.serve_forever()
400412 except e:
401413 print(e)