ScaleToise: animated smoothed toise for note display

This commit is contained in:
Louis-Joseph Fournier 2016-01-01 16:39:43 +01:00
parent e1175e85d0
commit 0dec54f2d0
3 changed files with 87 additions and 4 deletions

73
qml/ScaleToise.qml Normal file
View file

@ -0,0 +1,73 @@
import QtQuick 2.0
/**
* ScaleToise
*
* Display notes from scale, with current note centered.
*/
Item {
id: scale
// note or note + 12 * octave
property int note: 1
property variant notes_fr: ["do", "do#", "ré", "mib", "mi", "fa", "fa#", "sol", "sol#", "la", "sib", "si"]
property variant notes_en: [
"C", "C#", "D", "Eb", "E", "F", "F#", "G", "G#", "A", "Bb", "B"
]
property variant notes: [notes_en, notes_fr]
property int notes_style: 0
property int nb_notes: 12
/// current note is on the middle
property double position: note + (nb_notes + 1) / 2
property int first_note: Math.floor(position) % nb_notes
property double delta: position - Math.floor(position)
function note_name(i) {
return notes[notes_style][i];
}
Behavior on position {
NumberAnimation {
duration: 200
easing.amplitude: nb_notes
}
}
Row {
id: toise
anchors.top: parent.top
anchors.left: parent.left
anchors.leftMargin: - cellWidth * delta
anchors.bottom: parent.bottom
anchors.right: parent.right
property double cellWidth: parent.width / nb_notes
Repeater {
model: nb_notes + 1
Rectangle {
width: toise.cellWidth
height: parent.height
border.width: 1
Text {
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
text: note_name((index + nb_notes + first_note) % nb_notes)
}
}
}
}
MouseArea {
anchors.fill: parent
onClicked: note = Math.random() * 100
}
/*
onPositionChanged: {
console.log("note " + note_name(note % nb_notes) + " pos " + position + " first note " + first_note + " delta " + delta)
}*/
}

View file

@ -7,7 +7,7 @@ import QtQuick 2.0
Item { Item {
width: 600 width: 600
height: 350 height: 450
DesktopTheme { DesktopTheme {
id: theme id: theme

View file

@ -12,12 +12,22 @@ Item {
property QtObject theme property QtObject theme
anchors.fill: parent anchors.fill: parent
property int h_free: parent.height - parent.width / 2
CircleMeter { CircleMeter {
id: meter
theme: parent.theme theme: parent.theme
anchors.fill: parent y: (h_free - toise.height) / 3
/*
width: Math.min(parent.width, parent.height * 2) width: Math.min(parent.width, parent.height * 2)
height: width / 2*/ height: width / 2
}
ScaleToise {
id: toise
anchors.bottom: parent.bottom
anchors.left: parent.left
width: parent.width
height: Math.min(h_free, width / 12)
anchors.bottomMargin: (h_free - height) / 3
} }
} }