8000 Add start_listen/stop_listen for beat events · steeltrack/AbletonOSC@afeea20 · GitHub
[go: up one dir, main page]

Skip to content

Commit

Permalink
Add start_listen/stop_listen for beat events
Browse files Browse the repository at this point in the history
  • Loading branch information
ideoforms committed Jan 1, 2024
1 parent 2c27b6c commit afeea20
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,9 @@ Queries tracks 0..11, and returns a long list of values comprising:
track_1_name, clip_1_0_name, clip_1_1_name, ... clip_1_7_name, ...]
```

### Song status messages 8000
### Beat events

These messages are sent to the client automatically when the song state changes.

| Address | Response params | Description |
|:----------------|:----------------|:---------------------------------------------------------------------|
| /live/song/beat | beat_number | Sent to the client application on each beat when the song is playing |
To request a status message to be sent to the client on each beat, call `/live/song/start_listen/beat`. Every beat, a reply will be sent to `/live/song/get/beat`, with an int parameter containing the current beat number. To stop listening for beat events, call `/live/song/stop_listen/beat`.

</details>

Expand Down
26 changes: 21 additions & 5 deletions abletonosc/song.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,19 +247,35 @@ def song_jump_to_cue_point(song, params: Tuple[Any] = ()):
self.osc_server.add_handler("/live/song/cue_point/jump", partial(song_jump_to_cue_point, self.song))

#--------------------------------------------------------------------------------
# Listener for /live/song/beat
# Listener for /live/song/get/beat
#--------------------------------------------------------------------------------
self.last_song_time = -1.0
self.song.add_current_song_time_listener(self.song_time_changed)

def stop_beat_listener(params: Tuple[Any] = ()):
try:
self.song.remove_current_song_time_listener(self.current_song_time_changed)
except:
pass

def song_time_changed(self):
def start_beat_listener(params: Tuple[Any] = ()):
stop_beat_listener()
self.song.add_current_song_time_listener(self.current_song_time_changed)

self.osc_server.add_handler("/live/song/start_listen/beat", start_beat_listener)
self.osc_server.add_handler("/live/song/stop_listen/beat", stop_beat_listener)

def current_song_time_changed(self):
#--------------------------------------------------------------------------------
# If song has rewound or skipped to next beat, sent a /live/beat message
#--------------------------------------------------------------------------------
if (self.song.current_song_time < self.last_song_time) or \
(int(self.song.current_song_time) > int(self.last_song_time)):
self.osc_server.send("/live/song/beat", (int(self.song.current_song_time),))
self.osc_server.send("/live/song/get/beat", (int(self.song.current_song_time),))
self.last_song_time = self.song.current_song_time

def clear_api(self):
self.song.remove_current_song_time_listener(self.song_time_changed)
super().clear_api()
try:
self.song.remove_current_song_time_listener(self.current_song_time_changed)
except:
pass
8 changes: 5 additions & 3 deletions tests/test_song.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ def test_song_play(client):

def test_song_beat(client):
client.send_message("/live/song/stop_playing")
client.send_message("/live/song/start_listen/beat")
client.send_message("/live/song/start_playing")
wait_one_tick()
wait_one_tick()
assert client.await_message("/live/song/beat", timeout=1.0) == (1,)
assert client.await_message("/live/song/beat", timeout=1.0) == (2,)
assert client.await_message("/live/song/get/beat", timeout=1.0) == (1,)
assert client.await_message("/live/song/get/beat", timeout=1.0) == (2,)
client.send_message("/live/song/stop_playing")
wait_one_tick()
client.send_message("/live/song/continue_playing")
assert client.await_message("/live/song/beat", timeout=1.0) == (3,)
assert client.await_message("/live/song/get/beat", timeout=1.0) == (3,)
client.send_message("/live/song/stop_playing")
client.send_message("/live/song/stop_listen/beat")
wait_one_tick()

def test_song_stop_all_clips(client):
Expand Down

0 comments on commit afeea20

Please sign in to comment.
0