Browse Source

Add option to lilypond metadata to not print tempo markings, because laborejo always has them but you don't need them sometimes

master
Nils 3 years ago
parent
commit
310a219b0f
  1. 1
      engine/api.py
  2. 7
      engine/main.py
  3. 31
      qtgui/submenus.py
  4. 35
      template/qtgui/helper.py

1
engine/api.py

@ -309,6 +309,7 @@ def startEngine(nsmClient, additionalData:dict={}):
#General and abstract Commands
def getMetadata():
"""Do not confuse with template/config METADATA. This is Lilypond title, composer etc."""
return session.data.metaData
def setMetadata(data):

7
engine/main.py

@ -44,8 +44,10 @@ class Data(template.engine.sequencer.Score):
self.hiddenTracks = {} #track-instance:original Position. The value can exist multiple times. These still create a playback representation but are read-only and do not react to editing or GUI requests because you can't access them except through Track.allTrack (which is exactly the same for deleted tracks). Hidden tracks are saved though, deleted ones not.
self.tempoTrack = TempoTrack(parentData = self) #The tempoTrack is a Laborejo class. TempoMap is a template.sequencer class that is used by TempoTrack internally
#Metadata has only strings as keys, even the numbers.
#Lilypond Properties that might be used elsewhere as well, e.g. JACK Pretty Names
self.metaData = {key:"" for key in ("title", "subtitle", "dedication","composer","subsubtitle","instrument","meter","arranger", "poet","piece","opus","copyright","tagline", "subtext")}
self.metaData["metronome"] = True #show metronome in printout?
self.currentMetronomeTrack = self.tracks[0] #A Laborejo Track, indepedent of currentTrack. The metronome is in self.metronome, set by the template Score.
self._processAfterInit()
@ -1046,7 +1048,7 @@ class Data(template.engine.sequencer.Score):
Only visible tracks get exported.
Each object controls what it exports. Overrides are possible at every level.
"""
tempoStaff = self.tempoTrack.lilypond()
tempoStaff = self.tempoTrack.lilypond() if self.metaData["metronome"] else ""
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)
@ -1087,4 +1089,3 @@ class Data(template.engine.sequencer.Score):
"subdivisions" : self.subdivisions,
"isTransportMaster" : self.tempoMap.export()["isTransportMaster"],
}

31
qtgui/submenus.py

@ -30,7 +30,7 @@ translate = QtCore.QCoreApplication.translate
#Template
import template.engine.pitch as pitch
from template.qtgui.helper import QHLine
from template.qtgui.helper import QHLine, makeValueWidget, getValueFromWidget
from template.qtgui.submenus import *
#Our own files
@ -417,13 +417,13 @@ class SecondaryProperties(Submenu):
"""Directly edits the backend score meta data. There is no api and no callbacks"""
super().__init__(mainWindow, translate("submenus", "Meta Data"), hasOkCancelButtons=True)
dictionary = api.getMetadata() #TOOD: untranslated to keep relation to lilypond?
dictionary = api.getMetadata() #Do not confuse with template/config METADATA. This is Lilypond title, composer etc.
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()}
self.widgets = {key:makeValueWidget(value) for key, value in dictionary.items()}
importantKeys = ("title", "composer", "instrument", "copyright")
#Draw important metadata widgets first
@ -439,31 +439,8 @@ class SecondaryProperties(Submenu):
self.__call__()
def makeValueWidget(self, value):
types = {
str : QtWidgets.QLineEdit,
int : QtWidgets.QSpinBox,
float : QtWidgets.QDoubleSpinBox,
}
typ = type(value)
widget = types[typ]()
if typ == str:
widget.setText(value)
elif typ == int or typ == float:
widget.setValue(value)
return widget
def getValueFromWidget(self, widget):
typ = type(widget)
if typ == QtWidgets.QLineEdit:
return widget.text()
elif typ == QtWidgets.QSpinBox or typ == QtWidgets.QDoubleSpinBox:
return widget.value()
def process(self):
api.setMetadata({key:self.getValueFromWidget(widget) for key, widget in self.widgets.items()})
api.setMetadata({key:getValueFromWidget(widget) for key, widget in self.widgets.items()})
self.done(True)
#Instance gets killed afterwards. No need to save the new values.

35
template/qtgui/helper.py

@ -26,6 +26,41 @@ from PyQt5 import QtCore, QtGui, QtWidgets
from hashlib import md5
def makeValueWidget(value:any):
"""Create a widget just from a value. Needs an external label e.g. in a formLayout.
First usecase was laborejo lilypond metadata and properties where it edited an engine-dict
directly and inplace.
Use with getValueFromWidget"""
types = {
str : QtWidgets.QLineEdit,
int : QtWidgets.QSpinBox,
float : QtWidgets.QDoubleSpinBox,
bool : QtWidgets.QCheckBox,
}
typ = type(value)
widget = types[typ]()
if typ == str:
widget.setText(value)
elif typ == int or typ == float:
widget.setValue(value)
elif typ == bool:
widget.setChecked(value)
return widget
def getValueFromWidget(widget):
"""Use with makeValueWidget"""
typ = type(widget)
if typ == QtWidgets.QLineEdit:
return widget.text()
elif typ == QtWidgets.QSpinBox or typ == QtWidgets.QDoubleSpinBox:
return widget.value()
elif typ == QtWidgets.QCheckBox:
return widget.isChecked()
def iconFromString(st, size=128):
px = QtGui.QPixmap(size,size)
color = stringToColor(st)

Loading…
Cancel
Save