8000 Clear listeners on API reload · steeltrack/AbletonOSC@ccd678b · GitHub
[go: up one dir, main page]

Skip to content

Commit

Permalink
Clear listeners on API reload
Browse files Browse the repository at this point in the history
  • Loading branch information
ideoforms committed Jan 1, 2024
1 parent a2d2388 commit ccd678b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions abletonosc/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ def __init__(self, manager):
self.osc_server: OSCServer = self.manager.osc_server
self.init_api()
self.listener_functions = {}
self.listener_objects = {}
self.class_identifier = None

def init_api(self):
pass

def clear_api(self):
pass
self._clear_listeners()

#--------------------------------------------------------------------------------
# Generic callbacks
Expand Down Expand Up @@ -77,6 +78,7 @@ def property_changed_callback():
add_listener_function = getattr(target, add_listener_function_name)
add_listener_function(property_changed_callback)
self.listener_functions[listener_key] = property_changed_callback
self.listener_objects[listener_key] = target
#--------------------------------------------------------------------------------
# Immediately send the current value
#--------------------------------------------------------------------------------
Expand All @@ -99,5 +101,15 @@ def _stop_listen(self, target, prop, params: Optional[Tuple[Any]] = ()) -> None:
#--------------------------------------------------------------------------------
pass
del self.listener_functions[listener_key]
del self.listener_objects[listener_key]
else:
self.logger.warning("No listener function found for property: %s (%s)" % (prop, str(params)))
self.logger.warning("No listener function found for property: %s (%s)" % (prop, str(params)))

def _clear_listeners(self):
"""
Clears all listener functions, to prevent listeners continuing to report after a reload.
"""
for listener_key in list(self.listener_functions.keys())[:]:
target = self.listener_objects[listener_key]
prop, params = listener_key
self._stop_listen(target, prop, params)

0 comments on commit ccd678b

Please sign in to comment.
0