/*!
* This file is part of CameraPlus.
*
- * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
+ * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
#include <QWaitCondition>
#include <QDBusServiceWatcher>
#include <QDBusConnection>
+#if defined(QT4)
+#include <QDeclarativeInfo>
+#elif defined(QT5)
+#include <QQmlInfo>
+#endif
#define CAMERA_IMAGE_START_SOUND_ID "camera-image-start"
#define CAMERA_IMAGE_END_SOUND_ID "camera-image-end"
#define CAMERA_FOCUS_SOUND_ID "camera-focus"
// Odd, volume has to be a char *
-#define CANBERRA_FULL_VOLUME "0.0"
-
-// TODO: if we are using headphones then sound volume might be loud. Detect and lower it.
+#define CANBERRA_FULL_VOLUME "0.0"
+#define CANBERRA_HEADSET_VOLUME "-24.0"
Sounds::Sounds(QObject *parent) :
QObject(parent),
m_muted(false),
m_ctx(0),
- m_conf(0),
+ m_volume(Sounds::VolumeHigh),
m_watcher(new QDBusServiceWatcher("org.pulseaudio.Server",
QDBusConnection::systemBus(),
QDBusServiceWatcher::WatchForOwnerChange)) {
}
}
-void Sounds::setConfig(QtCamConfig *conf) {
- m_conf = conf;
-}
-
void Sounds::serviceOwnerChanged(const QString& serviceName, const QString& oldOwner,
const QString& newOwner) {
Q_UNUSED(serviceName);
}
}
-void Sounds::imageCaptureStarted() {
+void Sounds::playImageCaptureStartedSound() {
if (isMuted() || !m_ctx) {
return;
}
play(CAMERA_IMAGE_START_SOUND_ID);
}
-void Sounds::imageCaptureEnded() {
+void Sounds::playImageCaptureEndedSound() {
if (isMuted() || !m_ctx) {
return;
}
play(CAMERA_IMAGE_END_SOUND_ID);
}
-void Sounds::videoRecordingStarted() {
+void Sounds::playVideoRecordingStartedSound() {
if (isMuted() || !m_ctx) {
return;
}
playAndBlock(CAMERA_VIDEO_START_SOUND_ID);
}
-void Sounds::videoRecordingEnded() {
+void Sounds::playVideoRecordingEndedSound() {
if (isMuted() || !m_ctx) {
return;
}
play(CAMERA_VIDEO_STOP_SOUND_ID);
}
-void Sounds::autoFocusAcquired() {
+void Sounds::playAutoFocusAcquiredSound() {
if (isMuted() || !m_ctx) {
return;
}
return;
}
- cache(m_conf->imageCaptureStartedSound(), CAMERA_IMAGE_START_SOUND_ID);
- cache(m_conf->imageCaptureEndedSound(), CAMERA_IMAGE_END_SOUND_ID);
- cache(m_conf->videoRecordingStartedSound(), CAMERA_VIDEO_START_SOUND_ID);
- cache(m_conf->videoRecordingEndedSound(), CAMERA_VIDEO_STOP_SOUND_ID);
- cache(m_conf->autoFocusAcquiredSound(), CAMERA_FOCUS_SOUND_ID);
+ cache(m_imageCaptureStart, CAMERA_IMAGE_START_SOUND_ID);
+ cache(m_imageCaptureEnd, CAMERA_IMAGE_END_SOUND_ID);
+ cache(m_videoRecordingStart, CAMERA_VIDEO_START_SOUND_ID);
+ cache(m_videoRecordingEnd, CAMERA_VIDEO_STOP_SOUND_ID);
+ cache(m_autoFocusAcquired, CAMERA_FOCUS_SOUND_ID);
}
void Sounds::cache(const QString& path, const char *id) {
return;
}
+ const char *volume = m_volume == Sounds::VolumeLow ?
+ CANBERRA_HEADSET_VOLUME : CANBERRA_FULL_VOLUME;
+
int code = ca_context_play(m_ctx, 0,
- CA_PROP_CANBERRA_VOLUME, CANBERRA_FULL_VOLUME,
+ CA_PROP_CANBERRA_VOLUME, volume,
CA_PROP_EVENT_ID, id,
CA_PROP_MEDIA_ROLE, "camera-sound-effect",
NULL);
if (code != CA_SUCCESS) {
- qDebug() << "Failed to play sound" << ca_strerror(code) << code;
+ qmlInfo(this) << "Failed to play sound" << ca_strerror(code) << code;
}
}
ca_proplist_destroy(p);
mutex.unlock();
}
+
+QString Sounds::imageCaptureStart() const {
+ return m_imageCaptureStart;
+}
+
+void Sounds::setImageCaptureStart(const QString& path) {
+ if (path != m_imageCaptureStart) {
+ m_imageCaptureStart = path;
+ cache(m_imageCaptureStart, CAMERA_IMAGE_START_SOUND_ID);
+ emit imageCaptureStartChanged();
+ }
+}
+
+QString Sounds::imageCaptureEnd() const {
+ return m_imageCaptureEnd;
+}
+
+void Sounds::setImageCaptureEnd(const QString& path) {
+ if (path != m_imageCaptureEnd) {
+ m_imageCaptureEnd = path;
+ cache(m_imageCaptureEnd, CAMERA_IMAGE_END_SOUND_ID);
+ emit imageCaptureEndChanged();
+ }
+}
+
+QString Sounds::videoRecordingStart() const {
+ return m_videoRecordingStart;
+}
+
+void Sounds::setVideoRecordingStart(const QString& path) {
+ if (path != m_videoRecordingStart) {
+ m_videoRecordingStart = path;
+ cache(m_videoRecordingStart, CAMERA_VIDEO_START_SOUND_ID);
+ emit videoRecordingStartChanged();
+ }
+}
+
+QString Sounds::videoRecordingEnd() const {
+ return m_videoRecordingEnd;
+}
+
+void Sounds::setVideoRecordingEnd(const QString& path) {
+ if (path != m_videoRecordingEnd) {
+ m_videoRecordingEnd = path;
+ cache(m_videoRecordingEnd, CAMERA_VIDEO_STOP_SOUND_ID);
+ emit videoRecordingEndChanged();
+ }
+}
+
+QString Sounds::autoFocusAcquired() const {
+ return m_autoFocusAcquired;
+}
+
+void Sounds::setAutoFocusAcquired(const QString& path) {
+ if (path != m_autoFocusAcquired) {
+ m_autoFocusAcquired = path;
+ cache(m_autoFocusAcquired, CAMERA_FOCUS_SOUND_ID);
+ emit autoFocusAcquiredChanged();
+ }
+}
+
+Sounds::Volume Sounds::volume() const {
+ return m_volume;
+}
+
+void Sounds::setVolume(const Sounds::Volume& volume) {
+ if (m_volume != volume) {
+ m_volume = volume;
+ emit volumeChanged();
+ }
+}