diff options
Diffstat (limited to 'src/examples/piano')
-rw-r--r-- | src/examples/piano/piano.cpp | 17 | ||||
-rw-r--r-- | src/examples/piano/piano.pro | 20 | ||||
-rw-r--r-- | src/examples/piano/piano.qrc | 8 | ||||
-rw-r--r-- | src/examples/piano/qml/DarkPianoKey.qml | 21 | ||||
-rw-r--r-- | src/examples/piano/qml/LightPianoKey.qml | 23 | ||||
-rw-r--r-- | src/examples/piano/qml/Piano.qml | 110 | ||||
-rw-r--r-- | src/examples/piano/qml/PianoKey.qml | 45 |
7 files changed, 244 insertions, 0 deletions
diff --git a/src/examples/piano/piano.cpp b/src/examples/piano/piano.cpp new file mode 100644 index 0000000..55e0bde --- /dev/null +++ b/src/examples/piano/piano.cpp @@ -0,0 +1,17 @@ +#include <QGuiApplication> +#include <QQmlEngine> +#include <QQuickView> + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + app.setApplicationName("The QuickStreamer Piano"); + + QQuickView view; + view.engine()->addImportPath(TOP_OUTDIR "/src"); + view.setSource(QUrl("qrc:///qml/Piano.qml")); + QObject::connect(&view, SIGNAL(destroyed()), &app, SLOT(quit())); + view.show(); + + return app.exec(); +} diff --git a/src/examples/piano/piano.pro b/src/examples/piano/piano.pro new file mode 100644 index 0000000..fbf020a --- /dev/null +++ b/src/examples/piano/piano.pro @@ -0,0 +1,20 @@ +TEMPLATE = app +QT = quick + +DEFINES += \ + TOP_OUTDIR=\\\"$$TOP_OUTDIR/\\\" \ + TOP_SRCDIR=\\\"$$TOP_SRCDIR/\\\" \ + OUTDIR=\\\"$$OUT_PWD/\\\" \ + SRCDIR=\\\"$$PWD/\\\" + +SOURCES += \ + piano.cpp + +RESOURCES += \ + piano.qrc + +OTHER_FILES += \ + qml/Piano.qml \ + qml/PianoKey.qml \ + qml/DarkPianoKey.qml \ + qml/LightPianoKey.qml diff --git a/src/examples/piano/piano.qrc b/src/examples/piano/piano.qrc new file mode 100644 index 0000000..32a90b7 --- /dev/null +++ b/src/examples/piano/piano.qrc @@ -0,0 +1,8 @@ +<RCC> + <qresource prefix="/"> + <file>qml/Piano.qml</file> + <file>qml/PianoKey.qml</file> + <file>qml/DarkPianoKey.qml</file> + <file>qml/LightPianoKey.qml</file> + </qresource> +</RCC> diff --git a/src/examples/piano/qml/DarkPianoKey.qml b/src/examples/piano/qml/DarkPianoKey.qml new file mode 100644 index 0000000..23ed556 --- /dev/null +++ b/src/examples/piano/qml/DarkPianoKey.qml @@ -0,0 +1,21 @@ +import QtQuick 2.0 + +PianoKey { + Gradient { + id: releasedGradient + GradientStop { position: 0.00; color: "#000" } + GradientStop { position: 0.90; color: "#333" } + GradientStop { position: 0.93; color: "#fff" } + GradientStop { position: 0.95; color: "#222" } + GradientStop { position: 1.00; color: "#000" } + } + + Gradient { + id: pressedGradient + GradientStop { position: 0.00; color: "#000" } + GradientStop { position: 0.95; color: "#333" } + GradientStop { position: 1.00; color: "#fff" } + } + + gradient: pressed ? pressedGradient : releasedGradient +} diff --git a/src/examples/piano/qml/LightPianoKey.qml b/src/examples/piano/qml/LightPianoKey.qml new file mode 100644 index 0000000..5078052 --- /dev/null +++ b/src/examples/piano/qml/LightPianoKey.qml @@ -0,0 +1,23 @@ +import QtQuick 2.0 + +PianoKey { + Gradient { + id: releasedGradient + GradientStop { position: 0.00; color: "#ccc" } + GradientStop { position: 0.10; color: "#eee" } + GradientStop { position: 0.30; color: "#fff" } + GradientStop { position: 0.95; color: "#fff" } + GradientStop { position: 1.00; color: "#ddd" } + } + + Gradient { + id: pressedGradient + GradientStop { position: 0.00; color: "#ccc" } + GradientStop { position: 0.10; color: "#eee" } + GradientStop { position: 0.30; color: "#fff" } + GradientStop { position: 0.50; color: "#fff" } + GradientStop { position: 1.00; color: "#ddd" } + } + + gradient: pressed ? pressedGradient : releasedGradient +} diff --git a/src/examples/piano/qml/Piano.qml b/src/examples/piano/qml/Piano.qml new file mode 100644 index 0000000..d0a8711 --- /dev/null +++ b/src/examples/piano/qml/Piano.qml @@ -0,0 +1,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 + } + } +} diff --git a/src/examples/piano/qml/PianoKey.qml b/src/examples/piano/qml/PianoKey.qml new file mode 100644 index 0000000..a695557 --- /dev/null +++ b/src/examples/piano/qml/PianoKey.qml @@ -0,0 +1,45 @@ +import QtQuick 2.0 + +Rectangle { + property bool pressed: false + property double frequency: 440 + property string note: "" + + border { + color: "#000" + width: 1 + } + + width: 25 + height: 100 + + MouseArea { + anchors { fill:parent; margins: 1 } + onReleased: parent.pressed = false + onPressed: parent.pressed = true + } + + Text { + anchors { + top: parent.bottom + horizontalCenter: parent.horizontalCenter + } + + text: note + visible: note + opacity: parent.pressed ? 1 : 0.8 + font.bold: parent.pressed + } + + Text { + anchors { + bottom: parent.top + bottomMargin: 50 + horizontalCenter: parent.horizontalCenter + } + + text: parent.frequency + font.pixelSize: 8 + rotation: 90 + } +} |