diff --git a/flapi/_consts.py b/flapi/_consts.py index 887d9cf..df4afb5 100644 --- a/flapi/_consts.py +++ b/flapi/_consts.py @@ -5,7 +5,7 @@ """ from enum import IntEnum -VERSION = (1, 0, 0) +VERSION = (1, 0, 1) """ The version of Flapi in the format (major, minor, revision) """ diff --git a/flapi/server/consts.py b/flapi/server/consts.py index 887d9cf..df4afb5 100644 --- a/flapi/server/consts.py +++ b/flapi/server/consts.py @@ -5,7 +5,7 @@ """ from enum import IntEnum -VERSION = (1, 0, 0) +VERSION = (1, 0, 1) """ The version of Flapi in the format (major, minor, revision) """ diff --git a/flapi/server/device_flapi_receive.py b/flapi/server/device_flapi_receive.py index 756b69a..c2b087b 100644 --- a/flapi/server/device_flapi_receive.py +++ b/flapi/server/device_flapi_receive.py @@ -42,7 +42,7 @@ def send_stdout(text: str): def OnInit(): print("\n".join([ - "Flapi server", + "Flapi request server", f"Server version: {'.'.join(str(n) for n in consts.VERSION)}", f"Device name: {device.getName()}", f"Device assigned: {bool(device.isAssigned())}", @@ -97,7 +97,6 @@ def fl_exec(res: FlapiResponse, data: bytes): statement = b64decode(data) try: # Exec in global scope so that the imports are remembered - # TODO: Give each client separate global and local scopes exec(statement, connected_clients[res.client_id]) except Exception as e: # Something went wrong, give the error @@ -111,7 +110,6 @@ def fl_eval(res: FlapiResponse, data: bytes): expression = b64decode(data) try: # Exec in global scope so that the imports are remembered - # TODO: Give each client separate global and local scopes result = eval(expression, connected_clients[res.client_id]) except Exception as e: # Something went wrong, give the error @@ -161,10 +159,20 @@ def OnSysEx(event: 'FlMidiMsg'): handler = message_handlers.get(message_type) if handler is None: - return res.fail(message_type, f"Unknown message type {message_type}") + log.error(f"Unknown handler for message type {message_type}") + return res \ + .fail(message_type, f"Unknown message type {message_type}") \ + .send() # Capture stdout for the duration of the operation - with capout(client_id): - handler(res, data) + try: + with capout(client_id): + handler(res, data) + except Exception as e: + log.error(f"Unhandled error for handler {handler}", exc_info=e) + res.fail( + message_type, + f"Unhandled exception in {handler}: {type(e).__name__}: {e}", + ) res.send() diff --git a/flapi/server/device_flapi_respond.py b/flapi/server/device_flapi_respond.py index 1d200dc..d78659b 100644 --- a/flapi/server/device_flapi_respond.py +++ b/flapi/server/device_flapi_respond.py @@ -11,7 +11,7 @@ Flapi client. """ import device -from consts import MessageOrigin, MessageType, SYSEX_HEADER +from consts import MessageOrigin, MessageType, SYSEX_HEADER, VERSION try: from fl_classes import FlMidiMsg @@ -19,12 +19,21 @@ pass +def OnInit(): + print("\n".join([ + "Flapi response server", + f"Server version: {'.'.join(str(n) for n in VERSION)}", + f"Device name: {device.getName()}", + f"Device assigned: {bool(device.isAssigned())}", + f"FL Studio port number: {device.getPortNumber()}", + ])) + + # def print_msg(name: str, msg: bytes): # print(f"{name}: {[hex(b) for b in msg]}") def OnSysEx(event: 'FlMidiMsg'): - header = event.sysex[1:len(SYSEX_HEADER)+1] # Sysex header # print_msg("Header", header) # Remaining sysex data