From bd3a056f4e99fcd6b4e89f507e15a006d6420772 Mon Sep 17 00:00:00 2001 From: Alexander Ivash Date: Wed, 20 Dec 2017 23:19:24 +0000 Subject: [PATCH] rename exposed to QML "Audio" context object to "AudioScriptingInteface" to avoid naming conflict note: I'm not sure what exactly causes naming conflict - importing QtMultimedia in ForceLoad.qml, or the fact of existance of Audio.qml, but starting with Qt 5.10.0 'Audio' already exists in global scope --- interface/resources/qml/AudioScope.qml | 8 ++--- interface/resources/qml/hifi/audio/Audio.qml | 34 +++++++++---------- .../resources/qml/hifi/audio/InputPeak.qml | 2 +- interface/resources/qml/hifi/audio/MicBar.qml | 14 ++++---- .../qml/hifi/audio/PlaySampleSound.qml | 4 +-- interface/src/Application.cpp | 7 ++-- interface/src/ui/overlays/Web3DOverlay.cpp | 8 +++-- 7 files changed, 41 insertions(+), 36 deletions(-) diff --git a/interface/resources/qml/AudioScope.qml b/interface/resources/qml/AudioScope.qml index aea1473c3d..aa181dbf8d 100644 --- a/interface/resources/qml/AudioScope.qml +++ b/interface/resources/qml/AudioScope.qml @@ -110,7 +110,7 @@ Item { } function pullFreshValues() { - if (Audio.getRecording()) { + if (AudioScriptingInterface.getRecording()) { updateRecordingLabel(); } @@ -129,14 +129,14 @@ Item { _wavFilePath = _wavFilePath.replace(/[\-:]|\.\d*Z$/g, "").replace("T", "-") + ".wav"; // Using controller recording default directory _wavFilePath = Recording.getDefaultRecordingSaveDirectory() + _wavFilePath; - if (!Audio.startRecording(_wavFilePath)) { + if (!AudioScriptingInterface.startRecording(_wavFilePath)) { Messages.sendMessage("Hifi-Notifications", JSON.stringify({message:"Error creating: "+_wavFilePath})); updateRecordingUI(false); } } function stopRecording() { - Audio.stopRecording(); + AudioScriptingInterface.stopRecording(); setRecordingLabelOpacity(0.0); Messages.sendMessage("Hifi-Notifications", JSON.stringify({message:"Saved: "+_wavFilePath})); } @@ -158,7 +158,7 @@ Item { } function toggleRecording() { - if (Audio.getRecording()) { + if (AudioScriptingInterface.getRecording()) { updateRecordingUI(false); stopRecording(); } else { diff --git a/interface/resources/qml/hifi/audio/Audio.qml b/interface/resources/qml/hifi/audio/Audio.qml index 87ddce49ca..eab1e40af0 100644 --- a/interface/resources/qml/hifi/audio/Audio.qml +++ b/interface/resources/qml/hifi/audio/Audio.qml @@ -26,7 +26,7 @@ Rectangle { HifiConstants { id: hifi; } property var eventBridge; - property string title: "Audio Settings - " + Audio.context; + property string title: "Audio Settings - " + AudioScriptingInterface.context; signal sendToScript(var message); color: hifi.colors.baseGray; @@ -37,7 +37,7 @@ Rectangle { } - property bool isVR: Audio.context === "VR" + property bool isVR: AudioScriptingInterface.context === "VR" property real rightMostInputLevelPos: 0 //placeholder for control sizes and paddings //recalculates dynamically in case of UI size is changed @@ -72,17 +72,17 @@ Rectangle { property bool showPeaks: true; function enablePeakValues() { - Audio.devices.input.peakValuesEnabled = true; - Audio.devices.input.peakValuesEnabledChanged.connect(function(enabled) { + AudioScriptingInterface.devices.input.peakValuesEnabled = true; + AudioScriptingInterface.devices.input.peakValuesEnabledChanged.connect(function(enabled) { if (!enabled && root.showPeaks) { - Audio.devices.input.peakValuesEnabled = true; + AudioScriptingInterface.devices.input.peakValuesEnabled = true; } }); } function disablePeakValues() { root.showPeaks = false; - Audio.devices.input.peakValuesEnabled = false; + AudioScriptingInterface.devices.input.peakValuesEnabled = false; } Component.onCompleted: enablePeakValues(); @@ -117,10 +117,10 @@ Rectangle { text: qsTr("Mute microphone"); spacing: margins.sizeCheckBox - boxSize isRedCheck: true; - checked: Audio.muted; + checked: AudioScriptingInterface.muted; onClicked: { - Audio.muted = checked; - checked = Qt.binding(function() { return Audio.muted; }); // restore binding + AudioScriptingInterface.muted = checked; + checked = Qt.binding(function() { return AudioScriptingInterface.muted; }); // restore binding } } } @@ -130,10 +130,10 @@ Rectangle { AudioControls.CheckBox { spacing: muteMic.spacing text: qsTr("Enable noise reduction"); - checked: Audio.noiseReduction; + checked: AudioScriptingInterface.noiseReduction; onClicked: { - Audio.noiseReduction = checked; - checked = Qt.binding(function() { return Audio.noiseReduction; }); // restore binding + AudioScriptingInterface.noiseReduction = checked; + checked = Qt.binding(function() { return AudioScriptingInterface.noiseReduction; }); // restore binding } } AudioControls.CheckBox { @@ -184,7 +184,7 @@ Rectangle { spacing: 4; snapMode: ListView.SnapToItem; clip: true; - model: Audio.devices.input; + model: AudioScriptingInterface.devices.input; delegate: Item { width: rightMostInputLevelPos height: margins.sizeCheckBox > checkBoxInput.implicitHeight ? @@ -204,7 +204,7 @@ Rectangle { text: devicename onPressed: { if (!checked) { - Audio.setInputDevice(info, bar.currentIndex === 1); + AudioScriptingInterface.setInputDevice(info, bar.currentIndex === 1); } } } @@ -215,7 +215,7 @@ Rectangle { anchors.verticalCenter: parent.verticalCenter visible: ((bar.currentIndex === 1 && isVR) || (bar.currentIndex === 0 && !isVR)) && - Audio.devices.input.peakValuesAvailable; + AudioScriptingInterface.devices.input.peakValuesAvailable; } } } @@ -256,7 +256,7 @@ Rectangle { spacing: 4; snapMode: ListView.SnapToItem; clip: true; - model: Audio.devices.output; + model: AudioScriptingInterface.devices.output; delegate: Item { width: rightMostInputLevelPos height: margins.sizeCheckBox > checkBoxOutput.implicitHeight ? @@ -273,7 +273,7 @@ Rectangle { text: devicename onPressed: { if (!checked) { - Audio.setOutputDevice(info, bar.currentIndex === 1); + AudioScriptingInterface.setOutputDevice(info, bar.currentIndex === 1); } } } diff --git a/interface/resources/qml/hifi/audio/InputPeak.qml b/interface/resources/qml/hifi/audio/InputPeak.qml index 4ff49091b1..be58c9536b 100644 --- a/interface/resources/qml/hifi/audio/InputPeak.qml +++ b/interface/resources/qml/hifi/audio/InputPeak.qml @@ -40,7 +40,7 @@ Rectangle { verticalCenter: parent.verticalCenter; } - visible: Audio.muted; + visible: AudioScriptingInterface.muted; color: colors.muted; text: "MUTED"; diff --git a/interface/resources/qml/hifi/audio/MicBar.qml b/interface/resources/qml/hifi/audio/MicBar.qml index c66904034b..e798b35e29 100644 --- a/interface/resources/qml/hifi/audio/MicBar.qml +++ b/interface/resources/qml/hifi/audio/MicBar.qml @@ -17,7 +17,7 @@ import QtGraphicalEffects 1.0 import TabletScriptingInterface 1.0 Rectangle { - readonly property var level: Audio.inputLevel; + readonly property var level: AudioScriptingInterface.inputLevel; property bool standalone: false; property var dragTarget: null; @@ -60,7 +60,7 @@ Rectangle { hoverEnabled: true; scrollGestureEnabled: false; onClicked: { - Audio.muted = !Audio.muted; + AudioScriptingInterface.muted = !AudioScriptingInterface.muted; Tablet.playSound(TabletEnums.ButtonClick); } drag.target: dragTarget; @@ -82,7 +82,7 @@ Rectangle { readonly property string red: colors.muted; readonly property string fill: "#55000000"; readonly property string border: standalone ? "#80FFFFFF" : "#55FFFFFF"; - readonly property string icon: Audio.muted ? muted : unmuted; + readonly property string icon: AudioScriptingInterface.muted ? muted : unmuted; } Item { @@ -103,7 +103,7 @@ Rectangle { readonly property string mutedIcon: "../../../icons/tablet-icons/mic-mute-i.svg"; id: image; - source: Audio.muted ? mutedIcon : unmutedIcon; + source: AudioScriptingInterface.muted ? mutedIcon : unmutedIcon; width: 30; height: 30; @@ -126,9 +126,9 @@ Rectangle { Item { id: status; - readonly property string color: Audio.muted ? colors.muted : colors.unmuted; + readonly property string color: AudioScriptingInterface.muted ? colors.muted : colors.unmuted; - visible: Audio.muted; + visible: AudioScriptingInterface.muted; anchors { left: parent.left; @@ -147,7 +147,7 @@ Rectangle { color: parent.color; - text: Audio.muted ? "MUTED" : "MUTE"; + text: AudioScriptingInterface.muted ? "MUTED" : "MUTE"; font.pointSize: 12; } diff --git a/interface/resources/qml/hifi/audio/PlaySampleSound.qml b/interface/resources/qml/hifi/audio/PlaySampleSound.qml index dec2e9bfc9..6d7eb80974 100644 --- a/interface/resources/qml/hifi/audio/PlaySampleSound.qml +++ b/interface/resources/qml/hifi/audio/PlaySampleSound.qml @@ -27,9 +27,9 @@ RowLayout { } function playSound() { // FIXME: MyAvatar is not properly exposed to QML; MyAvatar.qmlPosition is a stopgap - // FIXME: Audio.playSystemSound should not require position + // FIXME: AudioScriptingInterface.playSystemSound should not require position if (sample === null && !isPlaying) { - sample = Audio.playSystemSound(sound, MyAvatar.qmlPosition); + sample = AudioScriptingInterface.playSystemSound(sound, MyAvatar.qmlPosition); isPlaying = true; sample.finished.connect(reset); } diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index f17e06cb35..86e914ea28 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2320,9 +2320,10 @@ void Application::initializeUi() { setupPreferences(); - // For some reason there is already an "Application" object in the QML context, - // though I can't find it. Hence, "ApplicationInterface" - surfaceContext->setContextProperty("Audio", DependencyManager::get().data()); + // in Qt 5.10.0 there is already an "Audio" object in the QML context + // though I failed to find it (from QtMultimedia??). So.. let it be "AudioScriptingInterface" + surfaceContext->setContextProperty("AudioScriptingInterface", DependencyManager::get().data()); + surfaceContext->setContextProperty("AudioStats", DependencyManager::get()->getStats().data()); surfaceContext->setContextProperty("AudioScope", DependencyManager::get().data()); diff --git a/interface/src/ui/overlays/Web3DOverlay.cpp b/interface/src/ui/overlays/Web3DOverlay.cpp index fcbc51b541..a49be2b7e9 100644 --- a/interface/src/ui/overlays/Web3DOverlay.cpp +++ b/interface/src/ui/overlays/Web3DOverlay.cpp @@ -194,7 +194,11 @@ void Web3DOverlay::setupQmlSurface() { _webSurface->getSurfaceContext()->setContextProperty("offscreenFlags", flags); _webSurface->getSurfaceContext()->setContextProperty("AddressManager", DependencyManager::get().data()); _webSurface->getSurfaceContext()->setContextProperty("Account", AccountScriptingInterface::getInstance()); - _webSurface->getSurfaceContext()->setContextProperty("Audio", DependencyManager::get().data()); + + // in Qt 5.10.0 there is already an "Audio" object in the QML context + // though I failed to find it (from QtMultimedia??). So.. let it be "AudioScriptingInterface" + _webSurface->getSurfaceContext()->setContextProperty("AudioScriptingInterface", DependencyManager::get().data()); + _webSurface->getSurfaceContext()->setContextProperty("AudioStats", DependencyManager::get()->getStats().data()); _webSurface->getSurfaceContext()->setContextProperty("HMD", DependencyManager::get().data()); _webSurface->getSurfaceContext()->setContextProperty("fileDialogHelper", new FileDialogHelper()); @@ -605,4 +609,4 @@ Web3DOverlay* Web3DOverlay::createClone() const { void Web3DOverlay::emitScriptEvent(const QVariant& message) { QMetaObject::invokeMethod(this, "scriptEventReceived", Q_ARG(QVariant, message)); -} \ No newline at end of file +}