Browse Source

Add lilypond text string to tempo items, like allegro

master
Nils 2 years ago
parent
commit
af1e5b8f28
  1. 8
      engine/api.py
  2. 6
      engine/tempotrack.py
  3. 4
      qtgui/conductor.py
  4. 17
      qtgui/submenus.py

8
engine/api.py

@ -2169,9 +2169,9 @@ def _tempoTrackUndoCreater(description:str):
session.history.register(lambda d=old: _lazyTempoTrackUndoRedo(d, description), descriptionString=description)
callbacks._historyChanged()
def addTempoItem(blockId, positionInTicksRelativeToBlock, unitsPerMinute, referenceTicks, graphType = "standalone"):
def addTempoItem(blockId, positionInTicksRelativeToBlock, unitsPerMinute, referenceTicks, graphType="standalone", description:str=""):
"""blockId includes the track as well as the CC"""
tempoItem = TempoItem(unitsPerMinute, referenceTicks)
tempoItem = TempoItem(unitsPerMinute, referenceTicks, description)
tempoItem.graphType = graphType
_addExistingTempoItem(blockId, positionInTicksRelativeToBlock, tempoItem) #handles undo and callbacks
return tempoItem
@ -2280,10 +2280,10 @@ def deleteTempoBlock(tempoBlockId):
session.history.register(lambda d=old, desc="Delete Tempo Block": _lazyTempoTrackUndoRedo(d, desc), descriptionString="Delete Tempo Block")
callbacks._updateTempoTrack()
def insertTempoItemAtAbsolutePosition(tickPositionAbsolute, unitsPerMinute, referenceTicks, graphType):
def insertTempoItemAtAbsolutePosition(tickPositionAbsolute, unitsPerMinute, referenceTicks, graphType, description:str):
blockId, blockPosition = session.data.tempoTrack.tempoBlocKByAbsolutePosition(tickPositionAbsolute)
positionInTicksRelativeToBlock = tickPositionAbsolute - blockPosition
addTempoItem(blockId, positionInTicksRelativeToBlock, unitsPerMinute, referenceTicks, graphType)
addTempoItem(blockId, positionInTicksRelativeToBlock, unitsPerMinute, referenceTicks, graphType, description)
def tempoAtTickPosition(tick):
tempoItem = session.data.tempoTrack.tempoAtTickPosition(tick)

6
engine/tempotrack.py

@ -44,11 +44,11 @@ class TempoItem(object):
allTempoItems = WeakValueDictionary() #key is the id, value is the weak reference to the tempo item
#tempoTrack = the only tempo track. set by tempo track init, which happens only once in the program.
def __init__(self, unitsPerMinute, referenceTicks): # 120 quarter notes per minute is unitsPerMinute=120, referenceTicks=D4
def __init__(self, unitsPerMinute, referenceTicks, description=""): # 120 quarter notes per minute is unitsPerMinute=120, referenceTicks=D4
self.unitsPerMinute = round(unitsPerMinute)
self.referenceTicks = round(referenceTicks)
self.graphType = "standalone" #options: linear, standalone
self.lilypondParameters = {"tempo":""} #for example 'Allegro' or 'Ein bischen schneller'. Only strings are allowed.
self.lilypondParameters = {"tempo": description} #for example 'Allegro' or 'Ein bischen schneller'. Only strings are allowed.
self._secondInit(parentBlock = None)
def _secondInit(self, parentBlock):
@ -710,7 +710,7 @@ class TempoTrack(GraphTrackCC):
t = tempoItem["lilypondParameters"]["tempo"]
d = duration.ticksToLilypond(tempoItem["referenceTicks"])
upm = str(tempoItem["unitsPerMinute"])
return f"\\tempo {t} {d} = {upm} {skipString}"
return f"\\tempo \"{t}\" {d} = {upm} {skipString}"
#return "\\tempo {} {} = {} {}".format(tempoItem["lilypondParameters"]["tempo"], duration.baseDurationToTraditionalNumber[tempoItem["referenceTicks"]], str(tempoItem["unitsPerMinute"]), skipString)
raise NotImplementedError

4
qtgui/conductor.py

