CustusX  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
virtual void playCancelSound()
Definition: cxAudioImpl.cpp:90
void playSound(QString file)
Definition: cxAudioImpl.cpp:32
ReporterPtr reporter()
Definition: cxReporter.cpp:36
virtual ~AudioImpl()
Definition: cxAudioImpl.cpp:77
virtual void playScreenShotSound()
AudioInternal(QObject *parent=NULL)
Definition: cxAudioImpl.cpp:25
virtual void playStopSound()
Definition: cxAudioImpl.cpp:85
virtual void playSuccessSound()
Definition: cxAudioImpl.cpp:95
static QString findConfigFolder(QString pathRelativeToConfigRoot, QString alternativeAbsolutePath="")
virtual void playSampleSound()
void playSoundInternalSignal(QString file)
virtual void playWarningSound()
mlWARNING
Definition: cxDefinitions.h:67
virtual void playStartSound()
Definition: cxAudioImpl.cpp:80
virtual void playErrorSound()
Namespace for all CustusX production code.