ObjectSave works on Sailfish

This commit is contained in:
Louis-Joseph Fournier 2016-01-10 12:06:03 +01:00
parent 77bad4b541
commit 095ace53e0
3 changed files with 9 additions and 174 deletions

View file

@ -33,6 +33,7 @@ Item {
}
ObjectSaver {
id: saver
filename: "config.dat"
object: Config
}

168
src/'
View file

@ -1,168 +0,0 @@
/* 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 <fstream>
#include "TunerWorker.hpp"
using namespace std;
/// file name to record audio
const char * TunerWorker::filename_record = NULL;
/// function to prevent screen blank on Sailfish OS
static void blank_prevent(bool prevent)
{
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);
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),
temperament_to_update(-1)
{
}
TunerWorker::~TunerWorker()
{
}
void TunerWorker::Start()
{
cerr << __func__ << endl;
mutex.lock();
running = true;
condition.wakeOne();
mutex.unlock();
}
void TunerWorker::Stop()
{
cerr << __func__ << endl;
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();
}
void TunerWorker::SetTemperamentIndex(int idx)
{
mutex.lock();
temperament_to_update = idx;
mutex.unlock();
}
void TunerWorker::Entry()
{
cerr << __func__ << endl;
int nbSamplePreventRunning = nbSecPreventRunning * PitchDetection::rate;
int nb_sample_running = 0;
ofstream *file = NULL;
if (filename_record) file = new ofstream(filename_record);
PitchDetection *pitchDetection = new PitchDetection();
emit temperamentListUpdated(pitchDetection->GetTemperamentList());
while (1) {
// wait for running
mutex.lock();
if (!running) {
blank_prevent(false);
while (!running && !quit) condition.wait(&mutex);
cerr << "wake-up" << endl;
// reset operations on start
if (!quit) {
pitchDetection->Reset();
nb_sample_running = 0;
}
}
if (quit) {
mutex.unlock();
break;
}
// update config
if (la_to_update) {
pitchDetection->SetLa(la_to_update);
la_to_update = 0;
}
if (temperament_to_update != -1) {
pitchDetection->SetTemperament(temperament_to_update);
temperament_to_update = -1;
}
mutex.unlock();
// record in file is needed
//if (file) file_record.write((char*) ptr, nb_frame * sizeof(int16_t));
std::cout << __func__ << " do job" << std::endl;
}
delete pitchDetection;
if (file) {
file->close();
delete file;
}
cerr << __func__ << " quit" << endl;
/*
// prevent screen blanking
if (nb_sample_running >= nbSamplePreventRunning && running) {
nb_sample_running = 0;
blank_prevent(true);
}*/
}
/// Set a filename to record raw audio stream
void TunerWorker::set_record(const char *f)
{
filename_record = f;
}

View file

@ -121,18 +121,20 @@ void ObjectSaver::load()
// load object from file
QMetaProperty property;
const QMetaObject *meta = object->metaObject();
QString title, value;
const char *t;
QByteArray title;
QString value;
int offset;
char c;
bool ok;
while (!file->atEnd()) {
title = file->readLine(100).trimmed();
t = title.toStdString().c_str();
offset = meta->indexOfProperty(t);
offset = meta->indexOfProperty(title.constData());
if (offset != -1 && !file->atEnd() && type_ok(meta->property(offset).type())) {
value = file->readLine(100).trimmed();
if (!object->setProperty(t, value /*value.toInt(&ok, 10)*/)) {
ok = object->setProperty(title.constData(), value);
if (!ok) {
qDebug() << __func__ << " set property " << title << " to " << value << " failed";
}
else {