summaryrefslogtreecommitdiff
path: root/src/examples/piano/qml/Piano.qml
blob: d0a8711b3bc2c03a5b91624d8526df71728258c1 (plain)
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
import QtQuick 2.0
import QuickStreamer 1.0

Rectangle {
    width: 800
    height: 600
    color: "#284"

    Row {
        id: lightKeys
        anchors.centerIn: parent

        Repeater {
            model: 28

            LightPianoKey {
                width: 24
                height: 145

                note: {
                    var n = "cdefgah"[index % 7]

                    if (index < 7)
                        return n.toUpperCase();

                    return n +  "'''".substr(4 - Math.floor(index / 7))
                }

                frequency: {
                    return 220 * Math.pow(Math.pow(2, 1/12),
                                          Math.floor(index / 7) * 12 +
                                          [0, 2, 4, 5, 7, 9, 11][index % 7])
                }

                onPressedChanged: {
                    audioSource.freq = frequency
                    audioSource.volume = pressed ? 1 : 0
                    pipeline.state = 4
                }
            }
        }
    }

    Row {
        anchors {
            horizontalCenter: parent.horizontalCenter
            top: lightKeys.top
        }

        spacing: 11

        Repeater {
            model: 27

            Item {
                width: 13
                height: 100

                DarkPianoKey {
                    anchors.fill: parent
                    visible: (index % 7) != 2 && (index % 7) != 6

                    frequency: {
                        return 220 * Math.pow(Math.pow(2, 1/12),
                                              Math.floor(index / 7) * 12 +
                                              [1, 3, 0, 6, 8, 10, 0][index % 7])
                    }

                    onPressedChanged: {
                        audioSource.freq = frequency
                        audioSource.volume = pressed ? 1 : 0
                        pipeline.state = 4
                    }
                }
            }
        }
    }

    Pipeline {
        id: pipeline
//        state: 4 // FIXME: this should be an enum

        AudioTestSrc {
            id: audioSource

            Behavior on volume {
                NumberAnimation {
                    easing: Easing.OutQuart
                    duration: 100
                }
            }

            /* fun:
            Behavior on freq {
                NumberAnimation {
                    easing: Easing.OutQuart
                    duration: 1500
                }
            }
            */

            volume: 0
//            wave: 12
        }

        AutoAudioSink {
            id: audioSink
        }
    }
}