Commit 36bed02a authored by Timothée Giet's avatar Timothée Giet
Browse files

GCSfx for audioEffects

new GCSfx component using SoundEffect qml component
much more efficient than GCAudio but restricted to wav files

(cherry picked from commit 73b2324b)
parent b3df7c15
......@@ -52,7 +52,7 @@ ActivityBase {
property alias score: score
property alias balloon: balloon
property alias timer:timer
property GCAudio audioEffects: activity.audioEffects
property GCSfx audioEffects: activity.audioEffects
}
onStart: Activity.start(coreItems, otherItems, operand)
......
......@@ -53,7 +53,7 @@ ActivityBase {
property alias question: question
property alias answer: answer
property alias choice: choice
property GCAudio audioEffects: activity.audioEffects
property GCSfx audioEffects: activity.audioEffects
property alias background: background
property alias bar: bar
property alias bonus: bonus
......
......@@ -133,7 +133,7 @@ ActivityBase {
property var buttonType: Fixture.Category5
property alias parser: parser
property double dpi
property GCAudio audioEffects: activity.audioEffects
property GCSfx audioEffects: activity.audioEffects
property Loading loading: activity.loading
}
......
......@@ -54,7 +54,7 @@ ActivityBase {
QtObject {
id: items
property Item main: activity.main
property GCAudio audioEffects: activity.audioEffects
property GCSfx audioEffects: activity.audioEffects
property alias background: background
property alias bar: bar
property alias bonus: bonus
......@@ -331,7 +331,6 @@ ActivityBase {
var to = moveToDo.to;
var moves = moveToDo.move;
items.audioEffects.play('qrc:/gcompris/src/core/resource/sounds/scroll.wav')
var fromPiece = getPieceAt(from)
var toPiece = getPieceAt(to)
......
......@@ -63,7 +63,7 @@ ActivityBase {
QtObject {
id: items
property Item main: activity.main
property GCAudio audioEffects: activity.audioEffects
property GCSfx audioEffects: activity.audioEffects
property alias background: background
property alias bar: bar
property alias bonus: bonus
......@@ -383,7 +383,6 @@ ActivityBase {
}
function moveTo(from, to) {
items.audioEffects.play('qrc:/gcompris/src/core/resource/sounds/scroll.wav')
var fromPiece = getPieceAt(from)
var toPiece = getPieceAt(to)
if(toPiece.img != '')
......
......@@ -43,7 +43,7 @@ Rectangle {
// True when the value is entered correctly
property bool valid: false
property GCAudio audioEffects
property GCSfx audioEffects
Component.onCompleted: Activity.registerAnswerItem(answerBackground)
......
......@@ -78,7 +78,7 @@ ActivityBase {
id: items
property GCAudio audioVoices: activity.audioVoices
property GCAudio audioEffects: activity.audioEffects
property GCSfx audioEffects: activity.audioEffects
property Item main: activity.main
property alias background: background
property alias bar: bar
......
......@@ -52,7 +52,7 @@ ActivityBase {
QtObject {
id: items
property Item main: activity.main
property GCAudio audioEffects: activity.audioEffects
property GCSfx audioEffects: activity.audioEffects
property alias background: background
property alias bar: bar
property alias bonus: bonus
......
......@@ -49,7 +49,7 @@ ActivityBase {
QtObject {
id: items
property alias background: background
property GCAudio audioEffects: activity.audioEffects
property GCSfx audioEffects: activity.audioEffects
property alias fireman: fireman
property alias fire: fire
property alias bar: bar
......
......@@ -25,7 +25,7 @@ Item {
id: part
property QtObject items
property int index
property GCAudio audioEffects
property GCSfx audioEffects
Rectangle {
anchors.horizontalCenter: parent.horizontalCenter
......
......@@ -58,7 +58,7 @@ ActivityBase {
property alias bar: bar
property alias bonus: bonus
property alias timer: timer
property GCAudio audioEffects: activity.audioEffects
property GCSfx audioEffects: activity.audioEffects
}
onStart: { Activity.start(items) }
......
......@@ -91,7 +91,7 @@ ActivityBase {
property alias score: score
property alias keyboard: keyboard
property alias wordDropTimer: wordDropTimer
property GCAudio audioEffects: activity.audioEffects
property GCSfx audioEffects: activity.audioEffects
property alias locale: background.locale
property alias textinput: textinput
}
......
......@@ -34,7 +34,7 @@ Item {
property int frames
property int frameW
property real widthRatio
property GCAudio audioEffects
property GCSfx audioEffects
function moveTo(direction) {
if (!movable)
......
......@@ -62,7 +62,7 @@ ActivityBase {
property int result: data[sublevel-1][1]
property alias timer: timer
property alias warningDialog: warningDialog
property GCAudio audioEffects: activity.audioEffects
property GCSfx audioEffects: activity.audioEffects
property bool solved
property bool levelchanged: false
property var levelArr
......
......@@ -28,7 +28,7 @@ import GCompris 1.0
Item {
id: hexagon
property GCAudio audioEffects
property GCSfx audioEffects
property ParticleSystemStar particles
property alias color: softCanvas.color
property bool hasStrawberry: false
......
......@@ -78,7 +78,7 @@ ActivityBase {
property alias timer: timer
property alias arrow: arrow
property alias asteroidCreation: asteroidCreation
property GCAudio audioEffects: activity.audioEffects
property GCSfx audioEffects: activity.audioEffects
property double distLeft: Math.abs(spaceshipX / ApplicationInfo.ratio)
property double distRight: Math.abs((background.width - spaceshipX) / ApplicationInfo.ratio)
property double forceLeft: (Math.pow(scaleLeft, 2) / Math.pow(distLeft, 2)) * Math.pow(10, 6)
......
......@@ -45,7 +45,7 @@ ActivityBase {
id: items
property alias bar: bar
property alias bonus: bonus
property GCAudio audioEffects: activity.audioEffects
property GCSfx audioEffects: activity.audioEffects
property alias imageAnimOff: imageAnimOff
property alias leftButton: leftButton
property alias rightButton: rightButton
......
......@@ -30,7 +30,7 @@ Item {
property alias state: hatImg.state
property alias target: offStar
property int starsSize
property GCAudio audioEffects
property GCSfx audioEffects
function getTarget() {
return offStar
......
......@@ -60,7 +60,7 @@ ActivityBase {
id: items
property Item main: activity.main
property alias background: background
property GCAudio audioEffects: activity.audioEffects
property GCSfx audioEffects: activity.audioEffects
property alias bar: bar
property alias bonus: bonus
property alias hat: theHat
......
......@@ -61,7 +61,7 @@ ActivityBase {
property alias mazeRows: maze.rows
property alias mazeColumns: maze.columns
property alias mazeRepeater: mazeRepeater.model
property GCAudio audioEffects: activity.audioEffects
property GCSfx audioEffects: activity.audioEffects
property alias message: message
property int playerx: 0
property int playery: 0
......
......@@ -36,7 +36,7 @@ Flipable {
property bool tuxTurn
property GCAudio audioVoices
property GCAudio audioEffects
property GCSfx audioEffects
onIsFoundChanged: {
opacity = 0
......
......@@ -59,7 +59,7 @@ ActivityBase {
id: items
property alias bar: bar
property alias bonus: bonus
property GCAudio audioEffects: activity.audioEffects
property GCSfx audioEffects: activity.audioEffects
property bool withTux: activity.withTux
property bool tuxTurn: false
property var playQueue
......
......@@ -50,7 +50,7 @@ ActivityBase {
id: items
property Item main: activity.main
property alias background: background
property GCAudio audioEffects: activity.audioEffects
property GCSfx audioEffects: activity.audioEffects
property alias answerModel: answerModel
property alias pocketModel: pocketModel
property alias store: store
......
......@@ -48,7 +48,7 @@ ActivityBase {
QtObject {
id: items
property Item main: activity.main
property GCAudio audioEffects: activity.audioEffects
property GCSfx audioEffects: activity.audioEffects
property alias question: question
property alias answer: answer
property alias selector: selector
......
......@@ -57,7 +57,7 @@ ActivityBase {
property alias background: background
property alias bar: bar
property alias bonus: bonus
property GCAudio audioEffects: activity.audioEffects
property GCSfx audioEffects: activity.audioEffects
property GCAudio audioVoices: activity.audioVoices
property alias pointImageRepeater: pointImageRepeater
property alias segmentsRepeater: segmentsRepeater
......
......@@ -34,7 +34,7 @@ Image {
background.vert ? (background.height - background.barHeight - 40 - frame.problemTextHeight) / 2 :
background.height - background.barHeight - 30 - frame.problemTextHeight
property GCAudio audioEffects: activity.audioEffects
property GCSfx audioEffects: activity.audioEffects
property alias repeater: repeater
property alias circleRepeater: circleRepeater
property int good: 0
......
......@@ -71,7 +71,7 @@ ActivityBase {
property alias score: score
property alias plane: plane
property GCAudio audioVoices: activity.audioVoices
property GCAudio audioEffects: activity.audioEffects
property GCSfx audioEffects: activity.audioEffects
property alias movePlaneTimer: movePlaneTimer
property alias cloudCreation: cloudCreation
}
......
......@@ -62,7 +62,7 @@ ActivityBase {
property alias background: background
property alias bar: bar
property alias bonus: bonus
property GCAudio audioEffects: activity.audioEffects
property GCSfx audioEffects: activity.audioEffects
property int currentLevel
property int numberOfLevel: 3
property bool sunIsUp
......
......@@ -33,7 +33,7 @@ Item {
property alias value1: domino.value1
property alias value2: domino.value2
property alias valueMax: domino.valueMax
property GCAudio audioEffects
property GCSfx audioEffects
Row {
id: barRow
......
......@@ -50,7 +50,7 @@ ActivityBase {
QtObject {
id: items
property Item main: activity.main
property GCAudio audioEffects: activity.audioEffects
property GCSfx audioEffects: activity.audioEffects
property alias background: background
property alias backgroundImg: backgroundImg
property alias bar: bar
......
......@@ -46,7 +46,7 @@ Rectangle {
property int weight: 0
property GCAudio audioEffects
property GCSfx audioEffects
function init() {
weight = 0
......
......@@ -57,7 +57,7 @@ ActivityBase {
property alias bar: bar
property alias bonus: bonus
property alias score: score
property GCAudio audioEffects: activity.audioEffects
property GCSfx audioEffects: activity.audioEffects
property alias availablePiecesModel: availablePieces
property alias columns: sudoColumn.columns
property alias rows: sudoColumn.rows
......
......@@ -37,7 +37,7 @@ Item {
property alias model: mymodel;
property alias view: view;
property GCAudio audioEffects
property GCSfx audioEffects
ListModel {
id: mymodel
......
......@@ -64,7 +64,7 @@ Item {
property real effY: car.yPos * car.blockSize
property real effWidth: (mode == "COLOR" || car.isHorizontal) ? car.width : car.height
property real effHeight: (mode == "COLOR" || car.isHorizontal) ? car.height : car.width
property GCAudio audioEffects
property GCSfx audioEffects
width: (mode == "IMAGE" || isHorizontal) ? (size * blockSize) : blockSize
height: (mode == "IMAGE" || isHorizontal) ? blockSize : (size * blockSize)
......
......@@ -53,7 +53,7 @@ ActivityBase {
QtObject {
id: items
property Item main: activity.main
property GCAudio audioEffects: activity.audioEffects
property GCSfx audioEffects: activity.audioEffects
property alias background: background
property alias bar: bar
property alias bonus: bonus
......
......@@ -73,7 +73,7 @@ ActivityBase {
}
property bool cycleDone: false
property GCAudio audioEffects: activity.audioEffects
property GCSfx audioEffects: activity.audioEffects
}
IntroMessage {
......
......@@ -111,7 +111,7 @@ Item {
* Append to it to play your effects.
* @sa GCAudio audioEffects
*/
property GCAudio audioEffects
property GCSfx audioEffects
/**
* type:Loading
......
......@@ -100,7 +100,7 @@ Item {
property int wrongAnswerShakeAmplitude: wrongAnswerShakeAmplitudeCalc < wrongAnswerShakeAmplitudeMin ? wrongAnswerShakeAmplitudeMin : wrongAnswerShakeAmplitudeCalc
// If you want the sound effects just pass the audioEffects
property GCAudio audioEffects
property GCSfx audioEffects
/**
* Emitted when button is pressed as a good answer.
......
......@@ -154,6 +154,7 @@ Image {
winVoices[Math.floor(Math.random()*winVoices.length)])))
if(winSound)
audioEffects.play(winSound)
start()
animation.start()
}
......@@ -162,7 +163,7 @@ Image {
* Private: Triggers loose feedback after the timer completion.
*/
function _bad(name) {
if(!audioEffects.play(
if(!audioVoices.play(
ApplicationInfo.getAudioFilePath(
looseVoices[Math.floor(Math.random()*looseVoices.length)])))
if(looseSound)
......
......@@ -66,7 +66,7 @@ Flipable {
// Set to false to prevent user inputs.
property bool isClickable: true
property GCAudio audioEffects
property GCSfx audioEffects
front: Rectangle {
anchors.fill: parent
......
......@@ -76,7 +76,7 @@ Item {
* type:GCAudio
* To play sound and audio effects.
*/
property GCAudio audioEffects
property GCSfx audioEffects
function isVisible(index) {
var value = item.value
......
/* GCompris - GCSoundEffect.qml
*
* Copyright (C) 2018 Timothée Giet <animtim@gmail.com>
*
* Authors:
* Johnny Jazeix <jazeix@gmail.com> (GCAudio base, 2014)
* Timothée Giet <animtim@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.6
import QtMultimedia 5.0
import GCompris 1.0
/**
* A QML component for sfx playback.
* @ingroup components
*
* Wrapper component around QtQuick's SoundEffect element, handling all sfx
* playback in GCompris uniformly.
*
* It maintains a queue of sfx-sources (@ref files) that are played back
* sequentially, to which the user can enqueue files that should be scheduled
* for playback.
*
* To make sure an sfx voice will be localized, replace the locale part
* of the file by '$LOCALE'.
*
* To makes sure that all sfx sources are normalized with respect to
* ApplicationInfo.CompressedSoundEffect replace the 'ogg' part of the file by
* '$CA'.
*
* @inherit QtQuick.Item
*/
Item {
id: gcsfx
/**
* type:bool
* Whether sfx should be muted.
*/
property bool muted
/**
* type:url
* URL to the sfx source to be played back.
*/
property alias source: sfx.source
/**
* type:string
* Status of the fx player.
*/
property alias status: sfx.status
/**
* type:var
* Current playback state.
*
* Possible values taken from SoundEffect.status
*/
property var playbackState: (sfx.error == SoundEffect.NoError) ?
sfx.playbackState : SoundEffect.StoppedState;
/**
* type:list
* Playback queue.
*/
property var files: []
/**
* Emitted in case of error.
*/
signal error
/**
* Emitted when playback of all scheduled sfx sources has finished.
*/
signal done
/**
* When mute is changed we set the volume to 0 to mute a potential playing
* sound.
*/
onMutedChanged: muted ? sfx.volume = 0 : sfx.volume = 1
/**
* Plays back the sfx resource @p file.
*
* @param type:string file [optional] URL to an sfx source.
* @returns @c true if playback has been started, @c false if file does not
* exist or sfx is muted
*/
function play(file) {
if(!fileId.exists(file) || muted)
return false
if(file) {
// Setting the source to "" on Linux fix a case where the sound is no more played if you play twice the same sound in a row
source = ""
source = file
}
if(!muted) {
sfx.play()
}
return true
}
/**
* Stops sfx playback.
*/
function stop() {
if(sfx.playbackState != SoundEffect.StoppedState)
sfx.stop()
}
/**
* Schedules a @p file for sfx playback.
*
* If there is no playback currently running, the new source will be
* played back immediately. Otherwise it is appended to the file queue of
* sources.
*
* @param type:string file File to the sfx file to be played back.
* @returns @c true upon success, or @c false if @p file does not exist or
* sfx is muted
*/
function append(file) {
if(!fileId.exists(file) || muted)
return false
if(sfx.playbackState !== SoundEffect.PlayingState
|| sfx.status === SoundEffect.EndOfMedia
|| sfx.status === SoundEffect.NoMedia
|| sfx.status === SoundEffect.InvalidMedia) {
// Setting the source to "" on Linux fix a case where the sound is no more played
source = ""
source = file
files.push(file)
silenceTimer.start()
} else {
files.push(file)
}
return true
}
/**
* Adds a pause of the given duration in ms before playing of the next file.
*
* @param type:int duration_ms Pause in milliseconds.
*/
function silence(duration_ms) {
silenceTimer.interval = duration_ms
}