summaryrefslogtreecommitdiffhomepage
path: root/qfunctionconfigurator/functionconfig.h
blob: 66e7f3e8b872ddd4553d2225f0f9e1fa79406907 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* Copyright (c) 2011-2014, Stanislaw Halik <sthalik@misaki.pl>

 * Permission to use, copy, modify, and/or distribute this
 * software for any purpose with or without fee is hereby granted,
 * provided that the above copyright notice and this permission
 * notice appear in all copies.
 */

#pragma once

#include <QList>
#include <QPointF>
#include <QString>
#include <QSettings>
#include <QMutex>
#include "facetracknoir/plugin-api.hpp"
#include <vector>

#define MEMOIZE_PRECISION 100

class MyMutex {
private:
    QMutex inner;
    
public:
    QMutex* operator->() { return &inner; }
    QMutex* operator->() const { return &const_cast<MyMutex*>(this)->inner; }
    
    MyMutex operator=(const MyMutex& datum)
    {
        auto mode =
                datum->isRecursive()
                ? QMutex::Recursive
                : QMutex::NonRecursive;
        
        return MyMutex(mode);
    }
    
    MyMutex(const MyMutex& datum)
    {
        *this = datum;
    }
    
    MyMutex(QMutex::RecursionMode mode = QMutex::NonRecursive) :
        inner(mode)
    {
    }
    
    QMutex* operator&()
    {
        return &inner;
    }
};

class OPENTRACK_EXPORT FunctionConfig {
private:
    void reload();
    float getValueInternal(int x);
    
    MyMutex _mutex;
	QList<QPointF> input;
    std::vector<float> data;
	QPointF last_input_value;
    volatile bool activep;
	int max_x;
	int max_y;
public:
    int maxInput() const { return max_x; }
    int maxOutput() const { return max_y; }
    FunctionConfig();
    FunctionConfig(int maxx, int maxy)
    {
        setMaxInput(maxx);
        setMaxOutput(maxy);
    }

    float getValue(float x);
	bool getLastPoint(QPointF& point);
	void removePoint(int i);
    void removeAllPoints() {
        QMutexLocker foo(&_mutex);
        input.clear();
        reload();
    }

	void addPoint(QPointF pt);
	void movePoint(int idx, QPointF pt);
	const QList<QPointF> getPoints();
	void setMaxInput(int MaxInput) {
		max_x = MaxInput;
	}
	void setMaxOutput(int MaxOutput) {
		max_y = MaxOutput;
	}

	void saveSettings(QSettings& settings, const QString& title);
	void loadSettings(QSettings& settings, const QString& title);

	void setTrackingActive(bool blnActive);
};