2016-01-01 18:39:43 +03:00
|
|
|
import QtQuick 2.0
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ScaleToise
|
|
|
|
*
|
|
|
|
* Display notes from scale, with current note centered.
|
|
|
|
*/
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: scale
|
2016-01-01 21:20:29 +03:00
|
|
|
|
|
|
|
property QtObject theme
|
2016-01-01 18:39:43 +03:00
|
|
|
|
|
|
|
// note or note + 12 * octave
|
|
|
|
property int note: 1
|
|
|
|
|
2016-01-01 20:43:42 +03:00
|
|
|
property variant notes_fr: [
|
|
|
|
"do", "do#", "ré", "mib", "mi", "fa", "fa#", "sol", "sol#", "la", "sib", "si"]
|
2016-01-01 18:39:43 +03:00
|
|
|
property variant notes_en: [
|
2016-01-01 20:43:42 +03:00
|
|
|
"C", "C#", "D", "Eb", "E", "F", "F#", "G", "G#", "A", "Bb", "B"]
|
2016-01-01 18:39:43 +03:00
|
|
|
property variant notes: [notes_en, notes_fr]
|
|
|
|
property int notes_style: 0
|
|
|
|
|
2016-01-01 20:43:42 +03:00
|
|
|
property color colorAltered: "#40888888"
|
2016-01-01 21:20:29 +03:00
|
|
|
property color colorNatural: "transparent"
|
2016-01-01 20:43:42 +03:00
|
|
|
|
|
|
|
property int h_margin: Math.max(height / 8, main_note.border_d)
|
|
|
|
|
2016-01-01 18:39:43 +03:00
|
|
|
property int nb_notes: 12
|
2016-01-02 13:22:25 +03:00
|
|
|
property int nb_notes_displayed: Math.min(nb_notes, width / theme.fontSizeLarge * 0.8)
|
|
|
|
|
2016-01-01 18:39:43 +03:00
|
|
|
/// current note is on the middle
|
2016-01-02 13:22:25 +03:00
|
|
|
property double position: note - (nb_notes_displayed - 1) / 2
|
2016-01-01 18:39:43 +03:00
|
|
|
|
|
|
|
property int first_note: Math.floor(position) % nb_notes
|
|
|
|
property double delta: position - Math.floor(position)
|
|
|
|
|
2016-01-02 13:22:25 +03:00
|
|
|
onFirst_noteChanged: console.log(first_note + " " + note + " " + nb_notes_displayed + " " + position)
|
|
|
|
|
2016-01-01 18:39:43 +03:00
|
|
|
function note_name(i) {
|
|
|
|
return notes[notes_style][i];
|
|
|
|
}
|
|
|
|
|
2016-01-01 20:43:42 +03:00
|
|
|
function isAltered(i) {
|
|
|
|
return (i < 4 && (i & 1)) || (i > 5 && !(i & 1))
|
|
|
|
}
|
|
|
|
|
2016-01-01 18:39:43 +03:00
|
|
|
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
|
2016-01-01 20:43:42 +03:00
|
|
|
anchors.topMargin: h_margin
|
|
|
|
anchors.bottomMargin: h_margin
|
2016-01-02 13:22:25 +03:00
|
|
|
property double cellWidth: parent.width / nb_notes_displayed
|
2016-01-01 18:39:43 +03:00
|
|
|
|
|
|
|
Repeater {
|
2016-01-02 13:22:25 +03:00
|
|
|
model: nb_notes_displayed + 1
|
2016-01-01 18:39:43 +03:00
|
|
|
Rectangle {
|
|
|
|
width: toise.cellWidth
|
2016-01-02 13:22:25 +03:00
|
|
|
height: toise.height
|
2016-01-01 18:39:43 +03:00
|
|
|
border.width: 1
|
2016-01-01 20:43:42 +03:00
|
|
|
property int note: (index + nb_notes + first_note) % nb_notes
|
2016-01-01 21:20:29 +03:00
|
|
|
color: isAltered(note) ? colorAltered : colorNatural
|
2016-01-01 18:39:43 +03:00
|
|
|
|
|
|
|
Text {
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
2016-01-01 20:43:42 +03:00
|
|
|
text: note_name(note)
|
2016-01-01 21:20:29 +03:00
|
|
|
color: theme.primaryColor
|
|
|
|
font.pixelSize: parent.height / 2
|
2016-01-01 18:39:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-01 20:43:42 +03:00
|
|
|
// Screen for actual note
|
|
|
|
Rectangle {
|
|
|
|
id: main_note
|
|
|
|
y: 0
|
2016-01-02 13:22:25 +03:00
|
|
|
x: toise.cellWidth * (parent.nb_notes_displayed - 1) / 2 - border_d
|
2016-01-01 20:43:42 +03:00
|
|
|
width: toise.cellWidth + border_d * 2
|
|
|
|
height: parent.height
|
|
|
|
|
|
|
|
property int border_d: 10
|
|
|
|
|
|
|
|
color: "transparent"
|
|
|
|
border.width: border_d
|
|
|
|
border.color: "#a0777777"
|
|
|
|
}
|
|
|
|
|
2016-01-01 18:39:43 +03:00
|
|
|
/*
|
|
|
|
onPositionChanged: {
|
|
|
|
console.log("note " + note_name(note % nb_notes) + " pos " + position + " first note " + first_note + " delta " + delta)
|
|
|
|
}*/
|
|
|
|
}
|