8000 Add test_clip_add_many_notes · steeltrack/AbletonOSC@3d5a5d6 · GitHub
[go: up one dir, main page]

Skip to content

Commit

Permalink
Add test_clip_add_many_notes
Browse files Browse the repository at this point in the history
  • Loading branch information
ideoforms committed Nov 19, 2023
1 parent 39e3934 commit 3d5a5d6
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion tests/test_clip.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from . import client, wait_one_tick
import pytest
import random

#--------------------------------------------------------------------------------
# To test clips, initialise by creating an empty MIDI clip and recording
Expand All @@ -11,7 +12,7 @@
def _create_test_clips(client):
midi_track_id = 0
midi_clip_id = 0
client.send_message("/live/clip_slot/create_clip", [midi_track_id, midi_clip_id, 4.0])
client.send_message("/live/clip_slot/create_clip", [midi_track_id, midi_clip_id, 8.0])

audio_track_id = 2
audio_clip_id = 0
Expand Down Expand Up @@ -84,3 +85,39 @@ def test_clip_add_remove_notes(client):
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)

def test_clip_add_many_notes(client):
"""
Test adding large numbers of notes to a clip.
Note that Ableton API's get_notes returns notes sorted by pitch, then time, so add notes
in this same order.
"""
random.seed(0)
all_note_data = []
pitch = 0
for n in range(127):
time = random.randrange(-32, 32) / 4
duration = random.randrange(1, 4) / 4
velocity = random.randrange(1, 128)
# Create multiple instances of the same sequence, shifted in time.
for timeshift in range(3):
note = (pitch,
time + (timeshift * 8),
duration,
velocity,
False)
all_note_data += note
pitch += 1
all_note_data = tuple(all_note_data)

# Check clip is initially empty
client.send_message("/live/clip/get/notes", (0, 0))
assert client.await_message("/live/clip/get/notes") == (0, 0)

# Populate clip and check return value
client.send_message("/live/clip/add/notes", (0, 0) + all_note_data)
client.send_message("/live/clip/get/notes", (0, 0))
assert client.await_message("/live/clip/get/notes") == (0, 0) + all_note_data

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

0 comments on commit 3d5a5d6

Please sign in to comment.
0