Skip to content

Commit 670ba50

Browse files
committed
Fix virtual device handling in tests
1 parent 3cac424 commit 670ba50

3 files changed

Lines changed: 21 additions & 6 deletions

File tree

isobar/io/midi/input.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ def __init__(self,
3232
"""
3333
if device_name is None:
3434
device_name = os.getenv("ISOBAR_DEFAULT_MIDI_IN")
35+
36+
if device_name and not virtual:
37+
#--------------------------------------------------------------------------------
38+
# For permissive matching, look up device names that start with the given string.
39+
#--------------------------------------------------------------------------------
40+
available_device_names = mido.get_input_names()
41+
matching_device_names = [name for name in available_device_names if device_name in name]
42+
43+
if len(matching_device_names) == 0:
44+
raise DeviceNotFoundException("Could not find MIDI device with name starting with: %s" % device_name)
45+
elif len(matching_device_names) > 1:
46+
raise DeviceNotFoundException("Multiple MIDI output devices found matching '%s'" % (device_name))
47+
else:
48+
device_name = matching_device_names[0]
49+
3550
try:
3651
self.midi = mido.open_input(name=device_name,
3752
callback=self._mido_callback,
@@ -360,4 +375,4 @@ def get_device_names(cls):
360375
midi_in.run()
361376
except KeyboardInterrupt:
362377
print("Exiting...")
363-
midi_in.close()
378+
midi_in.close()

isobar/io/midi/output.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ def __init__(self,
2929
if device_name is None:
3030
device_name = os.getenv("ISOBAR_DEFAULT_MIDI_OUT")
3131

32-
if device_name:
32+
if device_name and not virtual:
3333
#--------------------------------------------------------------------------------
3434
# For permissive matching, look up device names that start with the given string.
3535
#--------------------------------------------------------------------------------
3636
available_device_names = mido.get_output_names()
37-
matching_device_names = [name for name in available_device_names if name.startswith(device_name)]
37+
matching_device_names = [name for name in available_device_names if device_name in name]
3838

3939
if len(matching_device_names) == 0:
4040
raise DeviceNotFoundException("Could not find MIDI device with name starting with: %s" % device_name)
@@ -135,4 +135,4 @@ def get_device_names(cls):
135135
"""
136136
Returns a list of available MIDI output device names.
137137
"""
138-
return mido.get_output_names()
138+
return mido.get_output_names()

tests/test_track_record.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ def test_track_recording_notes(dummy_timeline):
2525
input_device.note_on(60, 64)
2626

2727
# Advance time to t=1
28-
dummy_timeline.tick() # t=0 event processing
29-
dummy_timeline.current_time += 1.0 # Simulate time passing
28+
for n in range(dummy_timeline.ticks_per_beat):
29+
dummy_timeline.tick()
3030

3131
# Send note off at t=1
3232
input_device.note_off(60)

0 commit comments

Comments
 (0)