Entropy Piano Tuner  1.1.3 (documentation not yet complete)
An open-source experimental software for piano tuning by entropy minimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
audioplayerforqt.cpp
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright 2015 Haye Hinrichsen, Christoph Wick
3  *
4  * This file is part of Entropy Piano Tuner.
5  *
6  * Entropy Piano Tuner is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * Entropy Piano Tuner is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * Entropy Piano Tuner. If not, see http://www.gnu.org/licenses/.
18  *****************************************************************************/
19 
20 #include "audioplayerforqt.h"
21 #include "audioplayerthreadforqt.h"
22 
23 #include "../core/system/log.h"
24 #include "settingsforqt.h"
25 
26 //-----------------------------------------------------------------------------
27 // Constructor
28 //-----------------------------------------------------------------------------
29 
34 
36  QObject(parent),
37  mQtThread(nullptr),
38  mQtAudioManager(nullptr)
39 {
40  setDeviceName(SettingsForQt::getSingleton().getOuputDeviceName().toStdString());
41  setSamplingRate(SettingsForQt::getSingleton().getOutputDeviceSamplingRate());
42 }
43 
44 
45 //-----------------------------------------------------------------------------
46 // Initialize the Qt-Player thread
47 //-----------------------------------------------------------------------------
48 
55 
57 {
58  mQtThread = new QThread;
60  mQtAudioManager->moveToThread(mQtThread);
61  connect(mQtAudioManager, SIGNAL(error(QString)), this, SLOT(errorString(QString)));
62  connect(mQtThread, SIGNAL(started()), mQtAudioManager, SLOT(workerFunction()));
63  connect(mQtAudioManager, SIGNAL(finished()), mQtThread, SLOT(quit()));
64  connect(mQtAudioManager, SIGNAL(finished()), mQtAudioManager, SLOT(deleteLater()));
65  connect(mQtThread, SIGNAL(finished()), mQtThread, SLOT(deleteLater()));
66 
67  mQtThread->start(QThread::HighPriority);
68 }
69 
70 
71 //-----------------------------------------------------------------------------
72 // Exit from the Qt-Player thread
73 //-----------------------------------------------------------------------------
74 
81 
83 {
85  while (mQtAudioManager->isRunning())
86  std::this_thread::sleep_for(std::chrono::milliseconds(10));
87 
88  // deleted automatically upon finished
89  mQtAudioManager = nullptr;
90  mQtThread = nullptr;
91 
93 }
94 
95 
97 {
98  if (!mQtAudioManager) {return;}
99 
100  mQtAudioManager->setPause(false);
101 }
102 
104 {
105  if (!mQtAudioManager) {return;}
106 
107  mQtAudioManager->setPause(true);
108 }
109 
111 {
112  LogE("Error in QtAudioManager: %s", s.toStdString().c_str());
113 }
114 
AudioPlayerForQt(QObject *parent)
Constructor, starting a Qt-thread.
void errorString(QString)
Class for the audio player thread.
void start() overridefinal
Start/restart the audio device.
void exit() overridefinal
Exit from the AudioPlayerForQt.
void init() overridefinal
Initialize the AudioPlayerForQt.
virtual void exit() override
Destroy the audio device.
void stop() overridefinal
Stop the audio device.
void setDeviceName(const std::string &n)
Set the device name.
Definition: audiobase.cpp:65
#define LogE(...)
Definition: log.h:62
AudioPlayerThreadForQt * mQtAudioManager
virtual void setSamplingRate(int rate)
Allow the implementation to change the sampling rate during operation.
Definition: audiobase.cpp:96
static SettingsForQt & getSingleton()
Getter function for the singleton.
void setPause(bool pause)
Pause the audio player.