Commit 83192a9c authored by Bruno Coudoin's avatar Bruno Coudoin
Browse files

core, audio refactoring

We now have 2 global audio items, one for the voices, one for the effects.

They both can be mutted from our configuration dialog

They are both passed to the ActivityBase of the activity and they must be used
there instead of creating a GCAudio in the activity itself.

This patch does not include the refactoring of all activities.
parent d5279e34
......@@ -20,7 +20,6 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.2
import QtMultimedia 5.0
import GCompris 1.0
import "../../core"
import "algorithm.js" as Activity
......@@ -54,7 +53,7 @@ ActivityBase {
property alias question: question
property alias answer: answer
property alias choice: choice
property alias audio: audio
property GCAudio audioEffects: activity.audioEffects
property alias background: background
property alias bar: bar
property alias bonus: bonus
......@@ -208,9 +207,6 @@ ActivityBase {
}
}
}
GCAudio {
id: audio
}
DialogHelp {
id: dialogHelp
......
/* GCompris - algorithm.js
*
* Copyright (C) 2014 <YOUR NAME HERE>
* Copyright (C) 2014 Bharath M S" <brat.197@gmail.com>
*
* Authors:
* Christof Petig and Ingo Konrad (GTK+ version)
......@@ -32,7 +32,6 @@ getSetLength() - returns the number of unique indices in the chosen sample
getImages() - returns a random array of length 8 that is based on the chosen sample
setQuestion() - the function is called to set questionTray
setAnswer() - the function is called to set answerTray
playSound() - the function used to play audio brick and bleep
clickHandler() - called to handle click event
variables :-
......@@ -158,12 +157,6 @@ function setAnswer(indices){
var choiceCount = 5 //game is won when choiceCount = 8
var times = 0 // level increases when times = 3
// The audio part does not work as expected
function playSound(id) {
items.audio.source = "qrc:/gcompris/src/core/resource/sounds/" + id + ".wav"
items.audio.play()
}
function clickHandler(id){
var tempIndex = []
......@@ -171,7 +164,7 @@ function clickHandler(id){
if(id === answerIndex[choiceCount]) { //correct answer
tempIndex = items.answer.model
choiceCount++;
playSound('bleep')
items.audioEffects.play('qrc:/gcompris/src/core/resource/sounds/bleep.wav')
if(choiceCount < 8){
tempIndex.push('question_mark')
......@@ -193,7 +186,7 @@ function clickHandler(id){
}
return 1
} else { // Wrong answer, try again
playSound('brick')
items.audioEffects.play('qrc:/gcompris/src/core/resource/sounds/brick.wav')
}
}
......
......@@ -230,31 +230,7 @@ to make the ball go in a straight line.")
}
function playSound(identifier) {
if(identifier == "tuxok") {
tuxok.play()
}
else if(identifier == "youcannot") {
youcannot.play()
}
else if(identifier == "brick") {
brick.play()
}
}
GCAudio {
id: brick
source: "qrc:/gcompris/src/activities/ballcatch/resource/brick.wav"
}
GCAudio {
id: tuxok
source: "qrc:/gcompris/src/activities/ballcatch/resource/tuxok.wav"
}
GCAudio {
id: youcannot
source: "qrc:/gcompris/src/activities/ballcatch/resource/youcannot.wav"
activity.audioEffects.play("qrc:/gcompris/src/activities/ballcatch/resource/"+ identifier + ".wav")
}
/* Timer starting when user first presses a first key.
......
......@@ -34,14 +34,9 @@ ActivityBase {
onStart: {}
onStop: {}
GCAudio {
id: audio
source: "qrc:/gcompris/src/activities/clickgame/resource/bubble.wav"
}
Timer {
interval: 5000; running: true; repeat: true
onTriggered: audio.play()
onTriggered: activity.audioEffects.play("qrc:/gcompris/src/activities/clickgame/resource/bubble.wav")
}
pageComponent: Image {
......@@ -57,7 +52,7 @@ ActivityBase {
activity.start.connect(start)
activity.stop.connect(stop)
}
onStart: { Activity.start(main, background, bar, bonus) }
onStart: { Activity.start(activity, background, bar, bonus) }
onStop: { Activity.stop() }
DialogHelp {
......
......@@ -21,14 +21,13 @@
*/
import QtQuick 2.1
import QtQuick.Particles 2.0
import QtMultimedia 5.0
import "clickgame.js" as Activity
import "../../core"
import GCompris 1.0
AnimatedSprite {
id: fish
property Item main
property Item activity
property Item bar
property real targetX // The x target of the fish
property int duration: 5000
......@@ -36,15 +35,10 @@ AnimatedSprite {
interpolate: true
Component.onCompleted: {
targetX = main.width - fish.width
targetX = activity.width - fish.width
x = targetX
}
GCAudio {
id: audioDrip
source: "qrc:/gcompris/src/activities/clickgame/resource/drip.wav"
}
transform: Rotation {
id: rotate; origin.x: width / 2; origin.y: 0; axis { x: 0; y: 1; z: 0 } angle: 0
}
......@@ -74,16 +68,16 @@ AnimatedSprite {
}
onXChanged: {
if( (x > main.width - fish.width && rotate.angle == 0) ||
if( (x > activity.width - fish.width && rotate.angle == 0) ||
(x == targetX && rotate.angle == 0) ) {
rotateLeftAnimation.start()
targetX = 0
x = targetX
y = Activity.currentLevel > 0 ? Math.random() * (main.height - bar.height - fish.height) : y
y = Activity.currentLevel > 0 ? Math.random() * (activity.height - bar.height - fish.height) : y
bubbleEffect.restart()
} else if(x == 0 && rotate.angle == 180) {
rotateRightAnimation.start()
targetX = main.width - fish.width
targetX = activity.width - fish.width
x = targetX
bubbleEffect.restart()
}
......@@ -97,7 +91,7 @@ AnimatedSprite {
onClicked: {
parent.opacity = 0
enabled = false
audioDrip.play()
activity.audioEffects.play("qrc:/gcompris/src/activities/clickgame/resource/drip.wav")
Activity.fishKilled()
particles.emitter.burst(40);
}
......
......@@ -212,7 +212,7 @@ var levelProperty = [
]
var currentImageId = 0
var currentLevel = 0
var main
var activity
var background
var bar
var bonus
......@@ -221,8 +221,8 @@ var bonus
var createdFishes
var killedFishes
function start(main_, background_, bar_, bonus_) {
main = main_
function start(activity_, background_, bar_, bonus_) {
activity = activity_
background = background_
bar = bar_
bonus = bonus_
......@@ -265,10 +265,10 @@ function createFish(minDuration) {
var fish = component.createObject(
background,
{
"main": main,
"activity": activity,
"bar": bar,
"x": Math.random() * (main.width - fishSource.width),
"y": Math.random() * (main.height - bar.height - fishSource.height),
"x": Math.random() * (activity.width - fishSource.width),
"y": Math.random() * (activity.height - bar.height - fishSource.height),
"width": fishSource.width * 1.1 * GCompris.ApplicationInfo.ratio,
"height": fishSource.height * 1.1 * GCompris.ApplicationInfo.ratio,
"source": "qrc:/gcompris/src/activities/clickgame/resource/" +
......
......@@ -98,7 +98,7 @@ ActivityBase {
function initQuestion() {
text = Activity.getCurrentTextQuestion()
if(Activity.getCurrentAudioQuestion()) {
activity.audio.append(Activity.getCurrentAudioQuestion())
activity.audioVoices.append(Activity.getCurrentAudioQuestion())
}
opacity = 1.0
}
......
......@@ -61,7 +61,7 @@ ActivityBase {
property alias mazeRows: maze.rows
property alias mazeColumns: maze.columns
property alias mazeRepeater: mazeRepeater.model
property alias playBrick: playBrick
property GCAudio audioEffects: activity.audioEffects
property alias message: message
property int playerx: 0
property int playery: 0
......@@ -349,11 +349,6 @@ ActivityBase {
text: qsTr("Look at your position, then switch back to invisible mode to continue your moves")
}
GCAudio {
id: playBrick
source: "qrc:/gcompris/src/core/resource/sounds/brick.wav"
}
DialogHelp {
id: dialogHelp
onClose: home()
......
......@@ -364,7 +364,7 @@ function clickRight() {
if (!(maze[getId(items.playerx, items.playery)] & EAST)) {
++items.playerx
} else {
items.playBrick.play()
items.audioEffects.play("qrc:/gcompris/src/core/resource/sounds/brick.wav")
}
}
}
......@@ -389,7 +389,7 @@ function clickLeft() {
if (!(maze[getId(items.playerx, items.playery)] & WEST)) {
--items.playerx
} else {
items.playBrick.play()
items.audioEffects.play("qrc:/gcompris/src/core/resource/sounds/brick.wav")
}
}
}
......@@ -418,7 +418,7 @@ function clickDown() {
if (!(maze[getId(items.playerx, items.playery)] & SOUTH)) {
++items.playery
} else {
items.playBrick.play()
items.audioEffects.play("qrc:/gcompris/src/core/resource/sounds/brick.wav")
}
}
}
......@@ -438,25 +438,25 @@ function clickUp() {
if (!(maze[getId(items.playerx, items.playery)] & EAST)) {
++items.playerx
} else {
items.playBrick.play()
items.audioEffects.play("qrc:/gcompris/src/core/resource/sounds/brick.wav")
}
} else if (getPlayerRotation() === 180) {
if (!(maze[getId(items.playerx, items.playery)] & NORTH)) {
--items.playery
} else {
items.playBrick.play()
items.audioEffects.play("qrc:/gcompris/src/core/resource/sounds/brick.wav")
}
} else if (getPlayerRotation() === 90) {
if (!(maze[getId(items.playerx, items.playery)] & WEST)) {
--items.playerx
} else {
items.playBrick.play()
items.audioEffects.play("qrc:/gcompris/src/core/resource/sounds/brick.wav")
}
} else {
if (!(maze[getId(items.playerx, items.playery)] & SOUTH)) {
++items.playery
} else {
items.playBrick.play()
items.audioEffects.play("qrc:/gcompris/src/core/resource/sounds/brick.wav")
}
}
} else {
......@@ -466,7 +466,7 @@ function clickUp() {
if (!(maze[getId(items.playerx, items.playery)] & NORTH)) {
--items.playery
} else {
items.playBrick.play()
items.audioEffects.play("qrc:/gcompris/src/core/resource/sounds/brick.wav")
}
}
}
......
......@@ -70,7 +70,8 @@ ActivityBase {
property alias bonus: bonus
property alias score: score
property alias plane: plane
property alias audio: audio
property GCAudio audioVoices: activity.audioVoices
property GCAudio audioEffects: activity.audioEffects
property alias movePlaneTimer: movePlaneTimer
property alias cloudCreation: cloudCreation
}
......@@ -131,9 +132,5 @@ ActivityBase {
background: background
}
GCAudio {
id: audio
}
}
}
......@@ -297,14 +297,14 @@ function handleCollisionsWithCloud() {
if(currentSubLevel === numberOfSubLevels) {
/* Try the next level */
nextLevel()
playSound("qrc:/gcompris/src/core/resource/sounds/bonus.wav")
items.audioEffects.play("qrc:/gcompris/src/core/resource/sounds/bonus.wav")
} else {
items.score.message = dataset[currentLevel].data[currentSubLevel]
}
} else {
/* Touched the wrong cloud */
if(!cloud.touched)
playSound("qrc:/gcompris/src/core/resource/sounds/crash.wav")
items.audioEffects.play("qrc:/gcompris/src/core/resource/sounds/crash.wav")
cloud.touch()
}
break;
......@@ -320,15 +320,9 @@ function handleCollisionsWithCloud() {
}
}
function playSound(sound) {
items.audio.source = sound
items.audio.play()
}
function playLetterSound(number) {
items.audio.source =
GCompris.ApplicationInfo.getAudioFilePath("voices/$LOCALE/alphabet/"
+ Core.getSoundFilenamForChar(number))
items.audio.play()
items.audioVoices.play(
GCompris.ApplicationInfo.getAudioFilePath("voices/$LOCALE/alphabet/"
+ Core.getSoundFilenamForChar(number))
)
}
......@@ -28,9 +28,11 @@ Item {
property Component pageComponent
property QtObject menu
property QtObject activityInfo
// The global audio item, append to it to play your sounds after the
// The global audio item, append to it to play your voices after the
// intro music
property GCAudio audio
property GCAudio audioVoices
// The global audio effect, use it to play sound effects
property GCAudio audioEffects
property bool isLocked: true
signal home
signal start
......
......@@ -58,8 +58,8 @@ static const QString ADMIN_GROUP_KEY = "Admin";
static const QString INTERNAL_GROUP_KEY = "Internal";
static const QString FULLSCREEN_KEY = "fullscreen";
static const QString ENABLE_AUDIO_KEY = "enableSounds";
static const QString ENABLE_EFFECTS_KEY = "enableEffects";
static const QString ENABLE_AUDIO_VOICES_KEY = "enableAudioVoices";
static const QString ENABLE_AUDIO_EFFECTS_KEY = "enableAudioEffects";
static const QString VIRTUALKEYBOARD_KEY = "virtualKeyboard";
static const QString LOCALE_KEY = "locale";
static const QString ENABLE_AUTOMATIC_DOWNLOADS = "enableAutomaticDownloads";
......@@ -81,9 +81,9 @@ ApplicationSettings::ApplicationSettings(QObject *parent): QObject(parent),
// general group
m_config.beginGroup(GENERAL_GROUP_KEY);
m_isEffectEnabled = m_config.value(ENABLE_EFFECTS_KEY, true).toBool();
m_isAudioEffectsEnabled = m_config.value(ENABLE_AUDIO_EFFECTS_KEY, true).toBool();
m_isFullscreen = m_config.value(FULLSCREEN_KEY, true).toBool();
m_isAudioEnabled = m_config.value(ENABLE_AUDIO_KEY, true).toBool();
m_isAudioVoicesEnabled = m_config.value(ENABLE_AUDIO_VOICES_KEY, true).toBool();
m_isVirtualKeyboard = m_config.value(VIRTUALKEYBOARD_KEY,
ApplicationInfo::getInstance()->isMobile()).toBool();
m_locale = m_config.value(LOCALE_KEY,
......@@ -105,8 +105,9 @@ ApplicationSettings::ApplicationSettings(QObject *parent): QObject(parent),
m_exeCount = m_config.value(EXE_COUNT_KEY, 0).toUInt();
m_config.endGroup();
connect(this, SIGNAL(audioEnabledChanged()), this, SLOT(notifyAudioEnabledChanged()));
connect(this, SIGNAL(fullscreenChanged()), this, SLOT(notifyFullscreenChanged()));
connect(this, SIGNAL(audioVoicesEnabledChanged()), this, SLOT(notifyAudioVoicesEnabledChanged()));
connect(this, SIGNAL(audioEffectsEnabledChanged()), this, SLOT(notifyAudioEffectsEnabledChanged()));
connect(this, SIGNAL(fullscreenChanged()), this, SLOT(notifyFullscreenChanged()));
connect(this, SIGNAL(localeChanged()), this, SLOT(notifyLocaleChanged()));
connect(this, SIGNAL(virtualKeyboardChanged()), this, SLOT(notifyVirtualKeyboardChanged()));
connect(this, SIGNAL(automaticDownloadsEnabledChanged()), this, SLOT(notifyAutomaticDownloadsEnabledChanged()));
......@@ -121,7 +122,7 @@ ApplicationSettings::~ApplicationSettings()
// make sure settings file is up2date:
// general group
m_config.beginGroup(GENERAL_GROUP_KEY);
m_config.setValue(ENABLE_AUDIO_KEY, m_isAudioEnabled);
m_config.setValue(ENABLE_AUDIO_VOICES_KEY, m_isAudioVoicesEnabled);
m_config.setValue(LOCALE_KEY, m_locale);
m_config.setValue(FULLSCREEN_KEY, m_isFullscreen);
m_config.setValue(VIRTUALKEYBOARD_KEY, m_isVirtualKeyboard);
......@@ -145,14 +146,24 @@ ApplicationSettings::~ApplicationSettings()
m_instance = NULL;
}
void ApplicationSettings::notifyAudioEnabledChanged()
void ApplicationSettings::notifyAudioVoicesEnabledChanged()
{
// Save in config
m_config.beginGroup(GENERAL_GROUP_KEY);
m_config.setValue(ENABLE_AUDIO_KEY, m_isAudioEnabled);
m_config.endGroup();
qDebug() << "notifyAudio: " << m_isAudioEnabled;
m_config.sync();
// Save in config
m_config.beginGroup(GENERAL_GROUP_KEY);
m_config.setValue(ENABLE_AUDIO_VOICES_KEY, m_isAudioVoicesEnabled);
m_config.endGroup();
qDebug() << "notifyAudioVoices: " << m_isAudioVoicesEnabled;
m_config.sync();
}
void ApplicationSettings::notifyAudioEffectsEnabledChanged()
{
// Save in config
m_config.beginGroup(GENERAL_GROUP_KEY);
m_config.setValue(ENABLE_AUDIO_EFFECTS_KEY, m_isAudioEffectsEnabled);
m_config.endGroup();
qDebug() << "notifyAudioEffects: " << m_isAudioEffectsEnabled;
m_config.sync();
}
void ApplicationSettings::notifyLocaleChanged()
......
......@@ -54,8 +54,8 @@ class ApplicationSettings : public QObject
Q_OBJECT
// general group
Q_PROPERTY(bool isAudioEnabled READ isAudioEnabled WRITE setIsAudioEnabled NOTIFY audioEnabledChanged)
Q_PROPERTY(bool isEffectEnabled READ isEffectEnabled WRITE setIsEffectEnabled NOTIFY effectEnabledChanged)
Q_PROPERTY(bool isAudioVoicesEnabled READ isAudioVoicesEnabled WRITE setIsAudioVoicesEnabled NOTIFY audioVoicesEnabledChanged)
Q_PROPERTY(bool isAudioEffectsEnabled READ isAudioEffectsEnabled WRITE setIsAudioEffectsEnabled NOTIFY audioEffectsEnabledChanged)
Q_PROPERTY(bool isFullscreen READ isFullscreen WRITE setFullscreen NOTIFY fullscreenChanged)
Q_PROPERTY(bool isVirtualKeyboard READ isVirtualKeyboard WRITE setVirtualKeyboard NOTIFY virtualKeyboardChanged)
Q_PROPERTY(QString locale READ locale WRITE setLocale NOTIFY localeChanged)
......@@ -86,16 +86,16 @@ public:
static QObject *systeminfoProvider(QQmlEngine *engine,
QJSEngine *scriptEngine);
bool isAudioEnabled() const { return m_isAudioEnabled; }
void setIsAudioEnabled(const bool newMode) {
m_isAudioEnabled = newMode;
emit audioEnabledChanged();
bool isAudioVoicesEnabled() const { return m_isAudioVoicesEnabled; }
void setIsAudioVoicesEnabled(const bool newMode) {
m_isAudioVoicesEnabled = newMode;
emit audioVoicesEnabledChanged();
}
bool isEffectEnabled() const { return m_isEffectEnabled; }
void setIsEffectEnabled(const bool newMode) {
m_isEffectEnabled = newMode;
emit effectEnabledChanged();
bool isAudioEffectsEnabled() const { return m_isAudioEffectsEnabled; }
void setIsAudioEffectsEnabled(const bool newMode) {
m_isAudioEffectsEnabled = newMode;
emit audioEffectsEnabledChanged();
}
bool isFullscreen() const { return m_isFullscreen; }
......@@ -147,8 +147,8 @@ public:
}
protected slots:
Q_INVOKABLE void notifyAudioEnabledChanged();
Q_INVOKABLE void notifyEffectEnabledChanged() {}
Q_INVOKABLE void notifyAudioVoicesEnabledChanged();
Q_INVOKABLE void notifyAudioEffectsEnabledChanged();
Q_INVOKABLE void notifyFullscreenChanged();
Q_INVOKABLE void notifyVirtualKeyboardChanged();
Q_INVOKABLE void notifyLocaleChanged();
......@@ -163,8 +163,8 @@ protected slots:
protected:
signals:
void audioEnabledChanged();
void effectEnabledChanged();
void audioVoicesEnabledChanged();
void audioEffectsEnabledChanged();
void fullscreenChanged();
void virtualKeyboardChanged();
void localeChanged();
......@@ -178,8 +178,8 @@ signals:
private:
static ApplicationSettings *m_instance;
bool m_isAudioEnabled;
bool m_isEffectEnabled;
bool m_isAudioVoicesEnabled;
bool m_isAudioEffectsEnabled;
bool m_isFullscreen;
bool m_isVirtualKeyboard;
bool m_isAutomaticDownloadsEnabled;
......
......@@ -97,11 +97,20 @@ Rectangle {
width: parent.width
// Put configuration here
GCDialogCheckBox {
id: enableAudioBox
text: qsTr("Enable audio")
checked: isAudioEnabled
id: enableAudioVoicesBox
text: qsTr("Enable audio voices")
checked: isAudioVoicesEnabled
onCheckedChanged: {
isAudioEnabled = checked;
isAudioVoicesEnabled = checked;
}
}
GCDialogCheckBox {
id: enableAudioEffectsBox
text: qsTr("Enable audio effects")
checked: isAudioEffectsEnabled
onCheckedChanged: {
isAudioEffectsEnabled = checked;
}
}
......@@ -367,15 +376,19 @@ Rectangle {
}
}
property bool isAudioEnabled: ApplicationSettings.isAudioEnabled
property bool isAudioVoicesEnabled: ApplicationSettings.isAudioVoicesEnabled
property bool isAudioEffectsEnabled: ApplicationSettings.isAudioEffectsEnabled
property bool isFullscreen: ApplicationSettings.isFullscreen
property bool isVirtualKeyboard: ApplicationSettings.isVirtualKeyboard
property bool isAutomaticDownloadsEnabled: ApplicationSettings.isAutomaticDownloadsEnabled
onStart: {
// Synchronize settings with data
isAudioEnabled = ApplicationSettings.isAudioEnabled
enableAudioBox.checked = isAudioEnabled
isAudioVoicesEnabled = ApplicationSettings.isAudioVoicesEnabled
enableAudioVoicesBox.checked = isAudioVoicesEnabled
isAudioEffectsEnabled = ApplicationSettings.isAudioEffectsEnabled
enableAudioEffectsBox.checked = isAudioEffectsEnabled
isFullscreen = ApplicationSettings.isFullscreen
enableFullscreenBox.checked = isFullscreen
......@@ -396,7 +409,8 @@ Rectangle {
}
function save() {
ApplicationSettings.isAudioEnabled = isAudioEnabled
ApplicationSettings.isAudioVoicesEnabled = isAudioVoicesEnabled
ApplicationSettings.isAudioEffectsEnabled = isAudioEffectsEnabled
ApplicationSettings.isFullscreen = isFullscreen