8000 Unit tests and fixes for clip/slot lifecycle · steeltrack/AbletonOSC@0322bc5 · GitHub
[go: up one dir, main page]

Skip to content

Commit

Permalink
Unit tests and fixes for clip/slot lifecycle
Browse files Browse the repository at this point in the history
  • Loading branch information
ideoforms committed Jan 1, 2024
1 parent e5d9696 commit 0322bc5
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 11 deletions.
10 changes: 9 additions & 1 deletion abletonosc/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,15 @@ def _stop_listen(self, target, prop, params: Optional[Tuple[Any]] = ()) -> None:
listener_function = self.listener_functions[listener_key]
remove_listener_function_name = "remove_%s_listener" % prop
remove_listener_function = getattr(target, remove_listener_function_name)
remove_listener_function(listener_function)
try:
remove_listener_function(listener_function)
except RuntimeError:
#--------------------------------------------------------------------------------
# This exception may be thrown when an observer is no longer connected --
# e.g., when trying to stop listening for a clip property of a clip that has been deleted.
# Ignore as it is benign.
#--------------------------------------------------------------------------------
pass
del self.listener_functions[listener_key]
else:
self.logger.warning("No listener function found for property: %s (%s)" % (prop, str(params)))
19 changes: 12 additions & 7 deletions abletonosc/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,20 @@ def create_track_callback(func: Callable,
*args,
include_track_id: bool = False):
def track_callback(params: Tuple[Any]):
track_index = int(params[0])
track = self.song.tracks[track_index]
if include_track_id:
rv = func(track, *args, tuple(params[0:]))
if params[0] == "*":
track_indices = list(range(len(self.tracks)))
else:
rv = func(track, *args, tuple(params[1:]))
track_indices = [int(params[0])]

if rv is not None:
return (track_index, *rv)
for track_index in track_indices:
track = self.song.tracks[track_index]
if include_track_id:
rv = func(track, *args, tuple(params[0:]))
else:
rv = func(track, *args, tuple(params[1:]))

if rv is not None:
return (track_index, *rv)

return track_callback

Expand Down
1 change: 1 addition & 0 deletions client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(self, hostname="127.0.0.1", port=REMOTE_PORT, client_port=LOCAL_POR
self.verbose = False

def handle_osc(self, address, *params):
# print("Received OSC: %s %s" % (address, params))
if address in self.address_handlers:
self.address_handlers[address](params)
if self.verbose:
Expand Down
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ def wait_one_tick():
time.sleep(TICK_DURATION)

c = AbletonOSCClient()
c.send_message("/live/reload")
c.send_message("/live/api/reload")
c.stop()
32 changes: 31 additions & 1 deletion tests/test_clip.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import client, wait_one_tick
from . import client, wait_one_tick, TICK_DURATION
import pytest
import random

Expand Down Expand Up @@ -113,3 +113,33 @@ def test_clip_add_many_notes(client):

# Clear clip
client.send_message("/live/clip/remove/notes", (0, 0))

def test_clip_playing_position_listen(client):
client.send_message("/live/clip/start_listen/playing_position", [0, 0])
client.send_message("/live/clip/fire", [0, 0])

rv = client.await_message("/live/clip/get/playing_position", TICK_DURATION * 2)
assert rv == (0, 0, 0)

rv = client.await_message("/live/clip/get/playing_position", TICK_DURATION * 2)
assert rv[0] == 0
assert rv[1] == 0
assert rv[2] > 0

client.send_message("/live/clip/stop_listen/playing_position", (0, 0))

def test_clip_listen_lifecycle(client):
client.send_message("/live/clip/set/name", [0, 0, "Alpha"])
wait_one_tick()
client.send_message("/live/clip/start_listen/name", [0, 0])
assert client.await_message("/live/clip/get/name", TICK_DURATION * 2) == (0, 0, "Alpha")
client.send_message("/live/clip/set/name", [0, 0, "Beta"])
assert client.await_message("/live/clip/get/name", TICK_DURATION * 2) == (0, 0, "Beta")

client.send_message("/live/clip_slot/delete_clip", [0, 0])
client.send_message("/live/clip_slot/create_clip", [0, 0, 8.0])
client.send_message("/live/clip/start_listen/name", [0, 0])
assert client.await_message("/live/clip/get/name", TICK_DURATION * 2) == (0, 0, "")
client.send_message("/live/clip/set/name", [0, 0, "Alpha"])
assert client.await_ 8000 message("/live/clip/get/name", TICK_DURATION * 2) == (0, 0, "Alpha")
client.send_message("/live/clip/stop_listen/name", [0, 0])
11 changes: 10 additions & 1 deletion tests/test_clip_slot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import client, wait_one_tick
from . import client, wait_one_tick, TICK_DURATION

def test_clip_slot_has_clip(client):
assert client.query("/live/clip_slot/get/has_clip", (0, 0)) == (0, 0, False)
Expand All @@ -21,3 +21,12 @@ def test_clip_slot_duplicate(client):

client.send_message("/live/clip_slot/delete_clip", [0, 0])
client.send_message("/live/clip_slot/delete_clip", [0, 2])

def test_clip_slot_property_listen(client):
client.send_message("/live/clip_slot/start_listen/has_clip", (0, 0))
assert client.await_message("/live/clip_slot/get/has_clip", TICK_DURATION * 2) == (0, 0, False)
client.send_message("/live/clip_slot/create_clip", [0, 0, 4.0])
assert client.await_message("/live/clip_slot/get/has_clip", TICK_DURATION * 2) == (0, 0, True)
client.send_message("/live/clip_slot/delete_clip", [0, 0])
assert client.await_message("/live/clip_slot/get/has_clip", TICK_DURATION * 2) == (0, 0, False)
client.send_message("/live/clip_slot/stop_listen/has_clip", (0,))

0 comments on commit 0322bc5

Please sign in to comment.
0