Grace Notes

Hi Marc,
I see that GraceNote is available as a subclass of Note in the pymusicxml package. But, can’t find anything about grace notes in the scamp package. Could you point me towards how you tackle grace notes in scamp? Is there something in playback_implementations or note_properties that we can use to make grace notes?

Not everything in pymusicxml is implemented in SCAMP, and grace notes are one of those things. It’s a bit tricky, because grace notes have no real duration, or at least no fixed duration; they steal from the notes or rests around them.

If grace notes did exist, what would you want the API to look like? How would the code for playing one go?

Hmm. Good question.

Right now I’m trying to do ruffs for percussion. Something like this:

I could imagine there is a requirement for a rest or note, preceding the grace notes, that is long enough you can steal time from it.

Such as an 8th note to steal two 32nds from.

Imagining how I would try to write this:

def rest_and_grace_notes(instrument,
                         grace_note_pitches: int | float | list,
                         grace_note_notated_lengths: int | float | list,
                         grace_note_volumes: int |float | list)
    # assuming grace notes playback at half of notated value:
    grace_length = sum(grace_note_notated_lengths)/2
    play_back_rest = rest_length - grace_length
    grace_wait(play_back_rest, written_rest_length)
    data = zip(grace_note_pitches, grace_note_volumes, grace_note_notated_lengths)
    for p, v, l in data:
        instrument.play_note(p, v, l/2, transcribe=False)
    # and then the magical gracenote transcription:
    for p, v, l, in data:
        write_grace_note(p, v, l)

And then something similar for note_and_grace_notes