ToiseFlikcable fully working with notes and octaves.

The binding beetween two toises has to be thinked.
This commit is contained in:
Louis-Joseph Fournier 2016-01-12 23:09:13 +01:00
parent df3a875a75
commit 73c80eb307
7 changed files with 47 additions and 17 deletions

View file

@ -113,6 +113,8 @@ Item {
note: tuner.note note: tuner.note
octave: tuner.octave octave: tuner.octave
onMultipleChanged: tuner.octave = index / 12
} }
Text { Text {
@ -139,12 +141,18 @@ Item {
theme: main.theme theme: main.theme
marks: [1, 2, 3, 4, 5, 6, 7, 8] marks: [1, 2, 3, 4, 5, 6, 7, 8]
min: 0
max: marks.length - 1
//nb_marks_displayed: is_portrait ? 4 : 3 //nb_marks_displayed: is_portrait ? 4 : 3
width: parent.width * 0.6 width: parent.width * 0.6
height: parent.toise_h height: parent.toise_h
index: tuner.octave index: tuner.octave - 1
onIndexChanged: {
// tuner.note = (tuner.note % 12) * (index + 1)
// tuner.octave = index + 1
}
} }
} }
} }

View file

@ -24,7 +24,7 @@ import "."
* Display notes from scale, with current note centered. * Display notes from scale, with current note centered.
*/ */
Toise { ToiseFlickable {
id: scale id: scale
// note // note
@ -57,4 +57,8 @@ Toise {
function isAltered(i) { function isAltered(i) {
return (i < 4 && (i & 1)) || (i > 5 && !(i & 1)) return (i < 4 && (i & 1)) || (i > 5 && !(i & 1))
} }
// ToiseFlikcable parameters
min: notes_en.length * 1 // ut 1
max: notes_en.length * 9 - 1 // si 8
} }

View file

@ -35,6 +35,10 @@ Item {
// function to get mark color // function to get mark color
property var mark_color: function (id) { return "transparent" } property var mark_color: function (id) { return "transparent" }
// min and max values
property double min: 0
property double max: 100
property int h_margin: Math.max(height / 8, main_mark.border_d) property int h_margin: Math.max(height / 8, main_mark.border_d)
property int nb_marks: marks.length property int nb_marks: marks.length
@ -42,16 +46,20 @@ Item {
property int nb_marks_displayed: nb_marks property int nb_marks_displayed: nb_marks
property bool is_pair: nb_marks_displayed % 2 == 0 property bool is_pair: nb_marks_displayed % 2 == 0
function index2pos(i) { return i - (nb_marks_displayed - 1) / 2 }
/// current mark is on the middle /// current mark is on the middle
property double position: index - (nb_marks_displayed - 1) / 2 property double position: index2pos(index)
property int first_mark: Math.floor(position) % nb_marks property int first_mark: Math.floor(position) % nb_marks
property double delta: position - Math.floor(position) property double delta: position - Math.floor(position)
property int idx_modulo: index % nb_marks property int idx_modulo: index % nb_marks
property alias cellWidth: toise.cellWidth property alias cellWidth: toise.cellWidth
property bool animation_enabled: true
Behavior on position { Behavior on position {
enabled: animation_enabled
NumberAnimation { NumberAnimation {
duration: 200 duration: 200
easing.amplitude: nb_marks easing.amplitude: nb_marks
@ -76,7 +84,8 @@ Item {
width: toise.cellWidth width: toise.cellWidth
height: toise.height height: toise.height
border.width: 1 border.width: 1
property int idx: (index + nb_marks + first_mark) % nb_marks property int idx_ref: Math.floor(position) + index
property int idx: (index + first_mark + nb_marks) % nb_marks
color: mark_color(idx) color: mark_color(idx)
Text { Text {
@ -85,6 +94,7 @@ Item {
text: marks[idx] text: marks[idx]
color: idx == idx_modulo ? theme.primaryColor : theme.secondaryColor color: idx == idx_modulo ? theme.primaryColor : theme.secondaryColor
font.pixelSize: parent.height / 2 font.pixelSize: parent.height / 2
opacity: idx_ref >= min && idx_ref <= max ? 1 : 0.2
} }
} }
} }

View file

@ -24,10 +24,22 @@ import QtQuick 2.0
*/ */
Toise { Toise {
property bool flik_enable: true
property int multiple: index % nb_marks
property double p_min: index2pos(min)
property double p_max: index2pos(max)
animation_enabled: false
MouseArea { MouseArea {
property int refX: 0 property int refX: 0
property double refPos: parent.position property double refPos: parent.position
enabled: flik_enable
anchors.fill: parent anchors.fill: parent
onPressed: { onPressed: {
@ -38,26 +50,18 @@ Toise {
if (!pressed) return if (!pressed) return
var d = (refX - mouseX) / parent.cellWidth var d = (refX - mouseX) / parent.cellWidth
var p = refPos + d var p = refPos + d
p = Math.max(Math.min(p, p_max), p_min)
var i = Math.round(p + (nb_marks_displayed - 1) / 2) var i = Math.round(p + (nb_marks_displayed - 1) / 2)
index = i % nb_marks index = i
position = p position = p
delta = position - Math.floor(position) delta = position - Math.floor(position)
first_mark = Math.floor(position) % nb_marks first_mark = Math.floor(position) % nb_marks
} }
onReleased: { onReleased: {
var p = 0 var p = index2pos(index)
var d = position - Math.floor(position)
if (d < 0.5) {
p = Math.floor(position)
}
else {
p = Math.ceil(position)
}
var i = Math.floor(p + (nb_marks_displayed - 1) / 2)
index = i % nb_marks
first_mark = p % nb_marks
position = p position = p
delta = 0 delta = position - Math.floor(position)
//console.log("index:" + index)
} }
} }
} }

View file

@ -106,6 +106,8 @@ Item {
id: toise id: toise
theme: main.theme theme: main.theme
flik_enable: false
anchors.top: main.is_portrait ? title_note.bottom : parent.top anchors.top: main.is_portrait ? title_note.bottom : parent.top
anchors.topMargin: parent.margin_h anchors.topMargin: parent.margin_h

View file

@ -7,6 +7,7 @@
<file>CircleMeter.qml</file> <file>CircleMeter.qml</file>
<file>ScaleToise.qml</file> <file>ScaleToise.qml</file>
<file>Toise.qml</file> <file>Toise.qml</file>
<file>ToiseFlickable.qml</file>
<file>Led.qml</file> <file>Led.qml</file>
<file>Config.qml</file> <file>Config.qml</file>
<file>qmldir</file> <file>qmldir</file>

View file

@ -6,6 +6,7 @@
<file>CircleMeter.qml</file> <file>CircleMeter.qml</file>
<file>ScaleToise.qml</file> <file>ScaleToise.qml</file>
<file>Toise.qml</file> <file>Toise.qml</file>
<file>ToiseFlickable.qml</file>
<file>Led.qml</file> <file>Led.qml</file>
<file>ConfigurePageSailfish.qml</file> <file>ConfigurePageSailfish.qml</file>
<file>Config.qml</file> <file>Config.qml</file>