Browse Source

Add horizontal piano

master
Nils 3 years ago
parent
commit
61c8bf1b83
  1. 9
      engine/instrument.py
  2. 4
      qtgui/designer/mainwindow.py
  3. 5
      qtgui/designer/mainwindow.ui
  4. 405
      qtgui/horizontalpiano.py
  5. 9
      qtgui/mainwindow.py
  6. 40
      qtgui/verticalpiano.py

9
engine/instrument.py

@ -304,9 +304,12 @@ class Instrument(object):
if "sw_label" in data: if "sw_label" in data:
label = data["sw_label"] label = data["sw_label"]
#remove leading int or key from label #remove leading int or key from label
m = re.match("\d+", label) mMidipitch = re.match("\d+", label) and not label[1] == "'" and not label[2] == "'" # 8' or 16' organs begin with a number as well. We sadly can't check for a space after the number so we have to check for the foot symbol
if m: #could be None mNotename = re.match("(c|(c#)|(db)|d|(d#)|(eb)|e|(e#)|(fb)|f|(f#)|(gb)|g|(g#)|(ab)|a|(a#)|(bb)|b|(b#))\d+", label, re.IGNORECASE)
label = label[m.span()[1]:].lstrip() #remove number and potential leading space if mMidipitch: #could be None
label = label[mMidipitch.span()[1]:].lstrip() #remove number and potential leading space
elif mNotename:
label = label[mNotename.span()[1]:].lstrip() #remove notenames like C#6 and potential leading space
else: else:
label = "" label = ""

4
qtgui/designer/mainwindow.py

@ -106,7 +106,7 @@ class Ui_MainWindow(object):
self.scrollArea.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop) self.scrollArea.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
self.scrollArea.setObjectName("scrollArea") self.scrollArea.setObjectName("scrollArea")
self.mixerAreaWidget = QtWidgets.QWidget() self.mixerAreaWidget = QtWidgets.QWidget()
self.mixerAreaWidget.setGeometry(QtCore.QRect(0, 0, 1184, 510)) self.mixerAreaWidget.setGeometry(QtCore.QRect(0, 0, 98, 113))
self.mixerAreaWidget.setObjectName("mixerAreaWidget") self.mixerAreaWidget.setObjectName("mixerAreaWidget")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.mixerAreaWidget) self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.mixerAreaWidget)
self.horizontalLayout_2.setObjectName("horizontalLayout_2") self.horizontalLayout_2.setObjectName("horizontalLayout_2")
@ -165,6 +165,8 @@ class Ui_MainWindow(object):
self.horizontalPianoFrame.setFrameShape(QtWidgets.QFrame.StyledPanel) self.horizontalPianoFrame.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.horizontalPianoFrame.setFrameShadow(QtWidgets.QFrame.Raised) self.horizontalPianoFrame.setFrameShadow(QtWidgets.QFrame.Raised)
self.horizontalPianoFrame.setObjectName("horizontalPianoFrame") self.horizontalPianoFrame.setObjectName("horizontalPianoFrame")
self.horizontalLayout_4 = QtWidgets.QHBoxLayout(self.horizontalPianoFrame)
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.verticalLayout.addWidget(self.horizontalPianoFrame) self.verticalLayout.addWidget(self.horizontalPianoFrame)
self.horizontalLayout_3.addWidget(self.rightFrame) self.horizontalLayout_3.addWidget(self.rightFrame)
MainWindow.setCentralWidget(self.centralwidget) MainWindow.setCentralWidget(self.centralwidget)

5
qtgui/designer/mainwindow.ui

@ -281,8 +281,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1184</width> <width>98</width>
<height>510</height> <height>113</height>
</rect> </rect>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
@ -419,6 +419,7 @@
<property name="frameShadow"> <property name="frameShadow">
<enum>QFrame::Raised</enum> <enum>QFrame::Raised</enum>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_4"/>
</widget> </widget>
</item> </item>
</layout> </layout>

405
qtgui/horizontalpiano.py