@ -170,7 +170,7 @@ class Conductor(QtWidgets.QGraphicsItem):
sp = round(sp / constantsAndConfigs.gridRhythm) * constantsAndConfigs.gridRhythm
unitsPerMinute, referenceTicks = api.tempoAtTickPosition(sp)
api.insertTempoItemAtAbsolutePosition(sp, unitsPerMinute, referenceTicks, graphType = "standalone")
api.insertTempoItemAtAbsolutePosition(sp, unitsPerMinute, referenceTicks, graphType = "standalone", description="")
class ConductorTransparentBlock(QtWidgets.QGraphicsRectItem):
"""A simplified version of a Block. Since we don't use blocks in the GUI, only in the backend
@ -494,7 +494,7 @@ class TempoPoint(QtWidgets.QGraphicsItem):
for n in (self.note, self.number, self.arrow):
if n: n.setDefaultTextColor(QtGui.QColor("black"))
if self.wheelEventChangedValue:
api.insertTempoItemAtAbsolutePosition(self.staticExportItem["position"], self.staticExportItem["unitsPerMinute"] + self.wheelEventChangedValue, self.staticExportItem["referenceTicks"], self.staticExportItem["graphType"])
api.insertTempoItemAtAbsolutePosition(self.staticExportItem["position"], self.staticExportItem["unitsPerMinute"] + self.wheelEventChangedValue, self.staticExportItem["referenceTicks"], self.staticExportItem["graphType"], self.staticExportItem["lilypondParameters"]["tempo"], )
else:
event.accept()

17
qtgui/submenus.py

@ -262,12 +262,12 @@ class SecondaryTempoChangeMenu(Submenu):
def __init__(self, mainWindow, staticExportTempoItem = None):
super().__init__(mainWindow, translate("submenus", "choose units per minute, reference note, graph type"), hasOkCancelButtons=True)
super().__init__(mainWindow, translate("submenus", "choose units per minute, reference note, graph type\nand an optional description like 'Allegro'"), hasOkCancelButtons=True)
self.mainWindow = mainWindow
self.staticExportTempoItem = staticExportTempoItem
tickindex, unitsPerMinute, referenceTicks, graphType = self.getCurrentValues() #takes self.staticExportTempoItem into account
tickindex, unitsPerMinute, referenceTicks, graphType, description = self.getCurrentValues() #takes self.staticExportTempoItem into account
self.unitbox = QtWidgets.QSpinBox()
self.unitbox.setMinimum(1)
@ -286,24 +286,29 @@ class SecondaryTempoChangeMenu(Submenu):
self.interpolationList.setCurrentIndex(l.index(graphType))
self.layout.addWidget(self.interpolationList)
self.description = QtWidgets.QLineEdit(description)
self.layout.addWidget(self.description)
self.__call__()
def process(self):
"""It says 'insert' but the backend is a dict. Changes are simply made by overwriting the
whole thing and the backend sends new data to draw to the GUI"""
tickindex, unitsPerMinute, referenceTicks, graphType = self.getCurrentValues()
tickindex, unitsPerMinute, referenceTicks, graphType, description = self.getCurrentValues()
newReferenceTicks = constantsAndConfigs.prettyExtendedRhythmsValues[self.referenceList.currentIndex()]
graphType = api.getListOfGraphInterpolationTypesAsStrings()[self.interpolationList.currentIndex()]
api.insertTempoItemAtAbsolutePosition(tickindex, self.unitbox.value(), newReferenceTicks, graphType)
description = self.description.text()
api.insertTempoItemAtAbsolutePosition(tickindex, self.unitbox.value(), newReferenceTicks, graphType, description)
self.done(True)
def getCurrentValues(self):
"""Get the current values from the note-editing backend cursor"""
if self.staticExportTempoItem:
return self.staticExportTempoItem["position"], self.staticExportTempoItem["unitsPerMinute"], self.staticExportTempoItem["referenceTicks"], self.staticExportTempoItem["graphType"],
return self.staticExportTempoItem["position"], self.staticExportTempoItem["unitsPerMinute"], self.staticExportTempoItem["referenceTicks"], self.staticExportTempoItem["graphType"], self.staticExportTempoItem["lilypondParameters"]["tempo"]
else:
assert self.mainWindow.scoreView.scoreScene.cursor.cursorExportObject
return self.mainWindow.scoreView.scoreScene.cursor.cursorExportObject["tickindex"], self.mainWindow.scoreView.scoreScene.cursor.cursorExportObject["tempoUnitsPerMinute"], self.mainWindow.scoreView.scoreScene.cursor.cursorExportObject["tempoReferenceTicks"], self.mainWindow.scoreView.scoreScene.cursor.cursorExportObject["tempoGraphType"],
return self.mainWindow.scoreView.scoreScene.cursor.cursorExportObject["tickindex"], self.mainWindow.scoreView.scoreScene.cursor.cursorExportObject["tempoUnitsPerMinute"], self.mainWindow.scoreView.scoreScene.cursor.cursorExportObject["tempoReferenceTicks"], self.mainWindow.scoreView.scoreScene.cursor.cursorExportObject["tempoGraphType"], "" #empty string is the description
class SecondaryTemporaryTempoChangeMenu(Submenu):
"""Essentially: What kind of fermata effect do you want?"""

Loading…
Cancel
Save