8000 Unify /live/clip/get/notes and /live/clip/remove/notes to have identi… · steeltrack/AbletonOSC@39e3934 · GitHub
[go: up one dir, main page]

Skip to content

Commit

Permalink
Unify /live/clip/get/notes and /live/clip/remove/notes to have identi…
Browse files Browse the repository at this point in the history
…cal orderings; add tests
  • Loading branch information
ideoforms committed Nov 18, 2023
1 parent 01c76d6 commit 39e3934
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,9 @@ Represents an audio or MIDI clip. Can be used to start/stop clips, and query/mod
| /live/clip/fire | track_id, clip_id | | Start clip playback |
| /live/clip/stop | track_id, clip_id | | Stop clip playback |
| /live/clip/duplicate_loop | track_id, clip_id | | Duplicates clip loop |
| /live/clip/get/notes | track_id, clip_id, [start_time, start_pitch, time_span, pitch_span] | track_id, clip_id, pitch, start_time, duration, velocity, mute, [pitch, start_time...] | Query the notes in a given clip, optionally including a start time/pitch and time/pitch span. |
| /live/clip/get/notes | track_id, clip_id, [start_pitch, pitch_span, start_time, time_span] | track_id, clip_id, pitch, start_time, duration, velocity, mute, [pitch, start_time...] | Query the notes in a given clip, optionally including a start time/pitch and time/pitch span. |
| /live/clip/add/notes | track_id, clip_id, pitch, start_time, duration, velocity, mute, ... | | Add new MIDI notes to a clip. pitch is MIDI note index, start_time and duration are beats in floats, velocity is MIDI velocity index, mute is true/false |
| /live/clip/remove/notes | start_pitch, pitch_span, start_time, time_span | | Remove notes from a clip in a given range of pitches and times. |
| /live/clip/remove/notes | [start_pitch, pitch_span, start_time, time_span] | | Remove notes from a clip in a range of pitches and times. If no ranges specified, all notes are removed. Note that ordering has changed as of 2023-11. |
| /live/clip/get/color | track_id, clip_id | track_id, clip_id, color | Get clip color |
| /live/clip/set/color | track_id, clip_id, color | | Set clip color |
| /live/clip/get/name | track_id, clip_id | track_id, clip_id, name | Get clip name |
Expand Down
20 changes: 14 additions & 6 deletions abletonosc/clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,16 @@ def clip_callback(params: Tuple[Any]) -> Tuple:

def clip_get_notes(clip, params: Tuple[Any] = ()):
if len(params) == 4:
time_start, pitch_start, time_span, pitch_span = params
pitch_start, pitch_span, time_start, time_span = params
elif len(params) == 0:
time_start, pitch_start, time_span, pitch_span = -8192, 0, 16384, 127
pitch_start, pitch_span, time_start, time_span = 0, 127, -8192, 16384
else:
raise ValueError("Invalid number of arguments for /clip/get/notes. Either 0 or 4 arguments must be passed.")
notes = clip.get_notes(time_start, pitch_start, time_span, pitch_span)
return tuple(item for sublist in notes for item in sublist)
notes = clip.get_notes_extended(pitch_start, pitch_span, time_start, time_span)
all_note_attributes = []
for note in notes:
all_note_attributes += [note.pitch, note.start_time, note.duration, note.velocity, note.mute]
return tuple(all_note_attributes)

def clip_add_notes(clip, params: Tuple[Any] = ()):
notes = []
Expand All @@ -131,8 +134,13 @@ def clip_add_notes(clip, params: Tuple[Any] = ()):
clip.add_new_notes(tuple(notes))

def clip_remove_notes(clip, params: Tuple[Any] = ()):
start_pitch, pitch_span, start_time, time_span = params
clip.remove_notes_extended(start_pitch, pitch_span, start_time, time_span)
if len(params) == 4:
pitch_start, pitch_span, time_start, time_span = params
elif len(params) == 0:
pitch_start, pitch_span, time_start, time_span = 0, 127, -8192, 16384
else:
raise ValueError("Invalid number of arguments for /clip/remove/notes. Either 0 or 4 arguments must be passed.")
clip.remove_notes_extended(pitch_start, pitch_span, time_start, time_span)

self.osc_server.add_handler("/live/clip/get/notes", create_clip_callback(clip_get_notes))
self.osc_server.add_handler("/live/clip/add/notes", create_clip_callback(clip_add_notes))
Expand Down
14 changes: 12 additions & 2 deletions tests/test_clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_clip_property_pitch_coarse(client):
def test_clip_property_pitch_fine(client):
_test_clip_property(client, 2, 0, "pitch_fine", (0.5, 0.0))

def test_clip_add_notes(client):
def test_clip_add_remove_notes(client):
client.send_message("/live/clip/get/notes", (0, 0))
assert client.await_message("/live/clip/get/notes") == (0, 0)

Expand All @@ -71,6 +71,16 @@ def test_clip_add_notes(client):

# Query between t in [0..2] and pitch in [60, 71]
# Should only return a single note
client.send_message("/live/clip/get/notes", (0, 0, 0, 60, 2, 11))
client.send_message("/live/clip/get/notes", (0, 0, 60, 11, 0, 2))
assert client.await_message("/live/clip/get/notes") == (0, 0,
60, 0.0, 0.25, 64, False)

client.send_message("/live/clip/remove/notes", (0, 0, 60, 11, 0, 2))
client.send_message("/live/clip/get/notes", (0, 0))
assert client.await_message("/live/clip/get/notes") == (0, 0,
60, 3.0, 0.5, 32, False,
67, -0.25, 0.5, 32, False,
72, 0.0, 0.25, 64, False)
client.send_message("/live/clip/remove/notes", (0, 0))
client.send_message("/live/clip/get/notes", (0, 0))
assert client.await_message("/live/clip/get/notes") == (0, 0)

0 comments on commit 39e3934

Please sign in to comment.
0