Browse Source

Always show the track name and index in block mode. Also add the track index to the track editor

master
Nils 2 years ago
parent
commit
06b672a2d5
  1. 26
      qtgui/musicstructures.py
  2. 18
      qtgui/scorescene.py
  3. 2
      qtgui/scoreview.py
  4. 3
      qtgui/trackEditor.py

26
qtgui/musicstructures.py

@ -205,8 +205,12 @@ class GuiTrack(QtWidgets.QGraphicsItem):
self.ccPaths = {} # ccNumber0-127:PathItem. Empty for a new track. We only create ccPaths with the first ccBlock. Creation and handling is done in GuiScore, starting with syncCCsToBackend. self.ccPaths = {} # ccNumber0-127:PathItem. Empty for a new track. We only create ccPaths with the first ccBlock. Creation and handling is done in GuiScore, starting with syncCCsToBackend.
self.setFlag(QtWidgets.QGraphicsItem.ItemIsMovable, True) self.setFlag(QtWidgets.QGraphicsItem.ItemIsMovable, True)
self.nameGraphic = self.NameGraphic(self.staticExportItem["name"], parent = self) self.nameGraphic = self.NameGraphic("", parent = self)
self.staticItems.append(self.nameGraphic) self.staticItems.append(self.nameGraphic)
self.nameGraphic.updateName(self.staticExportItem)
self.blockModeNameGraphic = self.NameGraphic("", parent = self) #additional name graphic in block mode that is always visible
self.staticItems.append(self.blockModeNameGraphic)
self.blockModeNameGraphic.updateName(self.staticExportItem)
#Add one central "Create new CC Path" button which is for all non-existing CC Paths of this track and reacte to the current constantsAndConfig.ccValue #Add one central "Create new CC Path" button which is for all non-existing CC Paths of this track and reacte to the current constantsAndConfig.ccValue
#This button is not in the CCPath object because those only get created for existing backend-CCs. #This button is not in the CCPath object because those only get created for existing backend-CCs.
@ -221,6 +225,9 @@ class GuiTrack(QtWidgets.QGraphicsItem):
class NameGraphic(QtWidgets.QGraphicsSimpleTextItem): class NameGraphic(QtWidgets.QGraphicsSimpleTextItem):
"""The update callback is in scoreScene.redraw()"""
def __init__(self, text, parent): def __init__(self, text, parent):
super().__init__(text) super().__init__(text)
self.setFlags(QtWidgets.QGraphicsItem.ItemIgnoresParentOpacity) self.setFlags(QtWidgets.QGraphicsItem.ItemIgnoresParentOpacity)
@ -241,6 +248,10 @@ class GuiTrack(QtWidgets.QGraphicsItem):
callContextMenu(listOfLabelsAndFunctions) callContextMenu(listOfLabelsAndFunctions)
event.accept() event.accept()
def updateName(self, trackExportObject:dict):
self.setText(f"Track {trackExportObject['index']+1} - {trackExportObject['name']}")
def secondStageInitNowThatWeHaveAScene(self): def secondStageInitNowThatWeHaveAScene(self):
"""ScoreScene.redraw() calls this after the track was inserted into the scene and therefore """ScoreScene.redraw() calls this after the track was inserted into the scene and therefore
has a position, opacity, parent item etc. (All of that is not read in normal __init__)""" has a position, opacity, parent item etc. (All of that is not read in normal __init__)"""
@ -265,9 +276,16 @@ class GuiTrack(QtWidgets.QGraphicsItem):
beam.rectangle.setVisible(constantsAndConfigs.noteHeadMode) beam.rectangle.setVisible(constantsAndConfigs.noteHeadMode)
def redraw(self, staticRepresentationList): def redraw(self, staticRepresentationList):
"""Called very often. For example after each note insert into the track.
But not after a mode change"""
self.createGraphicItemsFromData(staticRepresentationList) self.createGraphicItemsFromData(staticRepresentationList)
self.nameGraphic.setPos(30 + self.lengthInPixel, -1*constantsAndConfigs.stafflineGap) #self.lengthInPixel is now up to date self.nameGraphic.setPos(30 + self.lengthInPixel, -1*constantsAndConfigs.stafflineGap) #self.lengthInPixel is now up to date
def centerBlockModeNameGraphic(self, centerSceneX):
"""Attached to the horizontal scrollbar.
Instead of calculating X in every track we do it once in parentScore.reactToHorizontalScroll()"""
self.blockModeNameGraphic.setPos(centerSceneX, (-5*constantsAndConfigs.stafflineGap)) #y is in track coordinates
def paintBlockBackgroundColors(self, staticBlocksRepresentation): def paintBlockBackgroundColors(self, staticBlocksRepresentation):
"""This gets not called by self.createGraphicItemsFromData but only by """This gets not called by self.createGraphicItemsFromData but only by
a score callback for blocksChanged""" a score callback for blocksChanged"""
@ -501,6 +519,8 @@ class GuiTrack(QtWidgets.QGraphicsItem):
self.universalCreateFirstCCBlock.hide() self.universalCreateFirstCCBlock.hide()
if nameAsString == "notation": if nameAsString == "notation":
self.blockModeNameGraphic.hide()
self.nameGraphic.show()
self.setOpacity(1) self.setOpacity(1)
for backgroundColor in self.backgroundBlockColors: #created in self.paintBlockBackgroundColors() for backgroundColor in self.backgroundBlockColors: #created in self.paintBlockBackgroundColors()
backgroundColor.setOpacity(0.2) backgroundColor.setOpacity(0.2)
@ -508,6 +528,8 @@ class GuiTrack(QtWidgets.QGraphicsItem):
tbh.itemMode() tbh.itemMode()
elif nameAsString == "cc": elif nameAsString == "cc":
self.blockModeNameGraphic.hide()
self.nameGraphic.show()
self.setOpacity(0.1) #the notes can still be seen in the background. self.setOpacity(0.1) #the notes can still be seen in the background.
if constantsAndConfigs.ccViewValue in self.ccPaths: #It is not guaranteed that all CC Values have content. On the contrary... if constantsAndConfigs.ccViewValue in self.ccPaths: #It is not guaranteed that all CC Values have content. On the contrary...
self.ccPaths[constantsAndConfigs.ccViewValue].show() self.ccPaths[constantsAndConfigs.ccViewValue].show()
@ -519,6 +541,8 @@ class GuiTrack(QtWidgets.QGraphicsItem):
tbh.itemMode() tbh.itemMode()
elif nameAsString == "block": elif nameAsString == "block":
self.blockModeNameGraphic.show()
self.nameGraphic.hide()
self.setOpacity(0) self.setOpacity(0)
for backgroundColor in self.backgroundBlockColors: #simple QRectItems, they don't have their own updateMode function for backgroundColor in self.backgroundBlockColors: #simple QRectItems, they don't have their own updateMode function
backgroundColor.setOpacity(1) backgroundColor.setOpacity(1)

