summaryrefslogtreecommitdiffhomepage
path: root/migration/20160917_00-accela.cpp
blob: 714f5f9b28d7494deba490d2e741a242070d29a1 (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* Copyright (c) 2016, 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 "compat/util.hpp"

#include "filter-accela/accela-settings.hpp"

using namespace migrations;
using namespace options;

struct move_accela_to_sliders : migration
{
    struct map
    {
        const char* old_name;
        double old_max_100;
        double old_min;
        value<slider_value>* new_slider;
    };

    static constexpr const char* old_bundle_name = "Accela";
    static constexpr const char* new_bundle_name = "accela-sliders";
    static constexpr const char* slider_name = "rotation-nonlinearity";

    using map_ = struct { map s[8]; };

    static map_ make_settings(settings_accela& s)
    {
        map_ ret
        {
            {
                { "rotation-threshold", 4, 1, &s.rot_sensitivity },
                { "translation-threshold", 4, 1, &s.trans_sensitivity },
                { "rotation-deadzone", 4, 0, &s.rot_deadzone },
                { "translation-deadzone", 4, 0, &s.trans_deadzone },
                { "ewma", 1.25, 0, &s.ewma },
                { nullptr, 0, 0, nullptr },
            }
        };
        return ret;
    }

    move_accela_to_sliders() = default;

    QString unique_date() const override { return "20160917_00"; }
    QString name() const override { return "move accela to .ini sliders"; }

    bool should_run() const override
    {
        settings_accela s;
        map_ ss = make_settings(s);
        map* settings = ss.s;

        const bundle old_b = make_bundle(old_bundle_name);
        const bundle new_b = make_bundle(new_bundle_name);

        bool old_found = false;

        for (unsigned i = 0; settings[i].old_name; i++)
        {
            const map& cur = settings[i];
            if (new_b->contains(cur.new_slider->name()))
                return false;
            if (old_b->contains(cur.old_name))
                old_found = true;
        }

        old_found |= old_b->contains(slider_name);
        old_found &= !new_b->contains(slider_name);

        return old_found;
    }

    void run() override
    {
        settings_accela s;
        map_ ss = make_settings(s);
        map* settings = ss.s;

        bundle old_b = make_bundle(old_bundle_name);
        bundle new_b = make_bundle(new_bundle_name);

        for (unsigned i = 0; settings[i].old_name; i++)
        {
            const map& cur = settings[i];

            const slider_value val = progn(
                if (old_b->contains(cur.old_name))
                {
                    const double old = old_b->get<double>(cur.old_name);
                    return slider_value((cur.old_min + old) * cur.old_max_100 / 100.,
                                        cur.new_slider->default_value().min(),
                                        cur.new_slider->default_value().max());
                }
                else
                    return cur.new_slider->default_value();
            );

            value<slider_value> tmp(new_b, cur.new_slider->name(), slider_value(-1e6, val.min(), val.max()));
            tmp = val;
        }

        value<slider_value> tmp(new_b, slider_name, slider_value(-1e6, s.rot_nonlinearity().min(), s.rot_nonlinearity().max()));
        tmp = old_b->contains(slider_name)
                  ? old_b->get<slider_value>(slider_name)
                  : slider_value(1.1, 1, 1.75);

        new_b->save();
    }
};

// odr
constexpr double settings_accela::rot_gains[16][2];
constexpr double settings_accela::trans_gains[16][2];

constexpr const char* move_accela_to_sliders::old_bundle_name;
constexpr const char* move_accela_to_sliders::new_bundle_name;
constexpr const char* move_accela_to_sliders::slider_name;

OPENTRACK_MIGRATION(move_accela_to_sliders);