def createBeams(self, beamList):
for b in self.beams:
self.parentScore.removeWhenIdle(b)
self.beams = []
for startTick, endTick, beamtype, positionAsStaffline, direction in beamList:
numberOfBeams = int(log(beamtype, 2)-2)
assert numberOfBeams == log(beamtype, 2)-2
for x in range(numberOfBeams):
if direction > 0: #stem/beam upwards
beamNumberOffset = 4*x
xOffset = 7
else:
beamNumberOffset = -4*x
xOffset = 1
#non-scalable X-Offsets are not possible via setPos. zoom and stretch go haywire.
#Instead we use one item for strechting and for the offset position and wrap it in an item group that is used for positioing.
shifterAnchor = QtWidgets.QGraphicsItemGroup()
shifterAnchor.setParentItem(self)
rectangle = QtWidgets.QGraphicsRectItem(0, 0, (endTick-startTick) / constantsAndConfigs.ticksToPixelRatio, constantsAndConfigs.beamHeight) #x, y, w, h
rectangle.setBrush(QtGui.QColor("black"))
shifterAnchor.addToGroup(rectangle)
shifterAnchor.rectangle = rectangle
rectangle.setPos(xOffset, 0)
if constantsAndConfigs.noteHeadMode:
rectangle.show()
else:
rectangle.hide()
self.beams.append(shifterAnchor)
x = startTick/ constantsAndConfigs.ticksToPixelRatio
y = beamNumberOffset + positionAsStaffline * constantsAndConfigs.stafflineGap / 2 - 1
shifterAnchor.setPos(x, y)
评论列表
文章目录