18
qtgui/scorescene.py

@ -77,8 +77,6 @@ class GuiScore(QtWidgets.QGraphicsScene):
self.grid.setPos(0, -20 * constantsAndConfigs.stafflineGap) #this is more calculation than simply using self.yStart, and might require manual adjustment in the future, but at least it guarantees the grid matches the staffline positions self.grid.setPos(0, -20 * constantsAndConfigs.stafflineGap) #this is more calculation than simply using self.yStart, and might require manual adjustment in the future, but at least it guarantees the grid matches the staffline positions
self.grid.setZValue(-50) self.grid.setZValue(-50)
#All Cursors #All Cursors
self.cursor = Cursor() self.cursor = Cursor()
self.addItem(self.cursor) self.addItem(self.cursor)
@ -108,6 +106,8 @@ class GuiScore(QtWidgets.QGraphicsScene):
self.grid.updateMode(nameAsString) self.grid.updateMode(nameAsString)
self.reactToHorizontalScroll(0) #once force all block mode track names into the center. We cannot do this in init because the tracks are not ready by then. This assumes we always start the program in notation mode
def updateModeSingleTrackRedraw(self, nameAsString:str, trackId:int, trackExport:tuple): def updateModeSingleTrackRedraw(self, nameAsString:str, trackId:int, trackExport:tuple):
"""trackExport is a tuple of block export dicts""" """trackExport is a tuple of block export dicts"""
self.tracks[trackId].updateMode(nameAsString) self.tracks[trackId].updateMode(nameAsString)
@ -207,7 +207,8 @@ class GuiScore(QtWidgets.QGraphicsScene):
self.tracks[trackExportObject["id"]].staticExportItem = trackExportObject self.tracks[trackExportObject["id"]].staticExportItem = trackExportObject
self.tracks[trackExportObject["id"]].setPos(0, constantsAndConfigs.trackHeight * trackExportObject["index"] + doubleTrackOffset) self.tracks[trackExportObject["id"]].setPos(0, constantsAndConfigs.trackHeight * trackExportObject["index"] + doubleTrackOffset)
self.tracks[trackExportObject["id"]].setZValue(0) #direct comparison only possible with the grid, which is at -50 self.tracks[trackExportObject["id"]].setZValue(0) #direct comparison only possible with the grid, which is at -50
self.tracks[trackExportObject["id"]].nameGraphic.setText(trackExportObject["name"]) self.tracks[trackExportObject["id"]].nameGraphic.updateName(trackExportObject)
self.tracks[trackExportObject["id"]].blockModeNameGraphic.updateName(trackExportObject)
self.tracks[trackExportObject["id"]].show() self.tracks[trackExportObject["id"]].show()
if trackExportObject["double"]: if trackExportObject["double"]:
@ -601,3 +602,14 @@ class GuiScore(QtWidgets.QGraphicsScene):
api.toTickindex(trackId, event.scenePos().x() * constantsAndConfigs.ticksToPixelRatio) api.toTickindex(trackId, event.scenePos().x() * constantsAndConfigs.ticksToPixelRatio)
super().mouseReleaseEvent(event) super().mouseReleaseEvent(event)
def reactToHorizontalScroll(self, value:int):
"""This was created to keep the block-mode centered track name in the center when scrolling.
We forward to all tracks
At point of creation the scroll value was ignored."""
viewCenterAsScenePos = self.parentView.mapToScene(self.parentView.viewport().rect().topLeft())
centerSceneX = viewCenterAsScenePos.x() + 25 #just some padding
for track in self.tracks.values():
track.centerBlockModeNameGraphic(centerSceneX)
#we do not need to call super. this is attached with a connect signal, not a function override.

