From d8e944713a3fd69f670e83e6bfc3cead4fd2464b Mon Sep 17 00:00:00 2001 From: Nils <> Date: Sat, 13 Apr 2019 00:38:58 +0200 Subject: [PATCH] Restore lilypond export --- engine/api.py | 7 ++++ engine/config.py | 2 +- engine/lilypond.py | 34 ++++++++++++++----- engine/main.py | 4 +-- .../default.ly | 0 .../minimal.ly | 0 engine/tempotrack.py | 2 ++ qtgui/menu.py | 2 +- qtgui/submenus.py | 20 ++++++++--- template | 2 +- 10 files changed, 53 insertions(+), 20 deletions(-) rename engine/resources/{lilypondTemplate => lilypondTemplates}/default.ly (100%) rename engine/resources/{lilypondTemplate => lilypondTemplates}/minimal.ly (100%) diff --git a/engine/api.py b/engine/api.py index ba76c0f..d4cf081 100644 --- a/engine/api.py +++ b/engine/api.py @@ -307,6 +307,13 @@ def startEngine(nsmClient): #General and abstract Commands + +def getMetadata(): + return session.data.metaData + +def setMetadata(data): + session.data.metaData = data + def playFromCursor(): playFrom(ticks=session.data.cursorExport()["tickindex"]) diff --git a/engine/config.py b/engine/config.py index 81c2880..9553797 100644 --- a/engine/config.py +++ b/engine/config.py @@ -54,6 +54,6 @@ maximum fine control to get exactly the music you want! """ + "\n" + """ Working in Laborejo is very fast and efficient by using a combination of midi input and typing.""", - "dependencies" : "\n".join("* "+dep for dep in ("A Brain", "Linux" )), + "dependencies" : "\n".join("* "+dep for dep in ("This", "That" )), } diff --git a/engine/lilypond.py b/engine/lilypond.py index b82c433..f070362 100644 --- a/engine/lilypond.py +++ b/engine/lilypond.py @@ -21,10 +21,22 @@ along with this program. If not, see . """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: diff --git a/engine/main.py b/engine/main.py index f14e13c..2182389 100644 --- a/engine/main.py +++ b/engine/main.py @@ -35,6 +35,7 @@ from .block import Block from .track import Track from .cursor import Cursor from .tempotrack import TempoTrack +from .lilypond import fromTemplate class Data(template.engine.sequencer.Score): @@ -1021,9 +1022,6 @@ class Data(template.engine.sequencer.Score): data = {track:track.lilypond() for track in self.tracks} #processed in the lilypond module return fromTemplate(session = self.parentSession, templateFile = "default.ly", data = data, meta = self.metaData, tempoStaff = tempoStaff) - - - #Save / Load / Export def serialize(self)->dict: dictionary = super().serialize() diff --git a/engine/resources/lilypondTemplate/default.ly b/engine/resources/lilypondTemplates/default.ly similarity index 100% rename from engine/resources/lilypondTemplate/default.ly rename to engine/resources/lilypondTemplates/default.ly diff --git a/engine/resources/lilypondTemplate/minimal.ly b/engine/resources/lilypondTemplates/minimal.ly similarity index 100% rename from engine/resources/lilypondTemplate/minimal.ly rename to engine/resources/lilypondTemplates/minimal.ly diff --git a/engine/tempotrack.py b/engine/tempotrack.py index 333520b..e825956 100644 --- a/engine/tempotrack.py +++ b/engine/tempotrack.py @@ -28,7 +28,9 @@ from weakref import WeakValueDictionary, WeakSet #Third Party Modules #Template Modules +import template.engine.duration as duration from template.engine.duration import D1, D4, D1024 +from template.helper import pairwise #Our modules from .ccsubtrack import GraphTrackCC, GraphBlock diff --git a/qtgui/menu.py b/qtgui/menu.py index 673db2f..2a31ec3 100644 --- a/qtgui/menu.py +++ b/qtgui/menu.py @@ -460,7 +460,6 @@ class MenuActionDatabase(object): self.mainWindow.ui.actionRedo.setText("Redo") self.mainWindow.ui.actionRedo.setEnabled(False) - def exportLy(self): filename = QtWidgets.QFileDialog.getSaveFileName(self.mainWindow, "Export Lilypond Source File", self.mainWindow.settings.value("last_export_dir"), "Lilypond Source (*.ly)") filename = filename[0] #(path, filter) @@ -469,6 +468,7 @@ class MenuActionDatabase(object): filename = filename + ".ly" self.mainWindow.settings.setValue("last_export_dir", os.path.dirname(filename)) api.exportLilypond(filename) + hier weiter machen. settings gibts nicht mehr. im backend speichern. class ToolBarCCType(QtWidgets.QSpinBox): diff --git a/qtgui/submenus.py b/qtgui/submenus.py index 94270b0..25262fe 100644 --- a/qtgui/submenus.py +++ b/qtgui/submenus.py @@ -24,6 +24,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets import engine.api as api import template.engine.pitch as pitch +from template.qtgui.helper import QHLine from .constantsAndConfigs import constantsAndConfigs from .designer.tickWidget import Ui_tickWidget @@ -475,18 +476,27 @@ class TransposeMenu(Submenu): class SecondaryProperties(Submenu): def __init__(self, mainWindow): """Directly edits the backend score meta data. There is no api and no callbacks""" - super().__init__(mainWindow, "MetaData") + super().__init__(mainWindow, "Meta Data") - dictionary = api.session.score.metaData + dictionary = api.getMetadata() test = set(type(key) for key in dictionary.keys()) assert len(test) == 1 assert list(test)[0] == str self.widgets = {key:self.makeValueWidget(value) for key, value in dictionary.items()} + importantKeys = ("title", "composer", "instrument", "copyright") + #Draw important metadata widgets first + for k in importantKeys: + self.layout.addRow(k.title(), self.widgets[k]) + + self.layout.addRow(QHLine()) + + #Then the rest in alphabetical order for key, widget in sorted(self.widgets.items()): - self.layout.addRow(key.title(), widget) + if not key in importantKeys: + self.layout.addRow(key.title(), widget) self.__call__() @@ -513,8 +523,8 @@ class SecondaryProperties(Submenu): elif typ == QtWidgets.QSpinBox or typ == QtWidgets.QDoubleSpinBox: return widget.value() - def process(self): - api.session.score.metaData = {key:self.getValueFromWidget(widget) for key, widget in self.widgets.items()} + def process(self): + api.setMetadata({key:self.getValueFromWidget(widget) for key, widget in self.widgets.items()}) self.done(True) #Instance gets killed afterwards. No need to save the new values. diff --git a/template b/template index 22fc3c6..ff78979 160000 --- a/template +++ b/template @@ -1 +1 @@ -Subproject commit 22fc3c6bab656d7b13fb9dcdf48aaabe729ec4d1 +Subproject commit ff789798793af4981fe81b9d6f769a975735faea