|
|
@ -21,10 +21,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
|
|
|
|
|
|
"""Use generated music data and build a complete lilypond file from it""" |
|
|
|
|
|
|
|
import logging; logging.info("import {}".format(__file__)) |
|
|
|
|
|
|
|
#Standard Library Modules |
|
|
|
import os.path |
|
|
|
from datetime import date |
|
|
|
import subprocess |
|
|
|
from tempfile import gettempdir |
|
|
|
|
|
|
|
#Third Party Modules |
|
|
|
|
|
|
|
#Template Modules |
|
|
|
from template.start import PATHS |
|
|
|
|
|
|
|
#Our modules |
|
|
|
|
|
|
|
|
|
|
|
da = date.fromordinal(730920) # 730920th day after 1. 1. 0001 |
|
|
|
|
|
|
|
def saveAsLilypond(score, absoluteFilePath = None): |
|
|
@ -79,7 +91,7 @@ def fromTemplate(session, templateFile, data, meta, tempoStaff): |
|
|
|
templateString = f.read() |
|
|
|
|
|
|
|
templateString = templateString.replace("%$$DATE$$", da.today().strftime("%A %d. %B %Y")) #The current date |
|
|
|
templateString = templateString.replace("%$$FILENAME$$", session.absoluteFilePath) |
|
|
|
templateString = templateString.replace("%$$FILENAME$$", session.sessionPrefix) |
|
|
|
templateString = templateString.replace("%$$HEADER$$", processMeta(meta)) |
|
|
|
templateString = templateString.replace("%$$SUBTEXT$$", lilyfy(meta["subtext"])) |
|
|
|
voicesString, structureString = processData(data) |
|
|
@ -89,16 +101,20 @@ def fromTemplate(session, templateFile, data, meta, tempoStaff): |
|
|
|
|
|
|
|
return templateString |
|
|
|
|
|
|
|
def findTemplate(session, templateFile): |
|
|
|
def findTemplate(session, templateFile:str=None)->str: |
|
|
|
"""returns a path. checks for existence. |
|
|
|
see fromTemplate""" |
|
|
|
if not templateFile: |
|
|
|
path = session.absoluteFilePath, ".template.ly" |
|
|
|
assert path.endswith(".lbj.ly") |
|
|
|
|
|
|
|
There are two options: |
|
|
|
- Use a standard template in SHARE/lilypondTemplates |
|
|
|
- Use a template that belongs to the save file. |
|
|
|
|
|
|
|
The one that belongs to the save file needs to be created by hand by the user. |
|
|
|
If not we throw a FileNotFoundError""" |
|
|
|
if templateFile: |
|
|
|
path = os.path.join(PATHS["share"], "lilypondTemplates", templateFile) |
|
|
|
else: |
|
|
|
path = os.path.join(session.applicationDirectory, "laborejomodule", "templates", templateFile) |
|
|
|
assert path.endswith(".ly") |
|
|
|
|
|
|
|
path = os.path.join(session.sessionPrefix, "template.laborejo2.ly") #the name is always the same because the sessionPrefix is the unqiue part |
|
|
|
assert path.endswith(".ly") |
|
|
|
if os.path.exists(path): |
|
|
|
return path |
|
|
|
else: |
|
|
|