Hi Mike — welcome! Sorry for the slow response.
Here’s one way to do what you’re suggesting:
from scamp import *
s = Session()
cello = s.new_midi_part("cello", 0)
last_ks = None
ks_to_midi_pitch = {
"arco": 84,
"tremolo": 85,
"staccato": 86
}
def play_cello_note(pitch, volume, duration, properties=None, keyswitch="arco"):
global last_ks
if keyswitch != last_ks:
cello.play_note(ks_to_midi_pitch[keyswitch], 1.0, 0.05, blocking=False)
last_ks = keyswitch
cello.play_note(pitch, volume, duration, properties=properties)
play_cello_note(48, 0.7, 0.25, keyswitch="staccato")
play_cello_note(49, 0.7, 0.25, keyswitch="staccato")
play_cello_note(50, 0.7, 0.25, keyswitch="staccato")
play_cello_note(53, 0.7, 1.25, keyswitch="tremolo")
play_cello_note(52, 0.7, 0.5, keyswitch="arco")
play_cello_note(51, 0.7, 0.5, keyswitch="arco")
Here, ks_to_midi_pitch
defines a mapping from articulation names to keyswitch pitches, and anytime the keyswitch is different from the last keyswitch, it sends a very short note to the appropriate pitch to change keyswitch right as the note is starting.
This works for me on my computer, and I think it should be pretty reliable. Of course, it does mean you’re creating a new function for playing notes from each instrument, so there’s probably a cleaner way to do it using classes.
Hope this helps!