From 0dec54f2d01804755507e118567c6a7a4583cb8b Mon Sep 17 00:00:00 2001 From: Louis-Joseph Fournier Date: Fri, 1 Jan 2016 16:39:43 +0100 Subject: [PATCH] ScaleToise: animated smoothed toise for note display --- qml/ScaleToise.qml | 73 +++++++++++++++++++++++++++++++++++++++++++++ qml/Scene.qml | 2 +- qml/TunerScreen.qml | 16 ++++++++-- 3 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 qml/ScaleToise.qml diff --git a/qml/ScaleToise.qml b/qml/ScaleToise.qml new file mode 100644 index 0000000..e5e40bc --- /dev/null +++ b/qml/ScaleToise.qml @@ -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) + }*/ +} diff --git a/qml/Scene.qml b/qml/Scene.qml index 6cc7e62..45bc965 100644 --- a/qml/Scene.qml +++ b/qml/Scene.qml @@ -7,7 +7,7 @@ import QtQuick 2.0 Item { width: 600 - height: 350 + height: 450 DesktopTheme { id: theme diff --git a/qml/TunerScreen.qml b/qml/TunerScreen.qml index d8258e5..035a950 100644 --- a/qml/TunerScreen.qml +++ b/qml/TunerScreen.qml @@ -12,12 +12,22 @@ Item { property QtObject theme anchors.fill: parent + property int h_free: parent.height - parent.width / 2 CircleMeter { + id: meter theme: parent.theme - anchors.fill: parent - /* + y: (h_free - toise.height) / 3 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 } }