forked from KDE/rattlesnake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MetronomePage.qml
196 lines (180 loc) · 5.87 KB
/
MetronomePage.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.12
import org.kde.kirigami 2.10 as Kirigami
import org.kde.rattlesnake 1.0
Kirigami.Page {
title: qsTr("Metronome")
id: page
footer: ProgressBar {
height: TapIn.tapCounter === 0 ? 0 : 15
Behavior on height {
NumberAnimation {}
}
from: 0
to: 4
value: TapIn.tapCounter
Behavior on value {
NumberAnimation {}
}
}
Connections {
target: TapIn
function onTapStopped() {
Metronome.bpm = TapIn.bpm
container.state = "resized"
Metronome.start()
}
}
mainAction: Kirigami.Action {
icon.name: "zoom-original"
text: qsTr("Tap")
onTriggered: {
Metronome.stop()
TapIn.tap()
}
}
leftAction: Kirigami.Action {
icon.name: "document-edit"
text: "Edit Beat"
onTriggered: pageStack.push("qrc:/EditPage.qml")
}
ColumnLayout {
anchors.fill: parent
RowLayout {
Layout.fillWidth: true
Button {
icon.name: "list-remove"
onClicked: Metronome.removeNote(repeater.count - 1)
enabled: Metronome.notes.length > 1
}
Kirigami.Card {
id: editor
Layout.fillWidth: true
implicitHeight: 50
ScrollView {
anchors.fill: parent
ScrollBar.vertical.policy: ScrollBar.AlwaysOff
RowLayout {
height: editor.height
Item {
implicitWidth: 4
//spacer
}
Repeater {
id: repeater
Layout.alignment: Qt.AlignHCenter
Layout.fillWidth: true
Layout.fillHeight: true
model: Metronome.notes
delegate: Button {
implicitWidth: height
flat: index !== Metronome.currentIndex
Layout.alignment: Qt.AlignVCenter
text: modelData.sound + 1
onClicked: {
let instrumentIndex = Metronome.notes[model.index].sound
let newIndex = ((instrumentIndex + 1) % 3)
console.log(newIndex)
Metronome.notes[model.index].sound = newIndex
}
}
}
Item {
Layout.fillWidth: true
// spacer
}
}
}
}
Button {
icon.name: "list-add"
onClicked: Metronome.addNote(0)
}
}
Item {
Layout.fillHeight: true
}
Label {
Layout.alignment: Qt.AlignHCenter
text: "BPM:"
}
SpinBox {
Layout.alignment: Qt.AlignHCenter
from: dial.from
to: dial.to
editable: true
value: Metronome.bpm
onValueModified: Metronome.bpm = value
}
Dial {
id: dial
Layout.alignment: Qt.AlignHCenter
value: Metronome.bpm
from: 20
to: 400
Behavior on value {
NumberAnimation {}
}
onMoved: {
Metronome.bpm = value
}
contentItem: Item {
id: container
anchors.fill: dial
Rectangle {
id: animation
anchors.centerIn: parent
width: height
height: playPauseButton.height * 0.75
radius: height * 0.5
color: "white"
}
states: [
State {
name: "resized"
PropertyChanges {
target: animation
height: 600
opacity: 0
}
},
State {
name: "normal"
PropertyChanges {
target: animation
height: playPauseButton.height * 0.75
opacity: 100
}
}
]
state: "normal"
transitions: Transition {
enabled: container.state == "normal"
onRunningChanged: if (!running) {
container.state = "normal"
}
PropertyAnimation {
properties: "height, opacity"
easing.type: Easing.InOutQuad
}
}
RoundButton {
z: 1000
height: width
width: 50
id: playPauseButton
anchors.centerIn: parent
checkable: true
checked: Metronome.running
icon.name: checked ? "media-playback-pause" : "media-playback-start"
onClicked: checked ? Metronome.start() : Metronome.stop()
}
}
}
Item {
Layout.fillHeight: true
}
}
}