Browse Source

fix regression reduce measure count

master
Nils 3 years ago
parent
commit
5f4994f799
  1. 89
      qtgui/songeditor.py

89
qtgui/songeditor.py

@ -176,7 +176,8 @@ class SongEditor(QtWidgets.QGraphicsScene):
self.setSceneRect(0,0,requestAmountOfMeasures*SIZE_UNIT,self.cachedCombinedTrackHeight + 3*SIZE_TOP_OFFSET) #no empty space on top without a scene rect
for track in self.tracks.values():
track.updateSwitchVisibility(requestAmountOfMeasures=requestAmountOfMeasures-1)
factor = track.exportDict["patternLengthMultiplicator"]
track.updateSwitchVisibility(requestAmountOfMeasures=(requestAmountOfMeasures-1) // factor)
track.updateStaffLines(requestAmountOfMeasures-1)
def callback_scoreChanged(self, exportDictScore):
@ -226,9 +227,10 @@ class TrackStructure(QtWidgets.QGraphicsRectItem):
self._mousePressOn = None #to remember the position of a mouse click
#self._markerLine = QtWidgets.QGraphicsLineItem(0,0,10,0) #only updated, never replaced
self._markerLine = QtWidgets.QGraphicsRectItem(0,0,10,SIZE_UNIT) #only updated, never replaced
self._markerLine.setParentItem(self)
self._markerLine.setY(0) #x is set in mousePressEvent
self._markerLine.setZValue(_zValuesRelativeToScene["playhead"])
#self._markerLine.setParentItem(self) #incompatible with zValues. We need this relative to the scene
self.parentScene.addItem(self._markerLine)
#self._markerLine.setY(self.pos().y()) #won't work yet. We are not in the scene ourselves. We set it in mousePressEvent, before show()
self._markerLine.setZValue(_zValuesRelativeToScene["switch"])
self._markerLine.hide()
#Semitransparent hover-switch to show which one would be activated/deactivated
@ -237,6 +239,7 @@ class TrackStructure(QtWidgets.QGraphicsRectItem):
self._highlightSwitch = QtWidgets.QGraphicsRectItem(0,0,SIZE_UNIT, SIZE_UNIT)
self._highlightSwitch.setParentItem(self)
self._highlightSwitch.setOpacity(0.2)
self._highlightSwitch.hide()
def _setColors(self, exportDict):
"""Called from various callbacks like updateSwitches and updateMetadata"""
@ -325,6 +328,8 @@ class TrackStructure(QtWidgets.QGraphicsRectItem):
whichPatternsAreHalftoneTransposed = self.exportDict["whichPatternsAreHalftoneTransposed"]
factor = self.exportDict["patternLengthMultiplicator"]
#requestAmountOfMeasures = requestAmountOfMeasures // factor #already is.
#Adjust highlight mouse hover to new stretch factor
r = self._highlightSwitch.rect()
r.setRight(SIZE_UNIT * factor)
@ -335,10 +340,11 @@ class TrackStructure(QtWidgets.QGraphicsRectItem):
switch.stretch(factor)
switch.setPos(position * SIZE_UNIT * factor, self.y())
#both position and requestAmountOfMeasures below are adjusted with scale factors
if not position in structure:
switch.hide() #Not delete because this may be just a temporary reduction of measures
switch.scaleTransposeOff()
elif position > requestAmountOfMeasures: #switch end is out of bounds. For factor 1 this is the same as not in the score-area
elif position >= requestAmountOfMeasures: #switch is out of bounds. For factor 1 this is the same as not in the score-area
switch.hide()
switch.scaleTransposeOff()
else:
@ -354,36 +360,6 @@ class TrackStructure(QtWidgets.QGraphicsRectItem):
else:
switch.halftoneTransposeOff()
def scenePos2switchPosition(self, x):
"""Map scene coordinates to counted switch engine position"""
factor = self.exportDict["patternLengthMultiplicator"]
return int(x / SIZE_UNIT / factor)
def mousePressEvent(self, event):
#First we need to find the mouse clicks position. self.switches only holds pos that were at least activated once.
#The track is only the area where the rectangles and lines meet. it is impossible to click below or right of the tracks.
#we always get a valid position this way.
if event.button() == QtCore.Qt.MiddleButton and not self._mousePressOn:
self.parentScene.parentView.parentMainWindow.patternGrid.createShadow(self.exportDict)
else:
self.parentScene.parentView.parentMainWindow.chooseCurrentTrack(self.exportDict)
if event.button() == QtCore.Qt.LeftButton:
assert not self._mousePressOn
position = self.scenePos2switchPosition(event.scenePos().x()) #measure number 0 based
self._markerLine.setX(position * SIZE_UNIT )
newBool = not position in self.switches or not self.switches[position].isVisible()
if newBool:
self._markerLine.setBrush(self.currentColor)
else:
self._markerLine.setBrush(self.parentScene.parentView.parentMainWindow.fPalBlue.color(QtGui.QPalette.AlternateBase)) #we are always the active track so this is our color
self._mousePressOn = (time(), self, position, newBool) #Reset to None in mouseReleaseEvent
result = api.setSwitch(self.exportDict["id"], position, newBool) #returns True if a switch happend
#elif event.button() == QtCore.Qt.RightButton and not self._mousePressOn:
#no, this is done with contextMenuEvent directly so it also reacts to the context menu keyboard key.
def contextMenuEvent(self, event):
if self._mousePressOn: #Right click can happen while the left button is still pressed down, which we don't want.
@ -415,10 +391,47 @@ class TrackStructure(QtWidgets.QGraphicsRectItem):
self.parentScene.parentView.parentMainWindow.setFocus()
menu.exec_(pos)
def scenePos2switchPosition(self, x):
"""Map scene coordinates to counted switch engine position"""
factor = self.exportDict["patternLengthMultiplicator"]
return int(x / SIZE_UNIT / factor)
def mousePressEvent(self, event):
#First we need to find the mouse clicks position. self.switches only holds pos that were at least activated once.
#The track is only the area where the rectangles and lines meet. it is impossible to click below or right of the tracks.
#we always get a valid position this way.
if event.button() == QtCore.Qt.MiddleButton and not self._mousePressOn:
self.parentScene.parentView.parentMainWindow.patternGrid.createShadow(self.exportDict)
else:
self.parentScene.parentView.parentMainWindow.chooseCurrentTrack(self.exportDict)
if event.button() == QtCore.Qt.LeftButton: #Create a switch or continue to hold down mouse button and drag to draw -> mouseMoveEvent
assert not self._mousePressOn
position = self.scenePos2switchPosition(event.scenePos().x()) #measure number 0 based
self._markerLine.setX(position * SIZE_UNIT * self.exportDict["patternLengthMultiplicator"])
self._markerLine.setY(self.pos().y()) #we can't do that in init because self is not in the scene by then. markerLine is a child directly to the scene, no magic reparenting.
newBool = not position in self.switches or not self.switches[position].isVisible()
if newBool:
self._markerLine.setBrush(self.currentColor)
else:
self._markerLine.setBrush(self.parentScene.parentView.parentMainWindow.fPalBlue.color(QtGui.QPalette.AlternateBase)) #we are always the active track so this is our color
self._mousePressOn = (time(), self, position, newBool) #Reset to None in mouseReleaseEvent
result = api.setSwitch(self.exportDict["id"], position, newBool) #returns True if a switch happend
#elif event.button() == QtCore.Qt.RightButton and not self._mousePressOn:
#no, this is done with contextMenuEvent directly so it also reacts to the context menu keyboard key.
def mouseMoveEvent(self, event):
"""In Patroneo this is only triggered when left mouse button is down.
"""Draw new switches by holding and dragging the mouse
This is only the visual aspect. Actual calcuation and insert is in mouseReleaseEvent
The initial _markerLine is setup in mousePressEvent, where the first switch is already set as well
In Patroneo this is only triggered when left mouse button is down.
We don't set the Qt flag to always react"""
position = self.scenePos2switchPosition(event.scenePos().x()) #measure number 0 based
factor = self.exportDict["patternLengthMultiplicator"]
if self._mousePressOn and position != self._mousePressOn[2]:
#self._markerLine.setLine(0,0, (position - self._mousePressOn[2])*SIZE_UNIT + SIZE_UNIT/2, 0)
rect = self._markerLine.rect()
@ -429,11 +442,11 @@ class TrackStructure(QtWidgets.QGraphicsRectItem):
if position < self._mousePressOn[2]:
left = (position - self._mousePressOn[2]) * SIZE_UNIT
rect.setLeft(left)
rect.setLeft(left*factor)
rect.setRight(SIZE_UNIT)
else:
right = (position - self._mousePressOn[2]) * SIZE_UNIT + SIZE_UNIT
rect.setRight(right)
rect.setRight(right*factor)
rect.setLeft(0)
self._markerLine.setRect(rect)

Loading…
Cancel
Save