Last active
November 12, 2024 11:22
-
-
Save CnrLwlss/d6fee5e64861a6a616a9d80fe6f7d651 to your computer and use it in GitHub Desktop.
Python code to write a .pdf file of empty music staff for composing music. You can print it out and start writing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fpdf | |
def makePage(w=297,h=210): | |
'''Page width and height in mm. Default is A4 landscape''' | |
pdf = fpdf.FPDF(unit='mm', format=(w, h)) | |
pdf.add_page() | |
return(pdf) | |
def drawLines(pdf, titlegap = 30, stafflinegap = 4, linegap = 10): | |
'''All dimensions in mm. 5 lines for music notation. | |
Arbitarily chose to have linegap margins''' | |
deltay = titlegap | |
with pdf.new_path() as path: | |
while deltay+5*stafflinegap+linegap<=pdf.h: | |
for i in range(0,5): | |
path.move_to(linegap, deltay) | |
path.line_to(pdf.w-linegap, deltay) | |
deltay = deltay + stafflinegap | |
deltay = deltay + linegap | |
print("Another line would start outside page margins at: "+str(deltay+5*stafflinegap+linegap)) | |
path.close() | |
if __name__ == "__main__": | |
pdf = makePage(w=297,h=210) | |
drawLines(pdf,titlegap=30, stafflinegap=4, linegap=10) | |
pdf.output("SM_A4Landscape.pdf") | |
pdf = makePage(w=210,h=297) | |
drawLines(pdf,titlegap=50, stafflinegap=4, linegap=10) | |
pdf.output("SM_A4Portrait.pdf") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment