Key Signature?

Hello all! I’ve got a simple question: how do I change the key signature of the staff?

I’ve seen that I can add accidentals with the command:

piano = s.play_note(…“key: A major”)

But that still prints the staff in the key of C, so I’m wondering how to update the whole staff key signature.

I’ve read the documentation but still not certain how to integrate this into my transcription function.

I was hoping it would be something as simple as

performance = s.stop_transcribing(key_signature = “A major”)

Can you please advise?

Thanks!

It’s unfortunately not implemented yet, but it’s on my list! Part of the reason it hasn’t been a priority is that it’s so easy to do manually after the fact, either through abjad (if you’re using the lilypond output) or through notation software if you’re using the musicxml output.

But yeah, it’s silly that it’s not there! Part of the reason is that I’m not totally sure how to do it the right way. The way you suggest is good if the whole piece is in the same key, but if you’re changing keys part way through, how would you specify that?

The truth is that SCAMP needs a way of attaching staff notations that aren’t attached to particular notes, and that’s a bigger thing to implement.

What’s your use case BTW?

Hey Marc, thanks for the quick response!

I’m slightly relieved to hear that - lol, was worried that I was missing something obvious :slight_smile:

I’m building a series of apps that generate musical exercises, currently: random sight reading exercises and melodic patterns - so for my situation, printing in one key is common. Although, I’m aware that this only uses a very small slice of SCAMP’s true functionality - it still saves me some short term work rather than creating my own custom XML writing module.

It’s been a good excuse for me to dig deeper into the documentation and tutorials! I’ve definitely got lots of inspiration for more compositional/creative uses for SCAMP.

Appreciate the help!

BTW I’ve got some early WIP on my github if you’re interested

1 Like

Makes sense! BTW, if you’re exporting to XML, you could do this:

from scamp import *

s = Session(tempo=120)

violin = s.new_part("violin")
s.start_transcribing()

for _ in range(3):
    for p in [62, 65, 63, 67, 68, 72, 70]:
        violin.play_note(p, 0.7, 0.5, "key: Eb")

pymusicxml_score = s.stop_transcribing().to_score().to_music_xml()
pymusicxml_part = pymusicxml_score.contents[0]
pymusicxml_part.measures[0].key = "Eb"

pymusicxml_score.export_to_file("KeySig.musicxml")

It’s a little klugey — you get the musicxml representation, and then find the first measure of the first part and manually add a key signature — but maybe useful for your purposes?

I should also say: you can call pymusicxml_score.view_in_software(terminal_command) if you want to open it directly rather than save it to a file.