diff --git a/qml/Desktop.qml b/qml/Desktop.qml index 942c1d8..65894e2 100644 --- a/qml/Desktop.qml +++ b/qml/Desktop.qml @@ -33,6 +33,7 @@ Item { } ObjectSaver { + id: saver filename: "config.dat" object: Config } diff --git a/src/' b/src/' deleted file mode 100644 index 0abbd7e..0000000 --- a/src/' +++ /dev/null @@ -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 -#include - -#include -#include - -#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; -} - diff --git a/src/ObjectSaver.cpp b/src/ObjectSaver.cpp index 3181f10..1c2ac93 100644 --- a/src/ObjectSaver.cpp +++ b/src/ObjectSaver.cpp @@ -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 {