@ -0,0 +1,405 @@
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Copyright 2021, Nils Hilbricht, Germany ( https://www.hilbricht.net )
This file is part of the Laborejo Software Suite ( https://www.laborejo.org ),
This is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import logging; logger = logging.getLogger(__name__); logger.info("import")
#Standard Library Modules
#Third Party Modules
from PyQt5 import QtWidgets, QtCore, QtGui, QtOpenGL
#Template Modules
from template.engine.duration import baseDurationToTraditionalNumber
#User modules
import engine.api as api
from .verticalpiano import WIDTH as HEIGHT
from .verticalpiano import STAFFLINEGAP as WIDTH
WIDTH = WIDTH * 1.5
SCOREWIDTH = WIDTH * 75 #75 white keys. The vertical piano does have a linear layout while we have the inverleaved piano one.
class HorizontalPiano(QtWidgets.QGraphicsView):
def __init__(self, mainWindow):
super().__init__(mainWindow)
self.mainWindow = mainWindow
self.setAlignment(QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
self.setDragMode(QtWidgets.QGraphicsView.NoDrag)
self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.pianoScene = _HorizontalPianoScene(self)
self.setScene(self.pianoScene)
self.setSceneRect(QtCore.QRectF(0, 0, SCOREWIDTH, HEIGHT)) #x,y,w,h
#self.setFixedHeight(SCOREHEIGHT+3) # Don't set to scoreheight. Then we don't get a scrollbar. We need to set the sceneRect to 100%, not the view.
#self.mainWindow.ui.horizontalPianoFrame.setFixedHeight(SCOREHEIGHT+3) #Don't. This makes the whole window a fixed size!
#self.setFixedWidth(WIDTH) #Also done by parent widget in mainWindow
self.setLineWidth(0)
self.centerOn(SCOREWIDTH/2, 0)
def wheelEvent(self, event):
"""Convert vertical scrolling to horizontal"""
event.accept() #eat the event
self.horizontalScrollBar().setValue(self.horizontalScrollBar().value() + event.pixelDelta().y()) #y because it is the original vert. scroll
class _HorizontalPianoScene(QtWidgets.QGraphicsScene):
"""Most of this is copy paste from piano grid"""
def __init__(self, parentView):
super().__init__()
self.parentView = parentView
#Set color, otherwise it will be transparent in window managers or wayland that want that.
self.backColor = QtGui.QColor()
self.backColor.setNamedColor("#fdfdff")
self.setBackgroundBrush(self.backColor)
self.linesHorizontal = []
self.allKeys = {} # pitch/int : BlackKey or WhiteKey
self.numberLabels = [] #index is pitch
self._selectedInstrument = None #tuple instrumentStatus, instrumentData
self._leftMouseDown = False #For note preview
self.gridPen = QtGui.QPen(QtCore.Qt.SolidLine)
self.gridPen.setCosmetic(True)
boldPen = QtGui.QPen(QtCore.Qt.SolidLine)
boldPen.setCosmetic(True)
boldPen.setWidth(1)
whitekeyCounter = 0
for i in range(128):
blackKey = i % 12 in (1, 3, 6, 8, 10)
if blackKey:
key = BlackKey(self, i)
x = whitekeyCounter * WIDTH - WIDTH/2
numberY = 0 #for later
if i < 100:
numberX = x + 4
else:
numberX = x
key.setPos(x, HEIGHT * -0.66)
key.setZValue(4)
else:
key = WhiteKey(self, i)
x = whitekeyCounter * WIDTH
key.setPos(x, 0)
key.setZValue(1)
if i < 100:
numberX = x + 5
else:
numberX = x + 3
numberY = HEIGHT/2 -3 #100 #for later
whitekeyCounter += 1
self.addItem(key) #we can setPos before adding to the scene.
self.allKeys[i] = key
if not blackKey:
vline = QtWidgets.QGraphicsLineItem(0, 0, 0, HEIGHT) #x1, y1, x2, y2
vline.setPen(self.gridPen)
self.addItem(vline)
vline.setPos(key.x(), 0)
vline.setEnabled(False)
vline.setAcceptedMouseButtons(QtCore.Qt.NoButton) #Disabled items discard the mouse event unless mouseButtons are not accepted
vline.setZValue(2) #above the white keys
self.linesHorizontal.append(vline)
#Numbers last so they are on top.
numberLabel = NumberLabel(self, i)
self.addItem(numberLabel)
self.numberLabels.append(numberLabel) #index is pitch
#numberLabel.setPos(i * WIDTH + 2, 0)
numberLabel.setPos(numberX, numberY)
numberLabel.setZValue(10)
self.fakeDeactivationOverlay = QtWidgets.QGraphicsRectItem(0,0, SCOREWIDTH, HEIGHT)
self.fakeDeactivationOverlay.setBrush(QtGui.QColor("black"))
self.fakeDeactivationOverlay.setOpacity(0.6)
self.fakeDeactivationOverlay.setEnabled(False)
self.fakeDeactivationOverlay.setAcceptedMouseButtons(QtCore.Qt.NoButton) #Disabled items discard the mouse event unless mouseButtons are not accepted
self.addItem(self.fakeDeactivationOverlay)
self.fakeDeactivationOverlay.setPos(0,0)
self.fakeDeactivationOverlay.setZValue(12) #above the numbers
self.fakeDeactivationOverlay.show()
#Keyboard Creation Done
api.callbacks.instrumentMidiNoteOnActivity.append(self.highlightNoteOn)
api.callbacks.instrumentMidiNoteOffActivity.append(self.highlightNoteOff)
api.callbacks.instrumentStatusChanged.append(self.instrumentStatusChanged)
def clearHorizontalPiano(self):
for keyPitch, keyObject in self.allKeys.items():
keyObject.show()
keyObject.highlightOff()
keyObject.setPlayable(False)
keyObject.setKeySwitch(False)
for nl in self.numberLabels:
nl.setLabel("") #reset to just number
self.fakeDeactivationOverlay.show()
def instrumentStatusChanged(self, instrumentStatus:dict):
"""GUI callback. Data is live"""
#Is this for us?
if instrumentStatus and self._selectedInstrument and not instrumentStatus["idKey"] == self._selectedInstrument[0]["idKey"]:
return
#else:
# print ("not for us", instrumentStatus["idKey"])
self.clearHorizontalPiano()
if not instrumentStatus["state"]:
self.fakeDeactivationOverlay.show()
return
self.fakeDeactivationOverlay.hide()
for keyPitch, keyObject in self.allKeys.items():
if keyPitch in instrumentStatus["keySwitches"]:
opcode, keyswitchLabel = instrumentStatus["keySwitches"][keyPitch]
self.numberLabels[keyPitch].setLabel(keyswitchLabel)
keyObject.setKeySwitch(True)
elif keyPitch in instrumentStatus["playableKeys"]:
keyObject.setPlayable(True)
#else:
#self.numberLabels[keyPitch].hide()
def selectedInstrumentChanged(self, instrumentStatus, instrumentData):
"""GUI click to different instrument. The arguments are cached GUI data
If a library is clicked, and not an instrument, both parameters will be None.
"""
if instrumentStatus is None:
self._selectedInstrument = None
self.clearHorizontalPiano()
self.fakeDeactivationOverlay.show()
else:
self._selectedInstrument = (instrumentStatus, instrumentData)
self.instrumentStatusChanged(instrumentStatus)
def highlightNoteOn(self, idKey:tuple, pitch:int, velocity:int):
self.allKeys[pitch].highlightOn()
def highlightNoteOff(self, idKey:tuple, pitch:int, velocity:int):
self.allKeys[pitch].highlightOff()
def allHighlightsOff(self):
for keyPitch, keyObject in self.allKeys.items():
keyObject[pitch].highlightNoteOff()
def mousePressEvent(self, event):
self._leftMouseDown = False
if event.button() == QtCore.Qt.LeftButton:
self._leftMouseDown = True
self._lastPlayPitch = None #this must not be in _play, otherwise you can't move the mouse while pressed down
self._play(event)
super().mousePressEvent(event)
def wheelEvent(self, event):
event.ignore() #let the view handle it, for the scrollbar
def _off(self):
if self._selectedInstrument and not self._lastPlayPitch is None:
status, data = self._selectedInstrument
libId, instrId = status["idKey"]
api.sendNoteOffToInstrument(status["idKey"], self._lastPlayPitch)
self._lastPlayPitch = None
def _play(self, event):
assert self._leftMouseDown
potentialItem = self.itemAt(event.scenePos(), self.parentView.transform() )
if not (potentialItem and type(potentialItem) in (BlackKey, WhiteKey)):
return
pitch = potentialItem.pitch
if pitch < 0 or pitch > 127:
pitch = None
if self._selectedInstrument and not pitch == self._lastPlayPitch:
#TODO: Play note on at a different instrument than note off? Possible?
status, data = self._selectedInstrument
if not self._lastPlayPitch is None:
#Force a note off that is currently playing but not under the cursor anymore
#User did some input tricks with keyboard and mouse combined etc.
api.sendNoteOffToInstrument(status["idKey"], self._lastPlayPitch)
if not pitch is None:
#This is the normal note-on click
api.sendNoteOnToInstrument(status["idKey"], pitch)
self._lastPlayPitch = pitch
def mouseMoveEvent(self, event):
"""Event button is always 0 in a mouse move event"""
if self._leftMouseDown:
self._play(event)
super().mouseMoveEvent(event)
def mouseReleaseEvent(self, event):
if self._leftMouseDown:
self._off()
self._leftMouseDown = False
if event.button() == QtCore.Qt.LeftButton:
self._lastPlayPitch = None
super().mouseReleaseEvent(event)
class NumberLabel(QtWidgets.QGraphicsSimpleTextItem):
"""In opposite to verticalPiano the key label is a different childItem as the number"""
def __init__(self, parentGrid, number:int):
super().__init__()
self.parentGrid = parentGrid
self.number = number
self.labelItem = QtWidgets.QGraphicsSimpleTextItem("")
self.labelItem.setParentItem(self)
self.currentLabel = ""
self.setText(str(number))
self.setFlag(QtWidgets.QGraphicsItem.ItemIgnoresParentOpacity, True)
self.setAcceptedMouseButtons(QtCore.Qt.NoButton)
blackKey = number % 12 in (1, 3, 6, 8, 10)
if blackKey:
self.setBrush(QtGui.QColor("white"))
self.labelItem.setBrush(QtGui.QColor("white"))
self.setScale(0.9)
self.labelItem.setRotation(90)
self.labelItem.setPos(15,15)
else:
self.setBrush(QtGui.QColor("black"))
self.labelItem.setBrush(QtGui.QColor("black"))
self.setScale(1)
self.labelItem.setRotation(-90)
self.labelItem.setPos(-5,0)
def setLabel(self, label:str):
"""Each key can have an optional text label for keyswitches, percussion names etc.
Use with empty string to reset to just the midi pitch number."""
self.currentLabel = label
self.labelItem.setText(label)
class BlackKey(QtWidgets.QGraphicsRectItem):
def __init__(self, parentGrid, pitch):
super().__init__(0, 0, WIDTH * 0.8, HEIGHT) #x, y, w, h
self.parentGrid = parentGrid
self.pitch = pitch
self.setPen(QtGui.QPen(QtCore.Qt.NoPen))
self.setBrush(QtGui.QColor("black"))
self.setEnabled(False)
self.setAcceptedMouseButtons(QtCore.Qt.NoButton)
self.decorationOverlay = QtWidgets.QGraphicsRectItem(0, 0, WIDTH * 0.8, HEIGHT) #x, y, w, h
self.decorationOverlay.setEnabled(False)
self.decorationOverlay.setAcceptedMouseButtons(QtCore.Qt.NoButton)
self.decorationOverlay.setFlag(QtWidgets.QGraphicsItem.ItemIgnoresParentOpacity, True)
self.decorationOverlay.setOpacity(0.2) #just a tint
self.decorationOverlay.hide()
self.decorationOverlay.setParentItem(self)
self.highlight = QtWidgets.QGraphicsRectItem(0, 0, WIDTH * 0.8, HEIGHT) #x, y, w, h
self.highlight.setEnabled(False)
self.highlight.setAcceptedMouseButtons(QtCore.Qt.NoButton)
self.highlight.setFlag(QtWidgets.QGraphicsItem.ItemIgnoresParentOpacity, True)
self.highlight.setOpacity(0.5)
self.highlight.setBrush(QtGui.QColor("cyan"))
self.highlight.hide()
self.highlight.setParentItem(self)
def setPlayable(self, state:bool):
if state:
self.decorationOverlay.show()
self.decorationOverlay.setBrush(QtGui.QColor("orange"))
else:
self.decorationOverlay.hide()
def setKeySwitch(self, state:bool):
if state:
self.decorationOverlay.show()
self.decorationOverlay.setBrush(QtGui.QColor("red"))
else:
self.decorationOverlay.hide()
def highlightOn(self):
self.highlight.show()
def highlightOff(self):
self.highlight.hide()
class WhiteKey(QtWidgets.QGraphicsRectItem):
def __init__(self, parentGrid, pitch:int):
super().__init__(0, 0, WIDTH, HEIGHT) #x, y, w, h
self.parentGrid = parentGrid
self.pitch = pitch
self.setPen(QtGui.QPen(QtCore.Qt.NoPen))
self.setBrush(QtGui.QColor("white"))
self.setEnabled(False)
self.setAcceptedMouseButtons(QtCore.Qt.NoButton)
self.decorationOverlay = QtWidgets.QGraphicsRectItem(0, 0, WIDTH, HEIGHT) #x, y, w, h
self.decorationOverlay.setEnabled(False)
self.decorationOverlay.setAcceptedMouseButtons(QtCore.Qt.NoButton)
self.decorationOverlay.setFlag(QtWidgets.QGraphicsItem.ItemIgnoresParentOpacity, True)
self.decorationOverlay.setOpacity(0.2) #just a tint
self.decorationOverlay.hide()
self.decorationOverlay.setParentItem(self)
self.highlight = QtWidgets.QGraphicsRectItem(0, 0, WIDTH, HEIGHT) #x, y, w, h
self.highlight.setEnabled(False)
self.highlight.setAcceptedMouseButtons(QtCore.Qt.NoButton)
self.highlight.setFlag(QtWidgets.QGraphicsItem.ItemIgnoresParentOpacity, True)
self.highlight.setOpacity(0.5)
self.highlight.setBrush(QtGui.QColor("cyan"))
self.highlight.hide()
self.highlight.setParentItem(self)
def setPlayable(self, state:bool):
if state:
self.decorationOverlay.show()
self.decorationOverlay.setBrush(QtGui.QColor("orange"))
else:
self.decorationOverlay.hide()
def setKeySwitch(self, state:bool):
if state:
self.decorationOverlay.show()
self.decorationOverlay.setBrush(QtGui.QColor("red"))
else:
self.decorationOverlay.hide()
def highlightOn(self):
self.highlight.show()
def highlightOff(self):
self.highlight.hide()

9
qtgui/mainwindow.py

@ -40,6 +40,7 @@ from .instrument import InstrumentTreeController
from .auditioner import AuditionerMidiInputComboController from .auditioner import AuditionerMidiInputComboController
from .selectedinstrumentcontroller import SelectedInstrumentController from .selectedinstrumentcontroller import SelectedInstrumentController
from .verticalpiano import VerticalPiano from .verticalpiano import VerticalPiano
from .horizontalpiano import HorizontalPiano
from .chooseDownloadDirectory import ChooseDownloadDirectory from .chooseDownloadDirectory import ChooseDownloadDirectory
class MainWindow(TemplateMainWindow): class MainWindow(TemplateMainWindow):
@ -83,12 +84,11 @@ class MainWindow(TemplateMainWindow):
#Set up the two pianos #Set up the two pianos
self.verticalPiano = VerticalPiano(self) self.verticalPiano = VerticalPiano(self)
self.ui.verticalPianoFrame.layout().addWidget(self.verticalPiano) #add to DesignerUi. Layout is empty self.ui.verticalPianoFrame.layout().addWidget(self.verticalPiano) #add to DesignerUi. Layout is empty
#self.verticalPiano.setParent()
self.ui.verticalPianoFrame.setFixedWidth(150) self.ui.verticalPianoFrame.setFixedWidth(150)
#self.horizontalPiano = HorizontalPiano(self) self.horizontalPiano = HorizontalPiano(self)
#self.ui.horizontalPianoScrollArea.setWidget(self.horizontalPiano) self.ui.horizontalPianoFrame.layout().addWidget(self.horizontalPiano) #add to DesignerUi. Layout is empty
self.ui.horizontalPianoFrame.setFixedHeight(150)
style = """ style = """
QScrollBar:horizontal { QScrollBar:horizontal {
@ -206,6 +206,7 @@ class MainWindow(TemplateMainWindow):
The pianos use this to switch off. The pianos use this to switch off.
""" """
self.verticalPiano.pianoScene.selectedInstrumentChanged(instrumentStatus, instrumentData) self.verticalPiano.pianoScene.selectedInstrumentChanged(instrumentStatus, instrumentData)
self.horizontalPiano.pianoScene.selectedInstrumentChanged(instrumentStatus, instrumentData)
def zoom(self, scaleFactor:float): def zoom(self, scaleFactor:float):
pass pass

40
qtgui/verticalpiano.py

@ -26,44 +26,34 @@ import logging; logger = logging.getLogger(__name__); logger.info("import")
from PyQt5 import QtWidgets, QtCore, QtGui, QtOpenGL from PyQt5 import QtWidgets, QtCore, QtGui, QtOpenGL
#Template Modules #Template Modules
from template.qtgui.helper import stretchRect
from template.engine.duration import baseDurationToTraditionalNumber from template.engine.duration import baseDurationToTraditionalNumber
#User modules #User modules
import engine.api as api import engine.api as api
MAX_DURATION = 200 #to keep the code copy/paste compatible with piano grid we use the same constant but use our own value WIDTH = 200
STAFFLINEGAP = 20 #cannot be changed during runtime STAFFLINEGAP = 20 #cannot be changed during runtime
SCOREHEIGHT = STAFFLINEGAP * 128 #notes SCOREHEIGHT = STAFFLINEGAP * 128 #notes
class VerticalPiano(QtWidgets.QGraphicsView): class VerticalPiano(QtWidgets.QGraphicsView):
def __init__(self, mainWindow): def __init__(self, mainWindow):
super().__init__(mainWindow) super().__init__(mainWindow)
self.mainWindow = mainWindow self.mainWindow = mainWindow
viewport = QtWidgets.QOpenGLWidget()
viewportFormat = QtGui.QSurfaceFormat()
viewportFormat.setSwapInterval(0) #disable VSync
#viewportFormat.setSamples(2**8) #By default, the highest number of samples available is used.
viewportFormat.setDefaultFormat(viewportFormat)
viewport.setFormat(viewportFormat)
self.setViewport(viewport)
self.setAlignment(QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop) self.setAlignment(QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
self.setDragMode(QtWidgets.QGraphicsView.NoDrag) self.setDragMode(QtWidgets.QGraphicsView.NoDrag)
self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
#self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn) self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
self.pianoScene = _VerticalPianoScene(self) self.pianoScene = _VerticalPianoScene(self)
self.setScene(self.pianoScene) self.setScene(self.pianoScene)
self.setSceneRect(QtCore.QRectF(0, 0, MAX_DURATION/2, SCOREHEIGHT)) #x,y,w,h self.setSceneRect(QtCore.QRectF(0, 0, WIDTH/2, SCOREHEIGHT)) #x,y,w,h
#self.setFixedHeight(SCOREHEIGHT+3) # Don't set to scoreheight. Then we don't get a scrollbar. We need to set the sceneRect to 100%, not the view. #self.setFixedHeight(SCOREHEIGHT+3) # Don't set to scoreheight. Then we don't get a scrollbar. We need to set the sceneRect to 100%, not the view.
#self.mainWindow.ui.verticalPianoFrame.setFixedHeight(SCOREHEIGHT+3) #Don't. This makes the whole window a fixed size! #self.mainWindow.ui.verticalPianoFrame.setFixedHeight(SCOREHEIGHT+3) #Don't. This makes the whole window a fixed size!
#self.setFixedWidth(MAX_DURATION) #Also done by parent widget in mainWindow #self.setFixedWidth(WIDTH) #Also done by parent widget in mainWindow
self.setLineWidth(0) self.setLineWidth(0)
@ -100,7 +90,7 @@ class _VerticalPianoScene(QtWidgets.QGraphicsScene):
boldPen.setCosmetic(True) boldPen.setCosmetic(True)
boldPen.setWidth(1) boldPen.setWidth(1)
hlineUp = QtWidgets.QGraphicsLineItem(0, 0, MAX_DURATION*2, 0) #x1, y1, x2, y2 hlineUp = QtWidgets.QGraphicsLineItem(0, 0, WIDTH*2, 0) #x1, y1, x2, y2
hlineUp.setPen(boldPen) hlineUp.setPen(boldPen)
self.addItem(hlineUp) self.addItem(hlineUp)
hlineUp.setPos(0, 0) hlineUp.setPos(0, 0)
@ -109,7 +99,7 @@ class _VerticalPianoScene(QtWidgets.QGraphicsScene):
hlineUp.setFlag(QtWidgets.QGraphicsItem.ItemIgnoresParentOpacity, True) hlineUp.setFlag(QtWidgets.QGraphicsItem.ItemIgnoresParentOpacity, True)
self.linesHorizontal.append(hlineUp) self.linesHorizontal.append(hlineUp)
hlineDown = QtWidgets.QGraphicsLineItem(0, 0, MAX_DURATION*2, 0) #x1, y1, x2, y2 hlineDown = QtWidgets.QGraphicsLineItem(0, 0, WIDTH*2, 0) #x1, y1, x2, y2
hlineDown.setPen(boldPen) hlineDown.setPen(boldPen)
self.addItem(hlineDown) self.addItem(hlineDown)
hlineDown.setPos(0, 128 * STAFFLINEGAP) hlineDown.setPos(0, 128 * STAFFLINEGAP)
@ -119,7 +109,7 @@ class _VerticalPianoScene(QtWidgets.QGraphicsScene):
self.linesHorizontal.append(hlineDown) self.linesHorizontal.append(hlineDown)
for i in range(128): for i in range(128):
hline = QtWidgets.QGraphicsLineItem(0, 0, MAX_DURATION*2, 0) #x1, y1, x2, y2 hline = QtWidgets.QGraphicsLineItem(0, 0, WIDTH*2, 0) #x1, y1, x2, y2
hline.setPen(self.gridPen) hline.setPen(self.gridPen)
self.addItem(hline) self.addItem(hline)
hline.setPos(0, i * STAFFLINEGAP) hline.setPos(0, i * STAFFLINEGAP)
@ -156,7 +146,7 @@ class _VerticalPianoScene(QtWidgets.QGraphicsScene):
self.numberLabels.reverse() self.numberLabels.reverse()
self.fakeDeactivationOverlay = QtWidgets.QGraphicsRectItem(0,0,MAX_DURATION,SCOREHEIGHT) self.fakeDeactivationOverlay = QtWidgets.QGraphicsRectItem(0,0,WIDTH,SCOREHEIGHT)
self.fakeDeactivationOverlay.setBrush(QtGui.QColor("black")) self.fakeDeactivationOverlay.setBrush(QtGui.QColor("black"))
self.fakeDeactivationOverlay.setOpacity(0.6) self.fakeDeactivationOverlay.setOpacity(0.6)
@ -299,8 +289,8 @@ class NumberLabel(QtWidgets.QGraphicsSimpleTextItem):
self.currentLabel = "" self.currentLabel = ""
self.setText(str(number)) self.setText(str(number))
self.setFlag(QtWidgets.QGraphicsItem.ItemIgnoresParentOpacity, True) self.setFlag(QtWidgets.QGraphicsItem.ItemIgnoresParentOpacity, True)
self.setScale(1)
self.setAcceptedMouseButtons(QtCore.Qt.NoButton) self.setAcceptedMouseButtons(QtCore.Qt.NoButton)
self.setScale(1)
blackKey = number % 12 in (1, 3, 6, 8, 10) blackKey = number % 12 in (1, 3, 6, 8, 10)
if blackKey: if blackKey:
self.setBrush(QtGui.QColor("white")) self.setBrush(QtGui.QColor("white"))
@ -316,9 +306,9 @@ class NumberLabel(QtWidgets.QGraphicsSimpleTextItem):
class Highlight(QtWidgets.QGraphicsRectItem): class Highlight(QtWidgets.QGraphicsRectItem):
def __init__(self, parentGrid): def __init__(self, parentGrid):
super().__init__(0, 0, MAX_DURATION, STAFFLINEGAP) #x, y, w, h super().__init__(0, 0, WIDTH, STAFFLINEGAP) #x, y, w, h
self.setEnabled(False) #Not clickable, still visible. self.setEnabled(False) #Not clickable, still visible.
self.setAcceptedMouseButtons(QtCore.Qt.NoButton) #we still need this otherwise no rubberband. self.setAcceptedMouseButtons(QtCore.Qt.NoButton)
self.setFlag(QtWidgets.QGraphicsItem.ItemIgnoresParentOpacity, True) self.setFlag(QtWidgets.QGraphicsItem.ItemIgnoresParentOpacity, True)
self.setBrush(QtGui.QColor("cyan")) self.setBrush(QtGui.QColor("cyan"))
self.setOpacity(0.5) self.setOpacity(0.5)
@ -327,9 +317,9 @@ class Highlight(QtWidgets.QGraphicsRectItem):
class ColorKey(QtWidgets.QGraphicsRectItem): class ColorKey(QtWidgets.QGraphicsRectItem):
def __init__(self, parentGrid, color:QtGui.QColor): def __init__(self, parentGrid, color:QtGui.QColor):
super().__init__(0, 0, MAX_DURATION, STAFFLINEGAP) #x, y, w, h super().__init__(0, 0, WIDTH, STAFFLINEGAP) #x, y, w, h
self.setEnabled(False) #Not clickable, still visible. self.setEnabled(False) #Not clickable, still visible.
self.setAcceptedMouseButtons(QtCore.Qt.NoButton) #we still need this otherwise no rubberband. self.setAcceptedMouseButtons(QtCore.Qt.NoButton)
self.setFlag(QtWidgets.QGraphicsItem.ItemIgnoresParentOpacity, True) self.setFlag(QtWidgets.QGraphicsItem.ItemIgnoresParentOpacity, True)
self.setBrush(color) self.setBrush(color)
self.setOpacity(0.2) #just a tint self.setOpacity(0.2) #just a tint
@ -337,9 +327,9 @@ class ColorKey(QtWidgets.QGraphicsRectItem):
class BlackKey(QtWidgets.QGraphicsRectItem): class BlackKey(QtWidgets.QGraphicsRectItem):
def __init__(self, parentGrid): def __init__(self, parentGrid):
super().__init__(0, 0, MAX_DURATION, STAFFLINEGAP) #x, y, w, h super().__init__(0, 0, WIDTH, STAFFLINEGAP) #x, y, w, h
self.parentGrid = parentGrid self.parentGrid = parentGrid
self.setPen(QtGui.QPen(QtCore.Qt.NoPen)) self.setPen(QtGui.QPen(QtCore.Qt.NoPen))
self.setBrush(QtGui.QColor("black")) self.setBrush(QtGui.QColor("black"))
self.setEnabled(False) self.setEnabled(False)
self.setAcceptedMouseButtons(QtCore.Qt.NoButton) #we still need this otherwise no rubberband. self.setAcceptedMouseButtons(QtCore.Qt.NoButton)

Loading…
Cancel
Save