summaryrefslogtreecommitdiffhomepage
path: root/migration/20171020_00-max-pitch-output.cpp
blob: a5467b28b36a8ce59e4c3755b52aca2052530eb1 (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
/* Copyright (c) 2017, 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.
 */

#include "migration.hpp"
#include "options/options.hpp"
#include "logic/mappings.hpp"
#include "logic/main-settings.hpp"

#include <QString>

using namespace options;
using namespace migrations;

struct max_pitch_output : migration
{
    max_pitch_output() = default;

    QString unique_date() const override
    {
        return "20171020_00";
    }

    QString name() const override
    {
        return "max pitch output in mapping window";
    }

    bool should_run() const override
    {
        {
            static constexpr char const* name = "pitch-max-output-value";

            bundle b = make_bundle("opentrack-mappings");

            if (b->contains(name))
                return false;
        }

        main_settings s;
        Mappings m { s.all_axis_opts };

        Map& pitch_map = m(Pitch);
        spline& pitch_spline_1 = pitch_map.spline_main;
        spline& pitch_spline_2 = pitch_map.spline_alt;

        for (const spline& spl : { pitch_spline_1, pitch_spline_2 })
            for (QPointF& point : spl.get_points())
                if (point.y() - 1e-2 > 90)
                    return true;

        return false;
    }

    void run() override
    {
        main_settings s;
        axis_opts& pitch_opts = s.a_pitch;

        pitch_opts.clamp_y = axis_opts::o_r180;

        s.b_map->save();
    }
};

OPENTRACK_MIGRATION(max_pitch_output);