Warning, /education/minuet/src/app/qml/SheetMusicView/Note.qml is written in an unsupported language. File is not indexed.
0001 /**************************************************************************** 0002 ** 0003 ** Copyright (C) 2017 by Sandro S. Andrade <sandroandrade@kde.org> 0004 ** 0005 ** This program is free software; you can redistribute it and/or 0006 ** modify it under the terms of the GNU General Public License as 0007 ** published by the Free Software Foundation; either version 2 of 0008 ** the License or (at your option) version 3 or any later version 0009 ** accepted by the membership of KDE e.V. (or its successor approved 0010 ** by the membership of KDE e.V.), which shall act as a proxy 0011 ** defined in Section 14 of version 3 of the license. 0012 ** 0013 ** This program is distributed in the hope that it will be useful, 0014 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0016 ** GNU General Public License for more details. 0017 ** 0018 ** You should have received a copy of the GNU General Public License 0019 ** along with this program. If not, see <http://www.gnu.org/licenses/>. 0020 ** 0021 ****************************************************************************/ 0022 0023 import QtQuick 2.7 0024 0025 BravuraText { 0026 id: note 0027 0028 property int number; 0029 property int octave; 0030 property int midiKey; 0031 property int rhythm: 4; 0032 property int accident: 0 // [-2 double flat, -1 flat, 1 sharp, 2 double sharp] 0033 property bool spaced: true 0034 0035 objectName: "symbol" 0036 0037 onNumberChanged: { 0038 if (!internal.updating) { 0039 internal.updating = true; 0040 midiKey = 24 + (12*(octave-1))+number+accident; 0041 internal.updating = false 0042 } 0043 } 0044 onOctaveChanged: { 0045 if (!internal.updating) { 0046 internal.updating = true; 0047 midiKey = 24 + (12*(octave-1))+number+accident; 0048 internal.updating = false 0049 } 0050 } 0051 onAccidentChanged: { 0052 if (!internal.updating) { 0053 internal.updating = true; 0054 midiKey = 24 + (12*(octave-1))+number+accident; 0055 internal.updating = false 0056 } 0057 } 0058 onMidiKeyChanged: { 0059 if (!internal.updating) { 0060 internal.updating = true; 0061 number = (midiKey % 12); 0062 octave = (((midiKey-24) - number) / 12) + 1; 0063 accident = internal.accidentMap[number][1]; 0064 internal.updating = false 0065 } 0066 } 0067 0068 QtObject { 0069 id: internal 0070 0071 property bool updating: false; 0072 property var accidentMap: [ 0073 // [vertical offset, accident] 0074 [0, 0], 0075 [0, 1], 0076 [1, 0], 0077 [1, 1], 0078 [2, 0], 0079 [3, 0], 0080 [3, 1], 0081 [4, 0], 0082 [4, 1], 0083 [5, 0], 0084 [5, 1], 0085 [6, 0], 0086 ] 0087 0088 function itemIndex(item) { 0089 if (item.parent == null) 0090 return -1 0091 var siblings = item.parent.children 0092 for (var i = siblings.length - 1; i >=0 ; i--) 0093 if (siblings[i] == item) 0094 return i 0095 return -1 // will never happen 0096 } 0097 function previousItem(item) { 0098 if (item.parent == null) 0099 return null 0100 var siblings = item.parent.children 0101 for (var i = itemIndex(item) - 1; i >=0 ; i--) 0102 if (siblings[i].objectName == "symbol") 0103 return item.parent.children[i] 0104 return null 0105 } 0106 0107 property var rhythmTable: { "1": "\ue1d2", "2": "\ue1d3", "4": "\ue1d5", "8": "\ue1d7", "16": "\ue1d9", "32": "\ue1db", "64": "\ue1dd" } 0108 } 0109 0110 anchors { 0111 bottom: parent.children[0].bottom; 0112 bottomMargin: { 0113 (parent.clef.type == 0) ? 0114 ((internal.accidentMap[number][0])*5)+(octave-4)*35 0115 : 0116 -10+((internal.accidentMap[number][0])*5)+(octave-2)*35; 0117 } 0118 left: spaced ? internal.previousItem(note).right:internal.previousItem(note).left; 0119 leftMargin: spaced ? parent.spacing:0 0120 } 0121 text: ((accident == -1) ? "\ue260":(accident == 1) ? "\ue262":(accident == -2) ? "\ue264":(accident == 2) ? "\ue263":" ") + internal.rhythmTable[rhythm] 0122 font.pixelSize: 35 0123 }