summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Klotz <uwe_klotz@web.de>2017-06-07 19:28:14 +0200
committerUwe Klotz <uwe_klotz@web.de>2017-06-12 07:30:17 +0200
commit2004ad04cd379a0fd869415ab08385db698dafc4 (patch)
treebe4c93e1fabae46b7061306fcab48caa8d4d0b65
parent8aca1407a5f934061da44dfd5b49c4ecd3c08e73 (diff)
Use a managed database connection(s) for waveform analyzer(s)
-rw-r--r--src/analyzer/analyzerwaveform.cpp68
-rw-r--r--src/analyzer/analyzerwaveform.h13
2 files changed, 36 insertions, 45 deletions
diff --git a/src/analyzer/analyzerwaveform.cpp b/src/analyzer/analyzerwaveform.cpp
index 9fa7de5fe9..872a53b502 100644
--- a/src/analyzer/analyzerwaveform.cpp
+++ b/src/analyzer/analyzerwaveform.cpp
@@ -1,58 +1,50 @@
#include "analyzer/analyzerwaveform.h"
-#include <QtDebug>
-
#include "engine/engineobject.h"
#include "engine/enginefilterbutterworth8.h"
#include "engine/enginefilterbessel4.h"
#include "library/trackcollection.h"
-#include "library/dao/analysisdao.h"
#include "track/track.h"
#include "waveform/waveformfactory.h"
+#include "util/logger.h"
+
+namespace {
+
+mixxx::Logger kLogger("AnalyzerWaveform");
-namespace
-{
- QAtomicInt dbIndex(0);
+QAtomicInt dbIndex(0);
+
+QString nextDatabaseConnectioName() {
+ const int idx = ::dbIndex.fetchAndAddAcquire(1);
+ return QString("WAVEFORM_ANALYSIS-%1").arg(QString::number(idx));
}
+} // anonymous
+
AnalyzerWaveform::AnalyzerWaveform(UserSettingsPointer pConfig) :
m_skipProcessing(false),
m_waveformData(nullptr),
m_waveformSummaryData(nullptr),
m_stride(0, 0),
m_currentStride(0),
- m_currentSummaryStride(0) {
- const int idx = ::dbIndex.fetchAndAddAcquire(1);
- qDebug() << "AnalyzerWaveform::AnalyzerWaveform() :" << idx;
-
+ m_currentSummaryStride(0),
+ m_repository(pConfig, nextDatabaseConnectioName()),
+ m_analysisDao(pConfig) {
m_filter[0] = 0;
m_filter[1] = 0;
m_filter[2] = 0;
- //A new connection different for each thread is needed http://doc.qt.io/qt-4.8/threads-modules.html#threads-and-the-sql-module
- m_database = QSqlDatabase::addDatabase("QSQLITE", "WAVEFORM_ANALYSIS" + QString::number(idx));
- if (!m_database.isOpen()) {
- m_database.setHostName("localhost");
- m_database.setDatabaseName(QDir(pConfig->getSettingsPath()).filePath("mixxxdb.sqlite"));
- m_database.setUserName("mixxx");
- m_database.setPassword("mixxx");
-
- //Open the database connection in this thread.
- if (!m_database.open()) {
- qDebug() << "Failed to open database from analyzer thread."
- << m_database.lastError();
- }
+ if (!m_repository.openDatabaseConnection()) {
+ kLogger.warning()
+ << "Failed to open database connection for waveform analyzer";
+ return;
}
-
- m_pAnalysisDao = std::make_unique<AnalysisDao>(pConfig);
- m_pAnalysisDao->initialize(m_database);
+ m_analysisDao.initialize(m_repository.database());
}
AnalyzerWaveform::~AnalyzerWaveform() {
- QString conname = m_database.connectionName();
- qDebug() << "AnalyzerWaveform::~AnalyzerWaveform():" << conname;
+ kLogger.debug() << "~AnalyzerWaveform():";
destroyFilters();
- m_database.close();
- QSqlDatabase::removeDatabase(conname);
+ m_repository.closeDatabaseConnection();
}
bool AnalyzerWaveform::initialize(TrackPointer tio, int sampleRate, int totalSamples) {
@@ -123,7 +115,7 @@ bool AnalyzerWaveform::isDisabledOrLoadStoredSuccess(TrackPointer tio) const {
if (trackId.isValid() && (missingWaveform || missingWavesummary)) {
QList<AnalysisDao::AnalysisInfo> analyses =
- m_pAnalysisDao->getAnalysesForTrack(trackId);
+ m_analysisDao.getAnalysesForTrack(trackId);
QListIterator<AnalysisDao::AnalysisInfo> it(analyses);
while (it.hasNext()) {
@@ -138,7 +130,7 @@ bool AnalyzerWaveform::isDisabledOrLoadStoredSuccess(TrackPointer tio) const {
missingWaveform = false;
} else if (vc != WaveformFactory::VC_KEEP) {
// remove all other Analysis except that one we should keep
- m_pAnalysisDao->deleteAnalysis(analysis.analysisId);
+ m_analysisDao.deleteAnalysis(analysis.analysisId);
}
} if (analysis.type == AnalysisDao::TYPE_WAVESUMMARY) {
vc = WaveformFactory::waveformSummaryVersionToVersionClass(analysis.version);
@@ -148,7 +140,7 @@ bool AnalyzerWaveform::isDisabledOrLoadStoredSuccess(TrackPointer tio) const {
missingWavesummary = false;
} else if (vc != WaveformFactory::VC_KEEP) {
// remove all other Analysis except that one we should keep
- m_pAnalysisDao->deleteAnalysis(analysis.analysisId);
+ m_analysisDao.deleteAnalysis(analysis.analysisId);
}
}
}
@@ -156,7 +148,7 @@ bool AnalyzerWaveform::isDisabledOrLoadStoredSuccess(TrackPointer tio) const {
// If we don't need to calculate the waveform/wavesummary, skip.
if (!missingWaveform && !missingWavesummary) {
- qDebug() << "AnalyzerWaveform::loadStored - Stored waveform loaded";
+ kLogger.debug() << "loadStored - Stored waveform loaded";
if (pLoadedTrackWaveform) {
tio->setWaveform(pLoadedTrackWaveform);
}
@@ -270,8 +262,8 @@ void AnalyzerWaveform::process(const CSAMPLE* buffer, const int bufferLength) {
}
}
- //qDebug() << "AnalyzerWaveform::process - m_waveform->getCompletion()" << m_waveform->getCompletion() << "off" << m_waveform->getDataSize();
- //qDebug() << "AnalyzerWaveform::process - m_waveformSummary->getCompletion()" << m_waveformSummary->getCompletion() << "off" << m_waveformSummary->getDataSize();
+ //kLogger.debug() << "process - m_waveform->getCompletion()" << m_waveform->getCompletion() << "off" << m_waveform->getDataSize();
+ //kLogger.debug() << "process - m_waveformSummary->getCompletion()" << m_waveformSummary->getCompletion() << "off" << m_waveformSummary->getDataSize();
}
void AnalyzerWaveform::cleanup(TrackPointer tio) {
@@ -330,9 +322,9 @@ void AnalyzerWaveform::finalize(TrackPointer tio) {
// waveforms (i.e. if the config setting was disabled in a previous scan)
// and then it is not called. The other analyzers have signals which control
// the update of their data.
- m_pAnalysisDao->saveTrackAnalyses(*tio);
+ m_analysisDao.saveTrackAnalyses(*tio);
- qDebug() << "Waveform generation for track" << tio->getId() << "done"
+ kLogger.debug() << "Waveform generation for track" << tio->getId() << "done"
<< m_timer.elapsed().debugSecondsWithUnit();
}
diff --git a/src/analyzer/analyzerwaveform.h b/src/analyzer/analyzerwaveform.h
index 912436c329..2314ab28f4 100644
--- a/src/analyzer/analyzerwaveform.h
+++ b/src/analyzer/analyzerwaveform.h
@@ -2,23 +2,22 @@
#define ANALYZER_ANALYZERWAVEFORM_H
#include <QImage>
-#include <QSqlDatabase>
#include <limits>
#include "analyzer/analyzer.h"
#include "preferences/usersettings.h"
#include "util/math.h"
-#include "util/memory.h"
#include "waveform/waveform.h"
#include "util/performancetimer.h"
+#include "library/dao/analysisdao.h"
+#include "repository/repository.h"
//NOTS vrince some test to segment sound, to apply color in the waveform
//#define TEST_HEAT_MAP
class EngineFilterIIRBase;
class Waveform;
-class AnalysisDao;
inline CSAMPLE scaleSignal(CSAMPLE invalue, FilterIndex index = FilterCount) {
if (invalue == 0.0) {
@@ -140,8 +139,8 @@ struct WaveformStride {
class AnalyzerWaveform : public Analyzer {
public:
- AnalyzerWaveform(UserSettingsPointer pConfig);
- virtual ~AnalyzerWaveform();
+ explicit AnalyzerWaveform(UserSettingsPointer pConfig);
+ ~AnalyzerWaveform() override;
bool initialize(TrackPointer tio, int sampleRate, int totalSamples) override;
bool isDisabledOrLoadStoredSuccess(TrackPointer tio) const override;
@@ -173,8 +172,8 @@ class AnalyzerWaveform : public Analyzer {
std::vector<float> m_buffers[FilterCount];
PerformanceTimer m_timer;
- QSqlDatabase m_database;
- std::unique_ptr<AnalysisDao> m_pAnalysisDao;
+ mixxx::Repository m_repository;
+ mutable AnalysisDao m_analysisDao;
#ifdef TEST_HEAT_MAP
QImage* test_heatMap;