a follow up to my MuseScore and LilyPond musings from the previous post

Just a quick follow up to the last post about MuseScore, LilyPond, and my desire to get LilyPond output without entering the music natively as LilyPond syntax.

After some minor tests, it looks like the LilyPond output from MuseScore is far more workable than using "musicXML2ly.py", which comes with LilyPond.

… but it does need some minor clean up, etc.

I'm working on writing four pieces for solo guitar and below I have a snippet from the first piece. Note that I haven't entered fingerings, dynamics, etc. yet. If fact, the two fingerings and the "Adagio" used below are just there to see if they got outputted to LilyPond via MuseScore.

There are three snippets below. The first is the native MuseScore PDF output, followed by MuseScore's LilyPond output, then by MuseScore's LilyPond output after I did some processing on the ".ly" file with a Python script I wrote specifically for this piece. The Python script removes the numbering of every measure and also re-establishes the beaming in voice two which got lost from the direct MuseScore-to-LilyPond output. I probably will also have the script remove the parenthetical metronome marking that is being added to the LilyPond output.

MuseScore and LilyPond snippets

The Python script is also included below for demonstrative purposes. I'll probably work out a way to make the script configurable so that I can re-use the same script to process the other pieces but have a config file per piece that allows for customization.

import re

######################################
##### PART 1: comment out lines. #####
######################################

# comments out a line;
# the argument needs to be the start of a line but not all of it.
def lily_comment(line):
  commented = "%" + line
  return commented

# establish LilyPond file to process.
lily_via_mscore = "No_1c.ly"

# open LilyLond file; read it.
f = open(lily_via_mscore, "r")
new_lily = f.read()
f.close()

# place beginning of lines to comment out in array.
bads = ['\override Score.BarNumber'] # prevent numbering every measure.

# comment out bad lines.
for bad in bads:
  new_lily = new_lily.replace(bad, lily_comment(bad))

#####################################################
##### PART 2: beam all eighth notes in voice 2. #####
#####################################################

# make beams via regex.
output = ""
for line in new_lily.split("\n"):
  m = re.match(r"(.*)~ (<.*>)", line) #ex. changes this: "r8 d~ <d fis> r" to this: "r8 d~ [<d fis>] r".
  if m:
    beams = m.group(2)
    line = line.replace(beams, "[" + beams + "]")
  output = output + line + "\n"

# overwrite LilyPond file with revised version.
f = open(lily_via_mscore, "w")
f.write(output)
f.close()

# fin.
--------------

Related Content:

Leave a Comment

Your email address will not be published. Required fields are marked *


*