3

I am trying to produce a quick reworking of some educational materials on music showing how it may be able to create the associated media assets (images, audio files) from "code" in a Jupyter notebook using the Python music21 package.

It seems the simplest steps are the hardest. For example, how do I create an empty staff:

enter image description here

or a staff populated by notes but without a clef at the start?

enter image description here

If I do something like:

from music21 import *

s = stream.Stream()
s.append(note.Note('G4', type='whole'))
s.append(note.Note('A4', type='whole'))
s.append(note.Note('B4', type='whole'))
s.append(note.Note('C5', type='whole'))
s.show()

I get the following?

enter image description here

psychemedia
  • 5,690
  • 7
  • 52
  • 84

1 Answers1

2

Try creating a stream.Measure object, so that barlines before the notes don't appear.

Music21 puts barlines and clefs, etc., in by default. You can manually put in a time signature of 4/1 and a treble clef and set them with ".style.hideObjectOnPrint" (or just ".hideObjectOnPrint" on older m21 versions). You will probably need to also set .rightBarline = bar.Barline('none') or something like that for the end.

It is possible, but I haven't ever fully tried all the parts of it.