Ah! There’s a mistake. If your chord has both bass and treble notes, then the current code for play_piano_chord
will play the bass first and then play the treble, since both piano_bass.play_chord(bass_pitches, volume, length, properties)
and piano_treble.play_chord(treble_pitches, volume, length, properties)
get called and both are blocking calls.
Let’s change the code to this:
def play_piano_chord(pitches, volume, length, properties=None):
bass_pitches = [p for p in pitches if p < 60]
treble_pitches = [p for p in pitches if p >= 60]
if len(bass_pitches) > 0 and len(treble_pitches) > 0:
# there are both bass and treble pitches
piano_bass.play_chord(bass_pitches, volume, length, properties, blocking=False)
piano_treble.play_chord(treble_pitches, volume, length, properties)
elif len(bass_pitches) > 0:
# only bass pitches
piano_bass.play_chord(bass_pitches, volume, length, properties)
elif len(treble_pitches) > 0:
# only treble pitches
piano_treble.play_chord(treble_pitches, volume, length, properties)
This way, when there are both bass and treble, we make the first call blocking=False
so that it overlaps with the second call.