Commit ff577668 authored by Sandro Andrade's avatar Sandro Andrade
Browse files

Add highlight of noteOn events in virtual keyboard module

parent 7e877043
......@@ -45,12 +45,10 @@ void MidiSequencerOutputThread::setSong(Song *song)
bool MidiSequencerOutputThread::hasNext()
{
qDebug() << "hasNext() returns " << m_songIterator->hasNext();
return m_songIterator->hasNext();
}
drumstick::SequencerEvent *MidiSequencerOutputThread::nextEvent()
{
qDebug() << "nextEvent()";
return m_songIterator->next()->clone();
}
<RCC>
<qresource prefix="/">
<file alias="main.qml">qml/main.qml</file>
<file alias="WhiteKey.qml">qml/WhiteKey.qml</file>
<file alias="BlackKey.qml">qml/BlackKey.qml</file>
<file alias="Octave.qml">qml/Octave.qml</file>
<file alias="PianoView.qml">qml/PianoView.qml</file>
<file alias="MidiPlayer.qml">qml/MidiPlayer.qml</file>
<file alias="images/minuet-background.png">qml/images/minuet-background.png</file>
<file alias="images/navigate-next.png">qml/images/navigate-next.png</file>
</qresource>
......
import QtQuick 2.5
Rectangle {
property Item anchor;
width: 0.6*keyWidth; height: 0.6*keyHeight
border { width: 1; color: "black" }
color: mouseArea.pressed ? "#475057" : "black"
MouseArea { id: mouseArea; anchors.fill: parent }
anchors { left: anchor.right; leftMargin: -(0.6*keyWidth)/2; top: anchor.top }
z: 1
}
\ No newline at end of file
import QtQuick 2.5
Item {
width: 250; height: 100
Rectangle {
color: "black"
anchors.fill: parent
}
}
import QtQuick 2.5
Item {
property int keyWidth: 20
property int keyHeight: 68
property Item initialAnchor;
width: whiteKeys.width; height: keyHeight
Row {
id: whiteKeys
Repeater {
model: 7
Rectangle {
width: keyWidth; height: keyHeight
border { width: 1; color: "black" }
color: whitemouse.pressed ? "#475057" : "white"
MouseArea { id: whitemouse; anchors.fill: parent }
}
}
}
Row {
id: blackKeys1
anchors { left: whiteKeys.left; leftMargin: 14 }
spacing: 8
Repeater {
model: 2
Rectangle {
width: 12; height: 42
border { width: 1; color: "black" }
color: blackmouse.pressed ? "#475057" : "black"
MouseArea { id: blackmouse; anchors.fill: parent }
}
}
}
Row {
id: blackKeys2
anchors { left: blackKeys1.left; leftMargin: 60 }
spacing: 8
Repeater {
model: 3
Rectangle {
width: 12; height: 42
border { width: 1; color: "black" }
color: blackmouse.pressed ? "#475057" : "black"
MouseArea { id: blackmouse; anchors.fill: parent }
}
}
}
width: 7*keyWidth; height: keyHeight
anchors { left: initialAnchor.right }
WhiteKey { id: whiteKey1 }
BlackKey { anchor: whiteKey1 }
WhiteKey { id: whiteKey2; anchor: whiteKey1 }
BlackKey { anchor: whiteKey2 }
WhiteKey { id: whiteKey3; anchor: whiteKey2 }
WhiteKey { id: whiteKey4; anchor: whiteKey3 }
BlackKey { anchor: whiteKey4 }
WhiteKey { id: whiteKey5; anchor: whiteKey4 }
BlackKey { anchor: whiteKey5 }
WhiteKey { id: whiteKey6; anchor: whiteKey5 }
BlackKey { anchor: whiteKey6 }
WhiteKey { anchor: whiteKey6 }
}
\ No newline at end of file
import QtQuick 2.5
Item {
width: 1020; height: 68
Row {
id: whiteKeys0
Repeater {
model: 2
Rectangle {
width: 20; height: 68
border { width: 1; color: "black" }
color: whitemouse.pressed ? "#475057" : "white"
MouseArea { id: whitemouse; anchors.fill: parent }
id: keyboard
property int keyWidth: 20
property int keyHeight: 3.4*keyWidth
width: 2*keyWidth+7*(7*keyWidth); height: keyHeight
WhiteKey { id: whiteKeyA }
BlackKey { anchor: whiteKeyA }
WhiteKey { id: whiteKeyB; anchor: whiteKeyA }
Octave { id: octave1; initialAnchor: whiteKeyB }
Octave { id: octave2; initialAnchor: octave1 }
Octave { id: octave3; initialAnchor: octave2 }
Octave { id: octave4; initialAnchor: octave3 }
Octave { id: octave5; initialAnchor: octave4 }
Octave { id: octave6; initialAnchor: octave5 }
Octave { id: octave7; initialAnchor: octave6 }
}
}
}
Row {
id: blackKeys0
anchors { left: whiteKeys0.left; leftMargin: 14 }
Repeater {
model: 1
Rectangle {
width: 12; height: 42
border { width: 1; color: "black" }
color: blackmouse.pressed ? "#475057" : "black"
MouseArea { id: blackmouse; anchors.fill: parent }
}
}
}
Row {
anchors.left: whiteKeys0.right
Repeater {
model: 7
Octave { }
}
}
Component.onCompleted: {
sequencer.noteOn.connect(noteOn)
sequencer.noteOff.connect(noteOff)
}
function noteOn(chan, pitch, vol) {
whiteKeys0.children[1].color = "#475057"
highlightKey(pitch, "#778692")
}
function noteOff(chan, pitch, vol) {
highlightKey(pitch, ([1,3,6,8,10].indexOf(pitch % 12) > -1) ? "black":"white")
}
function highlightKey(pitch, color) {
if (pitch < 24) {
keyboard.children[pitch-21].color = color
return
}
var note = (pitch - 24) % 12
var octave = (pitch - 24 - note) / 12
keyboard.children[3+octave].children[note].color = color
}
}
import QtQuick 2.5
Rectangle {
property Item anchor;
width: keyWidth; height: keyHeight
border { width: 1; color: "black" }
color: mouseArea.pressed ? "#475057" : "white"
MouseArea { id: mouseArea; anchors.fill: parent }
Component.onCompleted: if (anchor != null) anchors.left = anchor.right;
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment