2016-01-05 02:17:20 +03:00
|
|
|
/* Copyright 2016 (C) Louis-Joseph Fournier
|
|
|
|
* louisjoseph.fournier@gmail.com
|
|
|
|
*
|
|
|
|
* This file is part of SailTuner.
|
|
|
|
*
|
|
|
|
* SailTuner is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* SailTuner is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QDBusConnection>
|
|
|
|
#include <QDBusInterface>
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include "TunerWorker.hpp"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
/// function to prevent screen blank on Sailfish OS
|
|
|
|
|
|
|
|
static void blank_prevent(bool prevent)
|
|
|
|
{
|
|
|
|
cerr << __func__ << endl;
|
|
|
|
QDBusConnection system = QDBusConnection::connectToBus(QDBusConnection::SystemBus, "system");
|
|
|
|
QDBusInterface interface("com.nokia.mce", "/com/nokia/mce/request", "com.nokia.mce.request", system);
|
|
|
|
|
|
|
|
if (prevent) {
|
|
|
|
interface.call(QLatin1String("req_display_blanking_pause"));
|
|
|
|
} else {
|
|
|
|
interface.call(QLatin1String("req_display_cancel_blanking_pause"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TunerWorker::TunerWorker() :
|
|
|
|
running(false),
|
|
|
|
quit(false),
|
|
|
|
la_to_update(0),
|
2016-01-05 12:34:22 +03:00
|
|
|
temperament_to_update(-1)
|
2016-01-05 02:17:20 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
TunerWorker::~TunerWorker()
|
|
|
|
{
|
2016-01-05 12:34:22 +03:00
|
|
|
if (pitchDetection) delete pitchDetection;
|
2016-01-05 02:17:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void TunerWorker::Start()
|
|
|
|
{
|
|
|
|
cerr << __func__ << endl;
|
|
|
|
mutex.lock();
|
|
|
|
running = true;
|
|
|
|
condition.wakeOne();
|
|
|
|
mutex.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TunerWorker::Stop()
|
|
|
|
{
|
|
|
|
mutex.lock();
|
|
|
|
running = false;
|
|
|
|
mutex.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TunerWorker::Quit()
|
|
|
|
{
|
|
|
|
mutex.lock();
|
|
|
|
running = false;
|
|
|
|
quit = true;
|
|
|
|
condition.wakeOne();
|
|
|
|
mutex.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TunerWorker::SetLa(double la)
|
|
|
|
{
|
|
|
|
mutex.lock();
|
|
|
|
la_to_update = la;
|
|
|
|
mutex.unlock();
|
|
|
|
}
|
|
|
|
|
2016-01-05 12:34:22 +03:00
|
|
|
void TunerWorker::SetTemperament(int idx)
|
2016-01-05 02:17:20 +03:00
|
|
|
{
|
2016-01-05 12:34:22 +03:00
|
|
|
mutex.lock();
|
|
|
|
temperament_to_update = idx;
|
|
|
|
mutex.unlock();
|
2016-01-05 02:17:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void TunerWorker::Entry()
|
|
|
|
{
|
2016-01-05 12:34:22 +03:00
|
|
|
cerr << __func__ << endl;
|
|
|
|
pitchDetection = new PitchDetection();
|
|
|
|
emit temperamentListUpdated(pitchDetection->GetTemperamentList());
|
2016-01-05 02:17:20 +03:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
// wait for running
|
|
|
|
mutex.lock();
|
|
|
|
if (!running) {
|
|
|
|
blank_prevent(false);
|
|
|
|
while (!running && !quit) condition.wait(&mutex);
|
2016-01-05 12:34:22 +03:00
|
|
|
cerr << "wake-up" << endl;
|
2016-01-05 02:17:20 +03:00
|
|
|
// reset operations on start
|
2016-01-05 12:34:22 +03:00
|
|
|
if (!quit) pitchDetection->Reset();
|
2016-01-05 02:17:20 +03:00
|
|
|
}
|
|
|
|
if (quit) {
|
|
|
|
mutex.unlock();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// update config
|
|
|
|
if (la_to_update) {
|
2016-01-05 12:34:22 +03:00
|
|
|
pitchDetection->SetLa(la_to_update);
|
2016-01-05 02:17:20 +03:00
|
|
|
la_to_update = 0;
|
|
|
|
}
|
2016-01-05 12:34:22 +03:00
|
|
|
if (temperament_to_update != -1) {
|
|
|
|
pitchDetection->SetTemperament(temperament_to_update);
|
|
|
|
temperament_to_update = -1;
|
2016-01-05 02:17:20 +03:00
|
|
|
}
|
|
|
|
mutex.unlock();
|
|
|
|
|
|
|
|
std::cout << __func__ << " do job" << std::endl;
|
|
|
|
}
|
2016-01-05 12:34:22 +03:00
|
|
|
/*
|
|
|
|
// prevent screen blanking
|
|
|
|
if (nb_sample_running >= nbSamplePreventRunning && running) {
|
|
|
|
nb_sample_running = 0;
|
|
|
|
blank_prevent(true);
|
|
|
|
}*/
|
2016-01-05 02:17:20 +03:00
|
|
|
}
|
|
|
|
|