ObjectSaver implementation (begin) and integration
This commit is contained in:
parent
30c93c96a7
commit
0cbf96b221
12 changed files with 216 additions and 1 deletions
|
@ -9,6 +9,7 @@ PKGCONFIG += libpulse-simple
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
src/desktop.cpp \
|
src/desktop.cpp \
|
||||||
|
src/ObjectSaver.cpp \
|
||||||
src/PitchDetection.cpp \
|
src/PitchDetection.cpp \
|
||||||
src/Tuner.cpp \
|
src/Tuner.cpp \
|
||||||
src/TunerWorker.cpp \
|
src/TunerWorker.cpp \
|
||||||
|
@ -19,6 +20,7 @@ SOURCES += \
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
src/PitchDetection.hpp \
|
src/PitchDetection.hpp \
|
||||||
|
src/ObjectSaver.hpp \
|
||||||
src/Tuner.hpp \
|
src/Tuner.hpp \
|
||||||
src/TunerWorker.hpp \
|
src/TunerWorker.hpp \
|
||||||
src/audio/LinearFilter.hpp \
|
src/audio/LinearFilter.hpp \
|
||||||
|
|
|
@ -14,6 +14,7 @@ RESOURCES += \
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
src/sailfish.cpp \
|
src/sailfish.cpp \
|
||||||
src/PitchDetection.cpp \
|
src/PitchDetection.cpp \
|
||||||
|
src/ObjectSaver.cpp \
|
||||||
src/Tuner.cpp \
|
src/Tuner.cpp \
|
||||||
src/TunerWorker.cpp \
|
src/TunerWorker.cpp \
|
||||||
src/audio/LinearFilter.cpp \
|
src/audio/LinearFilter.cpp \
|
||||||
|
@ -23,6 +24,7 @@ SOURCES += \
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
src/PitchDetection.hpp \
|
src/PitchDetection.hpp \
|
||||||
|
src/ObjectSaver.hpp \
|
||||||
src/Tuner.cpp \
|
src/Tuner.cpp \
|
||||||
src/Tuner.hpp \
|
src/Tuner.hpp \
|
||||||
src/TunerWorker.hpp \
|
src/TunerWorker.hpp \
|
||||||
|
|
9
qml/Config.qml
Normal file
9
qml/Config.qml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
import QtQuick 2.0
|
||||||
|
|
||||||
|
pragma Singleton
|
||||||
|
|
||||||
|
QtObject {
|
||||||
|
property double la: 441
|
||||||
|
property int temperament_idx: 1
|
||||||
|
property int notes_style: 0
|
||||||
|
}
|
|
@ -17,6 +17,9 @@
|
||||||
|
|
||||||
import QtQuick 2.0
|
import QtQuick 2.0
|
||||||
import LJTuner 1.0
|
import LJTuner 1.0
|
||||||
|
import LJUtils 1.0
|
||||||
|
|
||||||
|
import "."
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
width: 600
|
width: 600
|
||||||
|
@ -25,6 +28,13 @@ Item {
|
||||||
Tuner {
|
Tuner {
|
||||||
id: tuner
|
id: tuner
|
||||||
running: false
|
running: false
|
||||||
|
temperament_idx: Config.temperament_idx
|
||||||
|
la: Config.la
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjectSaver {
|
||||||
|
filename: "config.dat"
|
||||||
|
object: Config
|
||||||
}
|
}
|
||||||
|
|
||||||
DesktopTheme {
|
DesktopTheme {
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
import QtQuick 2.0
|
import QtQuick 2.0
|
||||||
import Sailfish.Silica 1.0
|
import Sailfish.Silica 1.0
|
||||||
import harbour.sailtuner.tuner 1.0
|
import harbour.sailtuner.tuner 1.0
|
||||||
|
import harbour.sailtuner.objectsaver 1.0
|
||||||
|
import "."
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sailfish main page
|
* Sailfish main page
|
||||||
|
@ -32,6 +34,11 @@ ApplicationWindow {
|
||||||
property int dbFontSize: 100
|
property int dbFontSize: 100
|
||||||
property QtObject tuner
|
property QtObject tuner
|
||||||
|
|
||||||
|
ObjectSaver {
|
||||||
|
filename: "config.dat"
|
||||||
|
object: Config
|
||||||
|
}
|
||||||
|
|
||||||
initialPage: Component {
|
initialPage: Component {
|
||||||
Page {
|
Page {
|
||||||
id: page
|
id: page
|
||||||
|
@ -52,6 +59,8 @@ ApplicationWindow {
|
||||||
Tuner {
|
Tuner {
|
||||||
id: tunerObject
|
id: tunerObject
|
||||||
running: Qt.application.active && app.userRunning
|
running: Qt.application.active && app.userRunning
|
||||||
|
temperament_idx: Config.temperament_idx
|
||||||
|
la: Config.la
|
||||||
}
|
}
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import QtQuick 2.0
|
import QtQuick 2.0
|
||||||
|
import "."
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ScaleToise
|
* ScaleToise
|
||||||
|
@ -31,7 +32,7 @@ Toise {
|
||||||
// octave
|
// octave
|
||||||
property int octave: 4
|
property int octave: 4
|
||||||
// en or fr
|
// en or fr
|
||||||
property int notes_style: 1
|
property int notes_style: Config.notes_style
|
||||||
|
|
||||||
property variant notes_fr: [
|
property variant notes_fr: [
|
||||||
"do", "do#", "ré", "mib", "mi", "fa", "fa#", "sol", "sol#", "la", "sib", "si"]
|
"do", "do#", "ré", "mib", "mi", "fa", "fa#", "sol", "sol#", "la", "sib", "si"]
|
||||||
|
|
|
@ -8,5 +8,7 @@
|
||||||
<file>ScaleToise.qml</file>
|
<file>ScaleToise.qml</file>
|
||||||
<file>Toise.qml</file>
|
<file>Toise.qml</file>
|
||||||
<file>Led.qml</file>
|
<file>Led.qml</file>
|
||||||
|
<file>Config.qml</file>
|
||||||
|
<file>qmldir</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
1
qml/qmldir
Normal file
1
qml/qmldir
Normal file
|
@ -0,0 +1 @@
|
||||||
|
singleton Config Config.qml
|
112
src/ObjectSaver.cpp
Normal file
112
src/ObjectSaver.cpp
Normal file
|
@ -0,0 +1,112 @@
|
||||||
|
/* 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 <QDebug>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QStandardPaths>
|
||||||
|
|
||||||
|
#include "ObjectSaver.hpp"
|
||||||
|
|
||||||
|
#define name_(x) #x
|
||||||
|
#define name(x) name_(x)
|
||||||
|
#define NAME name(TARGET)
|
||||||
|
|
||||||
|
ObjectSaver::ObjectSaver() :
|
||||||
|
object(NULL)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjectSaver::~ObjectSaver()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ObjectSaver::getFilename()
|
||||||
|
{
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjectSaver::setFilename(QString name)
|
||||||
|
{
|
||||||
|
filename = name;
|
||||||
|
if (object && filename != "") load();
|
||||||
|
}
|
||||||
|
|
||||||
|
QObject * ObjectSaver::getObject()
|
||||||
|
{
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjectSaver::setObject(QObject *obj)
|
||||||
|
{
|
||||||
|
object = obj;
|
||||||
|
if (filename != "") load();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the data file object opened, or NULL
|
||||||
|
QFile * ObjectSaver::getDataFile(bool is_write)
|
||||||
|
{
|
||||||
|
if (filename == "") {
|
||||||
|
qDebug() << __func__ << "filename empty";
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (!object) {
|
||||||
|
qDebug() << __func__ << "object null";
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
QString qDataDir = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
|
||||||
|
if (qDataDir == "") {
|
||||||
|
qDebug() << __func__ << "config path empty. abort";
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (is_write) {
|
||||||
|
QDir dir(qDataDir);
|
||||||
|
dir.mkpath(NAME);
|
||||||
|
}
|
||||||
|
QString path = qDataDir + "/" + NAME + "/" + filename;
|
||||||
|
|
||||||
|
QFile *file = new QFile(path);
|
||||||
|
|
||||||
|
if (!is_write && !file->exists()) {
|
||||||
|
qDebug() << __func__ << path << " don't exist";
|
||||||
|
delete file;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (!file->open(is_write ? (QIODevice::WriteOnly | QIODevice::Truncate) : QIODevice::ReadOnly)) {
|
||||||
|
qDebug() << __func__ << "file not opened";
|
||||||
|
delete file;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjectSaver::load()
|
||||||
|
{
|
||||||
|
QFile *file = getDataFile(false);
|
||||||
|
if (!file) return;
|
||||||
|
file->close();
|
||||||
|
delete file;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjectSaver::save()
|
||||||
|
{
|
||||||
|
QFile *file = getDataFile(true);
|
||||||
|
if (!file) return;
|
||||||
|
file->close();
|
||||||
|
delete file;
|
||||||
|
}
|
63
src/ObjectSaver.hpp
Normal file
63
src/ObjectSaver.hpp
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
/* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _OBJECT_SAVER_HPP
|
||||||
|
#define _OBJECT_SAVER_HPP
|
||||||
|
|
||||||
|
#include <QFile>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class to load/save qml objects simply,
|
||||||
|
* with limitations:
|
||||||
|
* - only 1 depth properties
|
||||||
|
* - double, int, string only (for the moment)
|
||||||
|
*/
|
||||||
|
class ObjectSaver : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
/// object to load/save
|
||||||
|
Q_PROPERTY(QObject* object READ getObject WRITE setObject NOTIFY objectChanged)
|
||||||
|
/// name of save file
|
||||||
|
Q_PROPERTY(QString filename READ getFilename WRITE setFilename)
|
||||||
|
|
||||||
|
private:
|
||||||
|
QObject *object;
|
||||||
|
QString filename;
|
||||||
|
|
||||||
|
QFile * getDataFile(bool is_write);
|
||||||
|
|
||||||
|
public:
|
||||||
|
ObjectSaver();
|
||||||
|
~ObjectSaver();
|
||||||
|
|
||||||
|
QString getFilename();
|
||||||
|
void setFilename(QString name);
|
||||||
|
QObject* getObject();
|
||||||
|
void setObject(QObject *obj);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
/// load the object. auto called if object and filename setted
|
||||||
|
void load();
|
||||||
|
/// save object to disk
|
||||||
|
void save();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void objectChanged();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -22,6 +22,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
|
#include "ObjectSaver.hpp"
|
||||||
#include "PitchDetection.hpp"
|
#include "PitchDetection.hpp"
|
||||||
#include "Tuner.hpp"
|
#include "Tuner.hpp"
|
||||||
|
|
||||||
|
@ -33,6 +34,7 @@ Q_DECL_EXPORT int main(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
qmlRegisterType<Tuner>("LJTuner", 1, 0, "Tuner");
|
qmlRegisterType<Tuner>("LJTuner", 1, 0, "Tuner");
|
||||||
|
qmlRegisterType<ObjectSaver>("LJUtils", 1, 0, "ObjectSaver");
|
||||||
|
|
||||||
QGuiApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
QQuickView view;
|
QQuickView view;
|
||||||
|
|
|
@ -53,6 +53,8 @@ Q_DECL_EXPORT int main(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
qmlRegisterType<Tuner>("harbour.sailtuner.tuner", 1, 0, "Tuner");
|
qmlRegisterType<Tuner>("harbour.sailtuner.tuner", 1, 0, "Tuner");
|
||||||
|
qmlRegisterType<ObjectSaver>("harbour.sailtuner.objectsaver", 1, 0, "ObjectSaver");
|
||||||
|
|
||||||
Main *appli = new Main(argc, argv);
|
Main *appli = new Main(argc, argv);
|
||||||
return appli->Launch();
|
return appli->Launch();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue