1

I'm cutting up sections of sheet music into snippets on the beat. I'm using music21 and LilyPond to convert the output into a png. There's a very specific issue though where I get no display of a snippet only containing a rest. If the rest is being displayed with note then it shows fine.. but if the bar consists of a rest and nothing else the image is blank. My guess would be the program doesn't know where to place the rest when there's no context to wether a bass clef - stave is being used.. but I did attempt to providing placement information to the rest through Style.absoluteY module but no joy. If anybody could provide a bit of insight that'd be cool! Cheers

n = note.Note("C4")

r = note.Rest()

ss = stream.Stream()


ss.append(n)

ss.append(r)

ss.show("lily")

When I use the above code I get an output of image of 1/4 note and 1/4 rest

Then, when I use the below code I get an output of blank white box, where there should be a single 1/4 rest


r = note.Rest()

ss = stream.Stream()



ss.append(r)

ss.show("lily")
1990brien
  • 13
  • 1
  • 3
  • might be a bug with the lily package. What happens if you just use: ss.show() ? – pastaleg Jun 27 '22 at 17:28
  • ss.show() opens musescore 3 and shows the score – 1990brien Jun 28 '22 at 13:50
  • I've been trying to use ss.show("musicxml.png") which produces the png through Musescore 3.app rather than LilyPond.app but this runs into permission errors [Errno 13] – 1990brien Jun 28 '22 at 13:52
  • Not really an answer to your question, but have you considered using the [Abjad](https://abjad.github.io/) package for engraving music with Python? Abjad is a phenomenal package for producing LilyPond scores from within Python, and is able to produce [extremely high-level scores](https://abjad.github.io/gallery-2020.html). – gilbertohasnofb Jun 28 '22 at 18:55
  • Lilypond support is somewhat deprecated. The best way to get an image file is `.show('musicxml.png')` (music21 creator) – Michael Scott Asato Cuthbert Sep 09 '22 at 08:01

1 Answers1

1

Lilypond interface is not so strong, so better would be to install MuseScore

add-apt-repository ppa:mscore-ubuntu/mscore3-stable
apt update
apt install musescore3

pip uninstall music21
pip install music21

output:

enter image description here

pastaleg
  • 1,782
  • 2
  • 17
  • 23
  • Thanks for reply! I'm using music21 already but was having issues outputting a PNG (score.show('png')) without going through LillyPond interface (score.show('lily')). If I try to use this right now I get errnor 3 with permissions issues.. guess I'll play around with it and see what happens – 1990brien Jun 27 '22 at 19:18
  • 1
    Can you open the mscore binary at the command line? If you're on a Mac, you may need to control-click the binary and give the OS explicit permission to run it before you try to use music21 as an interface to it. – Jacob Walls Jun 29 '22 at 16:20