/* Copyright (c) 2012-2016, Stanislaw Halik * 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 "compat/qcopyable-mutex.hpp" #include "options/options.hpp" using namespace options; #include "export.hpp" #include #include #include #include #include #include #include namespace spline_detail { class OPENTRACK_SPLINE_EXPORT settings final : public QObject { Q_OBJECT public: bundle b; value> points; settings(bundle b); signals: void recomputed() const; }; } class OPENTRACK_SPLINE_EXPORT spline final { int precision(const QList& points) const; void update_interp_data(); float getValueInternal(int x); void add_lone_point(); static bool sort_fn(const QPointF& one, const QPointF& two); static QPointF ensure_in_bounds(const QList& points, int i); template static inline auto clamp(t val, u min, w max) -> decltype (val * min * max) { if (val > max) return max; if (val < min) return min; return val; } mem s; QMetaObject::Connection connection; std::vector data; using interp_data_t = decltype(data); static constexpr int value_count = 10000; MyMutex _mutex; QPointF last_input_value; qreal max_x, max_y; volatile bool activep; public: using settings = spline_detail::settings; void reload(); void save(QSettings& s); void save(); void set_bundle(bundle b); qreal maxInput() const; qreal maxOutput() const; spline(); spline(qreal maxx, qreal maxy, const QString& name); ~spline(); spline& operator=(const spline&) = default; spline(const spline&) = default; float getValue(double x); bool getLastPoint(QPointF& point); void removePoint(int i); void removeAllPoints(); void addPoint(QPointF pt); void movePoint(int idx, QPointF pt); QList getPoints() const; void setMaxInput(qreal MaxInput); void setMaxOutput(qreal MaxOutput); void setTrackingActive(bool blnActive); bundle get_bundle(); void recompute(); mem get_settings(); mem get_settings() const; using points_t = decltype(s->points.get()); };