Qml: note names in a separate module

This commit is contained in:
Louis-Joseph Fournier 2016-01-15 17:32:19 +01:00
parent f75a6d906f
commit 1f397fa47f
7 changed files with 58 additions and 18 deletions

43
qml/NoteNames.qml Normal file
View file

@ -0,0 +1,43 @@
/* Copyright 2016 (C) Louis-Joseph Fournier
* louisjoseph.fournier@gmail.com
*
* This file is part of SailTuner.
*
* SailTuner is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SailTuner is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
import QtQuick 2.0
import "."
pragma Singleton
/**
* NoteNames
*
* Singleton to provide facilities to note names
*/
QtObject {
property int notes_style: Config.notes_style
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 notesTab: [notes_en, notes_fr]
property int nb: notes_fr.length
property variant notes: notesTab[notes_style]
function noteName(note) { return notes[note]; }
}

View file

@ -16,6 +16,7 @@
*/
import QtQuick 2.0
import "."
/**
* Main tuner screen
@ -113,8 +114,8 @@ Item {
//octave: tuner.octave
onReleased: {
note = index % 12
octave = index / 12
note = index % NoteNames.nb
octave = index / NoteNames.nb
toise_octave.index = octave
// set octave and note atomically
tuner.setNoteOctave(note, octave)
@ -178,7 +179,7 @@ Item {
toise.note = tuner.note
toise.octave = tuner.octave
toise_octave.index = tuner.octave
toise.index = tuner.note + 12 * tuner.octave
toise.index = tuner.note + NoteNames.nb * tuner.octave
toise.updateFlickable()
toise_octave.updateFlickable()
toise.flik_enable = true

View file

@ -31,22 +31,14 @@ ToiseFlickable {
property int note: 1
// octave
property int octave: 4
// en or fr
property int notes_style: Config.notes_style
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]
// case colors
property color colorAltered: "#40888888"
property color colorNatural: "transparent"
// Toise parameters
index: note + notes_en.length * octave
marks: notes[notes_style]
index: note + NoteNames.nb * octave
marks: NoteNames.notes
nb_marks_displayed: width > 100 ? Math.min(nb_marks, width / theme.fontSizeLarge * 0.8) : 1
mark_color: function(note) {
@ -59,12 +51,12 @@ ToiseFlickable {
}
// ToiseFlikcable parameters
min: notes_en.length * 0 // ut 0
max: notes_en.length * 9 - 1 // si 8
min: NoteNames.nb * 0 // ut 0
max: NoteNames.nb * 9 - 1 // si 8
onOctaveChanged: {
if (!flik_enable) return
index = note + notes_en.length * octave
index = note + NoteNames.nb * octave
updateFlickable()
}
}

View file

@ -16,6 +16,7 @@
*/
import QtQuick 2.0
import "."
/**
* Main tuner screen
@ -49,7 +50,7 @@ Item {
anchors.left: meter.left
anchors.topMargin: meter.width / 24
anchors.leftMargin: anchors.topMargin
width: meter.width / 12
width: meter.width / NoteNames.nb
height: width
led_color: dev_is_ok ? led_green : led_red
on: tuner.found && (dev_is_ok || tuner.deviation < 0)
@ -60,7 +61,7 @@ Item {
anchors.right: meter.right
anchors.topMargin: meter.width / 24
anchors.rightMargin: anchors.topMargin
width: meter.width / 12
width: meter.width / NoteNames.nb
height: width
led_color: dev_is_ok ? led_green : led_red
on: tuner.found && (dev_is_ok || tuner.deviation > 0)

View file

@ -11,6 +11,7 @@
<file>ToiseFlickable.qml</file>
<file>Led.qml</file>
<file>Config.qml</file>
<file>NoteNames.qml</file>
<file>qmldir</file>
</qresource>
</RCC>

View file

@ -1 +1,2 @@
singleton Config Config.qml
singleton NoteNames NoteNames.qml

View file

@ -11,6 +11,7 @@
<file>Led.qml</file>
<file>ConfigurePageSailfish.qml</file>
<file>Config.qml</file>
<file>NoteNames.qml</file>
<file>qmldir</file>
</qresource>
</RCC>