From cd9ded443e288b15e7609eff3cafb0f9f5461d31 Mon Sep 17 00:00:00 2001 From: Louis-Joseph Fournier Date: Tue, 5 Jan 2016 10:53:36 +0100 Subject: [PATCH] Worker: fix commands from Tuner to TunerWorker --- qml/Desktop.qml | 2 +- qml/TunerScreen.qml | 7 +++++++ src/PitchDetection.cpp | 4 ++++ src/Tuner.cpp | 20 +++++++------------- src/Tuner.hpp | 7 ------- src/TunerWorker.cpp | 8 ++++++-- src/TunerWorker.hpp | 2 +- 7 files changed, 26 insertions(+), 24 deletions(-) diff --git a/qml/Desktop.qml b/qml/Desktop.qml index 457f783..3f15519 100644 --- a/qml/Desktop.qml +++ b/qml/Desktop.qml @@ -24,7 +24,7 @@ Item { Tuner { id: tuner - running: true + running: false } DesktopTheme { diff --git a/qml/TunerScreen.qml b/qml/TunerScreen.qml index 4268205..d1f553a 100644 --- a/qml/TunerScreen.qml +++ b/qml/TunerScreen.qml @@ -149,4 +149,11 @@ Item { index: tuner.octave } } + + MouseArea { + anchors.fill: parent + onClicked: { + tuner.running = tuner.running ^ true + } + } } diff --git a/src/PitchDetection.cpp b/src/PitchDetection.cpp index ce1e5c8..3d3d643 100644 --- a/src/PitchDetection.cpp +++ b/src/PitchDetection.cpp @@ -222,6 +222,10 @@ void PitchDetection::analyse_file(const char *filename) cout << "analyse file " << filename << endl; ifstream fin; fin.open(filename); + if (!fin.is_open()) { + cerr << "file not opened" << endl; + return; + } const int nb_frame = 1024; PitchDetection *pitch = new PitchDetection(); diff --git a/src/Tuner.cpp b/src/Tuner.cpp index 64e05aa..7c29bdf 100644 --- a/src/Tuner.cpp +++ b/src/Tuner.cpp @@ -42,12 +42,6 @@ Tuner::Tuner() connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater); connect(&workerThread, &QThread::started, worker, &TunerWorker::Entry); - connect(this, &Tuner::quit, worker, &TunerWorker::Quit, Qt::DirectConnection); - connect(this, &Tuner::start, worker, &TunerWorker::Start); - connect(this, &Tuner::stop, worker, &TunerWorker::Stop); - connect(this, &Tuner::setTemperamentIndex, worker, &TunerWorker::SetTemperament); - connect(this, &Tuner::setLa, worker, &TunerWorker::SetLa); - connect(worker, &TunerWorker::resultUpdated, this, &Tuner::ResultUpdated); connect(worker, &TunerWorker::temperamentListUpdated, this, &Tuner::TemperamentListUpdated); @@ -56,9 +50,9 @@ Tuner::Tuner() Tuner::~Tuner() { - quit(); -// workerThread.quit(); - workerThread.wait(10); + worker->Quit(); + workerThread.quit(); + workerThread.wait(100); } bool Tuner::GetRunning() @@ -71,8 +65,8 @@ void Tuner::SetRunning(bool r) if (running == r) return; running = r; - if (r) emit start(); - else emit stop(); + if (r) worker->Start(); + else worker->Stop(); emit runningChanged(); } @@ -105,7 +99,7 @@ bool Tuner::GetFound() void Tuner::SetLa(double la) { this->la = la; - emit setLa(la); + worker->SetLa(la); emit laChanged(); } @@ -122,7 +116,7 @@ unsigned int Tuner::GetTemperamentIndex() void Tuner::SetTemperamentIndex(int idx) { temperament_idx = idx; - emit setTemperamentIndex(idx); + worker->SetTemperamentIndex(idx); emit temperamentChanged(); } diff --git a/src/Tuner.hpp b/src/Tuner.hpp index 1d40593..7960a86 100644 --- a/src/Tuner.hpp +++ b/src/Tuner.hpp @@ -75,13 +75,6 @@ class Tuner : public QObject { void resultChanged(); void temperamentChanged(); void temperamentListChanged(); - - // signals to worker - void quit(); - void start(); - void stop(); - void setTemperamentIndex(int idx); - void setLa(double la_freq); }; #endif diff --git a/src/TunerWorker.cpp b/src/TunerWorker.cpp index 1e1b3ab..ce3cb39 100644 --- a/src/TunerWorker.cpp +++ b/src/TunerWorker.cpp @@ -28,7 +28,7 @@ using namespace std; static void blank_prevent(bool prevent) { - cerr << __func__ << endl; + cerr << __func__ << " " << prevent << endl; QDBusConnection system = QDBusConnection::connectToBus(QDBusConnection::SystemBus, "system"); QDBusInterface interface("com.nokia.mce", "/com/nokia/mce/request", "com.nokia.mce.request", system); @@ -63,6 +63,7 @@ void TunerWorker::Start() void TunerWorker::Stop() { + cerr << __func__ << endl; mutex.lock(); running = false; mutex.unlock(); @@ -84,7 +85,7 @@ void TunerWorker::SetLa(double la) mutex.unlock(); } -void TunerWorker::SetTemperament(int idx) +void TunerWorker::SetTemperamentIndex(int idx) { mutex.lock(); temperament_to_update = idx; @@ -94,6 +95,7 @@ void TunerWorker::SetTemperament(int idx) void TunerWorker::Entry() { cerr << __func__ << endl; + pitchDetection = new PitchDetection(); emit temperamentListUpdated(pitchDetection->GetTemperamentList()); @@ -124,6 +126,8 @@ void TunerWorker::Entry() std::cout << __func__ << " do job" << std::endl; } + + cerr << __func__ << " quit" << endl; /* // prevent screen blanking if (nb_sample_running >= nbSamplePreventRunning && running) { diff --git a/src/TunerWorker.hpp b/src/TunerWorker.hpp index b6acfc1..3cfe150 100644 --- a/src/TunerWorker.hpp +++ b/src/TunerWorker.hpp @@ -55,7 +55,7 @@ class TunerWorker : public QObject { public slots: void Start(); void Stop(); - void SetTemperament(int idx); + void SetTemperamentIndex(int idx); void SetLa(double la); void Entry(); void Quit();