NorMIT-nav  2023.01.05-dev+develop.0da12
An IGT application
cxAudioImpl.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include "cxAudioImpl.h"
13 
14 #include <QSound>
15 #include <iostream>
16 #include "cxDataLocations.h"
17 #include <QFileInfo>
18 #include "cxTypeConversions.h"
19 #include "cxLogger.h"
20 #include "cxReporter.h"
21 
22 namespace cx
23 {
24 
25 AudioInternal::AudioInternal(QObject* parent) : QObject(parent), mLastPlayTimeMutex(QMutex::Recursive)
26 {
27  mLastPlayTime = QDateTime::fromMSecsSinceEpoch(0);
28  mMinTimeBetweenEachSound = 500;
29  connect(this, SIGNAL(playSoundInternalSignal(QString)), this, SLOT(playSoundSlot(QString)));
30 }
31 
32 void AudioInternal::playSound(QString file)
33 {
34  emit playSoundInternalSignal(file);
35 }
36 
37 bool AudioInternal::checkValidTime()
38 {
39  QDateTime now = QDateTime::currentDateTime();
40 
41  QMutexLocker sentry(&mLastPlayTimeMutex);
42  bool valid = mLastPlayTime.msecsTo(now) > mMinTimeBetweenEachSound;
43  if (!valid)
44  return false;
45  mLastPlayTime = now;
46  return true;
47 }
48 
49 void AudioInternal::playSoundSlot(QString file)
50 {
51  if (!this->checkValidTime())
52  return;
53 
54  if (!QFileInfo(file).isAbsolute())
55  file = QString("%1/%2").arg(DataLocations::findConfigFolder("/audio/")).arg(file);
56 
57  if (!QFileInfo(file).exists())
58  {
59  QString text = QString("Audio file %1 not found").arg(file);
60  reporter()->sendMessage(text, mlWARNING, 3000, true);
61  return;
62  }
63 
64  QSound::play(file);
65 }
66 
67 //---------------------------------------------------------
68 //---------------------------------------------------------
69 //---------------------------------------------------------
70 
71 
73 {
74  mInternal.reset(new AudioInternal());
75 }
76 
78 {}
79 
81 {
82  mInternal->playSound("Windows XP Hardware Insert.wav");
83 }
84 
86 {
87  mInternal->playSound("Windows XP Hardware Remove.wav");
88 }
89 
91 {
92  mInternal->playSound("Windows XP Hardware Fail.wav");
93 }
94 
96 {
97  mInternal->playSound("Windows XP Print complete.wav");
98 }
99 
101 {
102  mInternal->playSound("Windows XP Navigation.wav");
103 }
104 
106 {
107  mInternal->playSound("Windows XP Critical Stop.wav");
108 }
109 
111 {
112  mInternal->playSound("camera_shutter.wav");
113 }
114 
116 {
117  mInternal->playSound("Windows XP Information Bar.wav");
118 }
119 
120 }//namespace cx
cx::AudioInternal
Definition: cxAudioImpl.h:32
cxLogger.h
cx::AudioImpl::playErrorSound
virtual void playErrorSound()
Definition: cxAudioImpl.cpp:105
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::AudioImpl::~AudioImpl
virtual ~AudioImpl()
Definition: cxAudioImpl.cpp:77
cxAudioImpl.h
cxReporter.h
cx::reporter
ReporterPtr reporter()
Definition: cxReporter.cpp:36
cx::AudioImpl::playStartSound
virtual void playStartSound()
Definition: cxAudioImpl.cpp:80
cx::AudioImpl::playCancelSound
virtual void playCancelSound()
Definition: cxAudioImpl.cpp:90
cx::AudioInternal::playSound
void playSound(QString file)
Definition: cxAudioImpl.cpp:32
cx::AudioInternal::playSoundInternalSignal
void playSoundInternalSignal(QString file)
cxTypeConversions.h
cx::AudioImpl::AudioImpl
AudioImpl()
Definition: cxAudioImpl.cpp:72
cx::AudioImpl::playSuccessSound
virtual void playSuccessSound()
Definition: cxAudioImpl.cpp:95
cx::AudioInternal::AudioInternal
AudioInternal(QObject *parent=NULL)
Definition: cxAudioImpl.cpp:25
mlWARNING
mlWARNING
Definition: cxDefinitions.h:68
cxDataLocations.h
cx::AudioImpl::playSampleSound
virtual void playSampleSound()
Definition: cxAudioImpl.cpp:115
cx::AudioImpl::playWarningSound
virtual void playWarningSound()
Definition: cxAudioImpl.cpp:100
cx::AudioImpl::playStopSound
virtual void playStopSound()
Definition: cxAudioImpl.cpp:85
cx::AudioImpl::playScreenShotSound
virtual void playScreenShotSound()
Definition: cxAudioImpl.cpp:110
cx::DataLocations::findConfigFolder
static QString findConfigFolder(QString pathRelativeToConfigRoot, QString alternativeAbsolutePath="")
Definition: cxDataLocations.cpp:253