Browse Source

Restore lilypond export

master
Nils 5 years ago
parent
commit
d8e944713a
  1. 7
      engine/api.py
  2. 2
      engine/config.py
  3. 34
      engine/lilypond.py
  4. 4
      engine/main.py
  5. 0
      engine/resources/lilypondTemplates/default.ly
  6. 0
      engine/resources/lilypondTemplates/minimal.ly
  7. 2
      engine/tempotrack.py
  8. 2
      qtgui/menu.py
  9. 20
      qtgui/submenus.py
  10. 2
      template

7
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"])

2
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" )),
}

34
engine/lilypond.py

@ -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:

4
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()

0
engine/resources/lilypondTemplate/default.ly → engine/resources/lilypondTemplates/default.ly

0
engine/resources/lilypondTemplate/minimal.ly → engine/resources/lilypondTemplates/minimal.ly

2
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

2
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):

20
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.

2
template

@ -1 +1 @@
Subproject commit 22fc3c6bab656d7b13fb9dcdf48aaabe729ec4d1
Subproject commit ff789798793af4981fe81b9d6f769a975735faea
Loading…
Cancel
Save