From d3d36324c070bef7cf1b788f0b1b27b07996b45c Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Wed, 14 Jun 2017 09:02:01 -0400 Subject: [PATCH] play sample output sound --- interface/resources/qml/hifi/audio/Audio.qml | 28 ++++--- .../qml/hifi/audio/PlaySampleSound.qml | 79 +++++++++++++++++++ 2 files changed, 96 insertions(+), 11 deletions(-) create mode 100644 interface/resources/qml/hifi/audio/PlaySampleSound.qml diff --git a/interface/resources/qml/hifi/audio/Audio.qml b/interface/resources/qml/hifi/audio/Audio.qml index a30aba2a6b..d656d94488 100644 --- a/interface/resources/qml/hifi/audio/Audio.qml +++ b/interface/resources/qml/hifi/audio/Audio.qml @@ -124,17 +124,23 @@ Rectangle { Separator {} RowLayout { - HiFiGlyphs { - text: hifi.glyphs.unmuted; - color: hifi.colors.primaryHighlight; - anchors.verticalCenter: parent.verticalCenter; - size: 36; - } - RalewayRegular { - anchors.verticalCenter: parent.verticalCenter; - size: 16; - color: hifi.colors.lightGrayText; - text: qsTr("CHOOSE OUTPUT DEVICE"); + Column { + RowLayout { + HiFiGlyphs { + text: hifi.glyphs.unmuted; + color: hifi.colors.primaryHighlight; + anchors.verticalCenter: parent.verticalCenter; + size: 36; + } + RalewayRegular { + anchors.verticalCenter: parent.verticalCenter; + size: 16; + color: hifi.colors.lightGrayText; + text: qsTr("CHOOSE OUTPUT DEVICE"); + } + } + + PlaySampleSound { anchors { left: parent.left; leftMargin: 60 }} } } diff --git a/interface/resources/qml/hifi/audio/PlaySampleSound.qml b/interface/resources/qml/hifi/audio/PlaySampleSound.qml new file mode 100644 index 0000000000..72b155e56d --- /dev/null +++ b/interface/resources/qml/hifi/audio/PlaySampleSound.qml @@ -0,0 +1,79 @@ +// +// PlaySampleSound.qml +// qml/hifi/audio +// +// Created by Zach Pomerantz on 6/13/2017 +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +import QtQuick 2.5 +import QtQuick.Controls 1.4 +import QtQuick.Controls.Styles 1.4 +import QtQuick.Layouts 1.3 + +import "../../styles-uit" +import "../../controls-uit" as HifiControls + +RowLayout { + property var sound: null; + property var sample: null; + property bool isPlaying: false; + function createSampleSound() { + var SOUND = Qt.resolvedUrl("../../../sounds/sample.wav"); + sound = SoundCache.getSound(SOUND); + sample = null; + } + function playSound() { + sample = Audio.playSound(sound, { position: MyAvatar.position, loop: false, localOnly: true }); + isPlaying = true; + sample.finished.connect(function() { isPlaying = false; sample = null; }); + } + function stopSound() { + sample && sample.stop(); + } + + Component.onCompleted: createSampleSound(); + Component.onDestruction: stopSound(); + + HifiConstants { id: hifi; } + + Button { + style: ButtonStyle { + background: Rectangle { + implicitWidth: 20; + implicitHeight: 20; + radius: hifi.buttons.radius; + gradient: Gradient { + GradientStop { + position: 0.2; + color: isPlaying ? hifi.buttons.colorStart[hifi.buttons.blue] : hifi.buttons.colorStart[hifi.buttons.black]; + } + GradientStop { + position: 1.0; + color: isPlaying ? hifi.buttons.colorFinish[hifi.buttons.blue] : hifi.buttons.colorFinish[hifi.buttons.black]; + } + } + } + label: RalewayRegular { + // absolutely position due to asymmetry in glyph + x: isPlaying ? 0 : 1; + y: 1; + size: 14; + color: (control.pressed || control.hovered) ? (isPlaying ? "black" : hifi.colors.primaryHighlight) : "white"; + text: isPlaying ? hifi.glyphs.stop_square : hifi.glyphs.playback_play; + } + } + onClicked: isPlaying ? stopSound() : playSound(); + } + + RalewayRegular { + Layout.leftMargin: 2; + size: 14; + color: "white"; + text: isPlaying ? qsTr("Stop sample sound") : qsTr("Play sample sound"); + } + +}