2
qtgui/scoreview.py

@ -63,6 +63,7 @@ class ScoreView(QtWidgets.QGraphicsView):
#self.setDragMode(QtWidgets.QGraphicsView.ScrollHandDrag) #self.setDragMode(QtWidgets.QGraphicsView.ScrollHandDrag)
self.setDragMode(QtWidgets.QGraphicsView.NoDrag) self.setDragMode(QtWidgets.QGraphicsView.NoDrag)
self.horizontalScrollBar().valueChanged.connect(self.scoreScene.reactToHorizontalScroll)
api.callbacks.setCursor.append(self.centerOnCursor) #returns a dict api.callbacks.setCursor.append(self.centerOnCursor) #returns a dict
self._lastSavedMode = None #CC, Blocks, Notes. for self.updateMode self._lastSavedMode = None #CC, Blocks, Notes. for self.updateMode
@ -88,7 +89,6 @@ class ScoreView(QtWidgets.QGraphicsView):
self.setStyleSheet(style) self.setStyleSheet(style)
def wheelEvent(self, event): def wheelEvent(self, event):
if QtWidgets.QApplication.keyboardModifiers() in (QtCore.Qt.ControlModifier, QtCore.Qt.ControlModifier|QtCore.Qt.ShiftModifier): #a workaround for a qt bug. see score.wheelEvent docstring. if QtWidgets.QApplication.keyboardModifiers() in (QtCore.Qt.ControlModifier, QtCore.Qt.ControlModifier|QtCore.Qt.ShiftModifier): #a workaround for a qt bug. see score.wheelEvent docstring.
event.ignore() #do not send to scene, but tell the mainWindow to use it. event.ignore() #do not send to scene, but tell the mainWindow to use it.

3
qtgui/trackEditor.py

@ -357,7 +357,7 @@ class TrackEditor(QtWidgets.QWidget):
widget = TrackWidget(self, trackExportObject) widget = TrackWidget(self, trackExportObject)
self.tracks[trackExportObject["id"]] = widget self.tracks[trackExportObject["id"]] = widget
self.layout.insertWidget(-1, widget) self.layout.insertWidget(-1, widget)
widget.setTitle("id: {}".format(trackExportObject["id"])) widget.setTitle(f'Track {trackExportObject["index"]+1} - id: {trackExportObject["id"]}')
else: else:
leftOver.remove(trackExportObject["id"]) leftOver.remove(trackExportObject["id"])
@ -467,4 +467,3 @@ class BlockGraphicsItem(QtWidgets.QGraphicsRectItem):
else: else:
return QtGui.QColor(255,255,255,255) #Return White return QtGui.QColor(255,255,255,255) #Return White
""" """

Loading…
Cancel
Save