Skip to content

Commit 3fd0c61

Browse files
authored
Merge pull request #15 from spridget/patch-2
Update ble_midi_simpletest.py
2 parents 948cb89 + 711160a commit 3fd0c61

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

examples/ble_midi_simpletest.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,29 @@
3737
print("Waiting for connection")
3838
while not ble.connected:
3939
pass
40-
print("Connected")
41-
# Sleep briefly so client can get ready and send setup
42-
# writes to the MIDIService. 0.5secs was insufficient.
43-
time.sleep(1.0)
44-
# Send one unique NoteOn/Off at the beginning to check that the
45-
# delay is sufficient.
46-
midi.send(NoteOn(20, 99))
47-
midi.send(NoteOff(20, 99))
48-
while ble.connected:
49-
midi.send(NoteOn(44, 120)) # G sharp 2nd octave
50-
time.sleep(0.25)
51-
a_pitch_bend = PitchBend(random.randint(0, 16383))
52-
midi.send(a_pitch_bend)
53-
time.sleep(0.25)
54-
# note how a list of messages can be used
55-
midi.send([NoteOff("G#2", 120), ControlChange(3, 44)])
56-
time.sleep(0.5)
40+
print("Connected; waiting for pairing")
41+
for connection in ble.connections:
42+
while not connection.paired:
43+
if not connection.connected:
44+
break
45+
if connection.paired:
46+
print("Paired; sending MIDI messages")
47+
# Sleep briefly so client can get ready and send setup
48+
# writes to the MIDIService. 0.5secs was insufficient.
49+
time.sleep(3.0)
50+
# Send one unique NoteOn/Off at the beginning to check that the
51+
# delay is sufficient.
52+
midi.send(NoteOn(20, 99))
53+
midi.send(NoteOff(20, 99))
54+
while ble.connected:
55+
midi.send(NoteOn(44, 120)) # G sharp 2nd octave
56+
time.sleep(0.25)
57+
a_pitch_bend = PitchBend(random.randint(0, 16383))
58+
midi.send(a_pitch_bend)
59+
time.sleep(0.25)
60+
# note how a list of messages can be used
61+
midi.send([NoteOff("G#2", 120), ControlChange(3, 44)])
62+
time.sleep(0.5)
5763
print("Disconnected")
5864
print()
5965
ble.start_advertising(advertisement)

0 commit comments

Comments
 (0)