diff --git a/engine/api.py b/engine/api.py index 3b86899..07253cc 100644 --- a/engine/api.py +++ b/engine/api.py @@ -774,12 +774,16 @@ def joinBlock(): def deleteBlock(blockId): track, block = session.data.blockById(blockId) oldBlockArrangement = track.asListOfBlockIds() - parentTrack, deletedBlock = track.deleteBlock(block) - if (parentTrack and deletedBlock): #not the last block + result = track.deleteBlock(block) + if result: #not the last block + parentTrack, deletedBlock = result #Blocks are never truly deleted but a stored in the Block.allBlocks dict. This keeps the reference to this deleted block alive and it can be added through rearrange, which gets its blocks from this dict. session.history.register(lambda i=id(track), l=oldBlockArrangement: rearrangeBlocks(i, l), descriptionString = "delete block") callbacks._updateTrack(id(track)) callbacks._setCursor() + return True + else: + return False def deleteCurrentBlock(): currentBlockId = id(session.data.currentTrack().currentBlock()) @@ -837,7 +841,7 @@ def moveBlockToOtherTrack(blockId, newTrackId, listOfBlockIdsForNewTrack): newTrack.appendExistingBlock(block) newTrack.rearrangeBlocks(listOfBlockIdsForNewTrack) #We don't need to check if deleting succeeded because we already checked if there are more than 1 blocks in the track above. - oldTrack.deleteBlock(block) #It is important that we delete the block at exactly this point in time, not ealier. Otherwise the reference for undo will go away. + oldTrack.deleteBlock(block) #Check for last block is above. It is important that we delete the block at exactly this point in time, not ealier. Otherwise the reference for undo will go away. block.parentTrack = newTrack callbacks._updateTrack(id(oldTrack)) @@ -1924,7 +1928,7 @@ def moveCCBlockToOtherTrack(graphBlockId, newTrackId, listOfBlockIdsForNewTrack) newGraphTrack.appendExistingGraphBlock(graphBlock) newGraphTrack.rearrangeBlocks(listOfBlockIdsForNewTrack) - oldccTrack.deleteBlock(graphBlock) #It is important that we delete the block at exactly this point in time, not ealier. Otherwise the reference for undo will go away. + oldccTrack.deleteBlock(graphBlock) #Check for last block is above. It is important that we delete the block at exactly this point in time, not earlier. Otherwise the reference for undo will go away. graphBlock.parentGraphTrack = newGraphTrack callbacks._updateGraphTrackCC(trId, cc) diff --git a/engine/items.py b/engine/items.py index b8cbf3c..646b5eb 100644 --- a/engine/items.py +++ b/engine/items.py @@ -1136,6 +1136,7 @@ class Chord(Item): note = self.getNearestNote(pitch) oldValueForUndo = note.pitch note.octaveDown() + self.notelist.sort() self._cachedClefForLedgerLines = None return lambda: self._setNotePitch(note, oldValueForUndo) diff --git a/engine/track.py b/engine/track.py index b3ccf84..cca7492 100644 --- a/engine/track.py +++ b/engine/track.py @@ -448,6 +448,8 @@ class Track(object): block.parentTrack = None self.toPosition(originalPosition, strict = False) #has head() in it. strict=False just leaves the cursor at head if we can't return to the position because it got deleted. return self, block #self is parent Track + else: + return False def currentBlock(self): block = self.blocks[self.state.blockindex] @@ -601,7 +603,8 @@ class Track(object): while not self.state.ticksSinceLastMeasureStartLive <= 0: self.left() while self.left(): #stops automatically at the beginning of the track - if self.currentItem().logicalDuration() > 0 or not self.state.ticksSinceLastMeasureStartLive == 0: #we found the boundary between this measure and the one before it + curItem = self.currentItem() + if curItem and curItem.logicalDuration() > 0 or not self.state.ticksSinceLastMeasureStartLive == 0: #we found the boundary between this measure and the one before it self.right() break else: diff --git a/qtgui/conductor.py b/qtgui/conductor.py index 2f7236a..292998d 100644 --- a/qtgui/conductor.py +++ b/qtgui/conductor.py @@ -605,7 +605,7 @@ class TimeLine(QtWidgets.QGraphicsItem): secondsSinceLastTempoChange = gridCounter * self.gridInSeconds - sliceStartInSeconds posInTicks = nowPoint["position"] + secondsSinceLastTempoChange * ticksPerSecondForThisSlice - assert nowPoint["position"] <= posInTicks <= nextPoint["position"] + assert nowPoint["position"] <= posInTicks <= nextPoint["position"], (nowPoint["position"], posInTicks, nextPoint["position"]) result.append((posInTicks, gridCounter * self.gridInSeconds)) sliceStartInSeconds = sliceEndInSeconds diff --git a/qtgui/items.py b/qtgui/items.py index 8b0e470..8a04df6 100644 --- a/qtgui/items.py +++ b/qtgui/items.py @@ -485,7 +485,7 @@ class GuiChord(GuiItem): for noteExportObject in self.staticItem["notelist"]: #notes in a chord come in the order highest to lowest #determine if we have two neighbouring noteheads. If yes we shift one of the heads to the right - assert lastDotOnLine >= noteExportObject["dotOnLine"] + assert lastDotOnLine >= noteExportObject["dotOnLine"], (lastDotOnLine, noteExportObject["dotOnLine"]) #If this fails means the engine function did not call Chord.notelist.sort() after modification if lastDotOnLine - noteExportObject["dotOnLine"] == 1: moveThisNoteheadToTheRight = True lastDotOnLine = noteExportObject["dotOnLine"]