Warning, /multimedia/rattlesnake/MetronomePage.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2023 Mathis BrĂ¼chert <mbb@kaidan.im>
0002 //
0003 // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 
0005 import QtQuick 2.12
0006 import QtQuick.Window 2.12
0007 import QtQuick.Controls 2.14
0008 import QtQuick.Layouts 1.12
0009 import org.kde.kirigami 2.20 as Kirigami
0010 import org.kde.kirigamiaddons.labs.mobileform 0.1 as MobileForm
0011 
0012 import org.kde.rattlesnake 1.0
0013 
0014 import "components"
0015 
0016 Kirigami.Page {
0017     leftPadding: 0
0018     rightPadding: 0
0019     Component.onCompleted: {
0020         Metronome.addNote(0)
0021         Metronome.addNote(0)
0022         Metronome.addNote(0)
0023     }
0024 
0025 
0026     title: qsTr("Metronome")
0027     id: page
0028     footer: ProgressBar {
0029         height: TapIn.tapCounter === 0 ? 0 : 15
0030         Behavior on height {
0031             NumberAnimation {}
0032         }
0033 
0034         from: 0
0035         to: 4
0036         value: TapIn.tapCounter
0037 
0038         Behavior on value {
0039             NumberAnimation {}
0040         }
0041     }
0042 
0043 
0044     Connections {
0045         target: TapIn
0046         function onTapStopped() {
0047             Metronome.bpm = TapIn.bpm
0048             container.state = "resized"
0049             Metronome.start()
0050         }
0051     }
0052     DoubleActionButton {
0053         parent: overlay
0054         x: root.width - width - margin
0055         y: root.height - height - pageStack.globalToolBar.preferredHeight - margin
0056         rightAction: Kirigami.Action {
0057             icon.name: "qrc:/media/icons/tap-in.svg"
0058             text: qsTr("Tap-In")
0059             onTriggered: {
0060                 Metronome.stop()
0061                 TapIn.tap()
0062             }
0063         }
0064         leftAction: Kirigami.Action {
0065             icon.name: "document-edit"
0066             text: qsTr("Edit Beat")
0067             onTriggered: pageStack.push("qrc:/EditPage.qml")
0068         }
0069     }
0070 
0071     ColumnLayout {
0072         anchors.fill: parent
0073 
0074         RowLayout {
0075             Layout.alignment: Qt.AlignCenter
0076             Layout.preferredWidth: 10
0077             Item { Layout.fillWidth: true }
0078             Button {
0079                 icon.name: "list-remove"
0080                 onClicked: Metronome.removeNote(repeater.count - 1)
0081                 enabled: Metronome.notes.length > 1
0082             }
0083             ScrollView {
0084                 Layout.maximumWidth: 300
0085                 ScrollBar.vertical.policy: ScrollBar.AlwaysOff
0086                 ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
0087 
0088                 RowLayout {
0089                     height: editor.height
0090                     Item {
0091                         implicitHeight: 4
0092                         //spacer
0093                     }
0094                     Repeater {
0095                         id: repeater
0096                         Layout.alignment: Qt.AlignHCenter
0097                         Layout.fillWidth: true
0098                         Layout.fillHeight: true
0099                         model: Metronome.notes
0100                         delegate: Button {
0101                             implicitWidth: height
0102                             flat:true
0103                             implicitHeight: Kirigami.Units.gridUnit*3
0104 
0105                             Layout.alignment: Qt.AlignVCenter
0106                             contentItem: Item{
0107                                 Kirigami.Icon{
0108                                     id: buttonIcon
0109                                     isMask:true
0110                                     opacity: 0.6
0111                                     color: index !== Metronome.currentIndex ? Kirigami.Theme.textColor:Kirigami.Theme.hoverColor
0112                                     source: if (modelData.sound === 0) {
0113                                             "qrc:/media/icons/sound1.svg"
0114                                         } else if (modelData.sound === 1) {
0115                                             "qrc:/media/icons/sound2.svg"
0116                                         } else if (modelData.sound === 2) {
0117                                             "qrc:/media/icons/sound3.svg"
0118                                         }
0119                                     anchors.centerIn: parent
0120                                     height: Kirigami.Units.gridUnit*3
0121                                     width:height
0122                                 }
0123                             }
0124 
0125 
0126                             onClicked: {
0127                                 let instrumentIndex = Metronome.notes[model.index].sound
0128                                 let newIndex = ((instrumentIndex + 1) % 3)
0129                                 console.log(newIndex)
0130                                 Metronome.notes[model.index].sound = newIndex
0131                             }
0132                         }
0133                     }
0134                     Item {
0135                         Layout.fillWidth: true
0136                         // spacer
0137                     }
0138                 }
0139             }
0140 
0141             Button {
0142                 icon.name: "list-add"
0143                 onClicked: Metronome.addNote(0)
0144             }
0145             Item { Layout.fillWidth: true }
0146 
0147         }
0148         Item { Layout.fillHeight: true }
0149 
0150         MobileForm.FormCard {
0151             Layout.topMargin: Kirigami.Units.largeSpacing
0152             Layout.fillWidth: true
0153             contentItem: ColumnLayout {
0154                 spacing:0
0155                 MobileForm.AbstractFormDelegate {
0156                     background: Item {}
0157                     contentItem: ColumnLayout {
0158 
0159                         Label {
0160                             color: Kirigami.Theme.disabledTextColor
0161                             Layout.alignment: Qt.AlignHCenter
0162                             text: "BPM:"
0163                         }
0164                         Label {
0165                             Layout.alignment: Qt.AlignHCenter
0166                             text: Metronome.bpm
0167                             font.pixelSize: 30
0168                         }
0169                         RowLayout {
0170                             Layout.alignment: Qt.AlignHCenter
0171 
0172                             ToolButton {
0173                                 icon.name: "go-previous"
0174                                 onClicked: Metronome.bpm = Metronome.bpm -1
0175 
0176                             }
0177                             Dial {
0178                                 id: dial
0179                                 value: Metronome.bpm
0180                                 from: 20
0181                                 to: 260
0182                                 inputMode: Kirigami.Settings.hasTransientTouchInput? Dial.Vertical : Dial.Circular
0183 
0184                                 Behavior on value {
0185                                     NumberAnimation {}
0186                                 }
0187 
0188                                 onMoved: {
0189                                     Metronome.bpm = value
0190                                 }
0191                                 contentItem: Item {
0192                                     id: container
0193                                     anchors.fill: dial
0194                                     Rectangle {
0195                                         id: animation
0196                                         anchors.centerIn: parent
0197                                         width: height
0198                                         height: playPauseButton.height * 0.75
0199                                         radius: height * 0.5
0200                                         color: Kirigami.Theme.hoverColor
0201                                     }
0202                                     states: [
0203                                         State {
0204                                             name: "resized"
0205                                             PropertyChanges {
0206                                                 target: animation
0207                                                 height: 600
0208                                                 opacity: 0
0209                                             }
0210                                         },
0211                                         State {
0212                                             name: "normal"
0213                                             PropertyChanges {
0214                                                 target: animation
0215                                                 height: playPauseButton.height * 0.75
0216                                                 opacity: 0.5
0217                                             }
0218                                         }
0219                                     ]
0220                                     state: "normal"
0221                                     transitions: Transition {
0222                                         enabled: container.state == "normal"
0223 
0224                                         onRunningChanged: if (!running) {
0225                                                               container.state = "normal"
0226                                                           }
0227                                         PropertyAnimation {
0228 
0229                                             properties: "height, opacity"
0230                                             easing.type: Easing.InOutQuad
0231                                         }
0232                                     }
0233                                     RoundButton {
0234                                         z: 1000
0235                                         height: width
0236                                         width: 50
0237                                         id: playPauseButton
0238                                         anchors.centerIn: parent
0239                                         checkable: true
0240                                         checked: Metronome.running
0241                                         icon.name: checked ? "media-playback-pause" : "media-playback-start"
0242                                         onClicked: checked ? Metronome.start() : Metronome.stop()
0243                                     }
0244                                 }
0245                             }
0246                             ToolButton {
0247                                 icon.name: "go-next"
0248                                 onClicked: Metronome.bpm = Metronome.bpm + 1
0249 
0250                             }
0251                         }
0252                     }
0253                 }
0254             }
0255         }
0256 
0257         Item {
0258             Layout.fillHeight: true
0259         }
0260     }
0261 }