diff options
Diffstat (limited to 'migration')
| -rw-r--r-- | migration/20160906_00-mappings.cpp | 124 | ||||
| -rw-r--r-- | migration/20160906_01-axis-signs.cpp | 1 | ||||
| -rw-r--r-- | migration/20160917_00-accela.cpp | 121 | 
3 files changed, 65 insertions, 181 deletions
| diff --git a/migration/20160906_00-mappings.cpp b/migration/20160906_00-mappings.cpp index 4fac3a91..1ff02ce1 100644 --- a/migration/20160906_00-mappings.cpp +++ b/migration/20160906_00-mappings.cpp @@ -20,88 +20,94 @@  using namespace migrations; -struct mappings_from_2_3_0_rc11 : migration +static const char* old_names[] =  { -    static QList<QList<QPointF>> get_old_splines() -    { -        QList<QList<QPointF>> ret; +    "tx", "tx_alt", +    "ty", "ty_alt", +    "tz", "tz_alt", +    "rx", "rx_alt", +    "ry", "ry_alt", +    "rz", "rz_alt", +}; -        static const char* names[] = -        { -            "tx", "tx_alt", -            "ty", "ty_alt", -            "tz", "tz_alt", -            "rx", "rx_alt", -            "ry", "ry_alt", -            "rz", "rz_alt", -        }; - -        return group::with_settings_object([&](QSettings& settings) { -            for (const char* name : names) -            { -                QList<QPointF> points; +static const char* new_names[] = { +    "spline-X",       "alt-spline-X", +    "spline-Y",       "alt-spline-Y", +    "spline-Z",       "alt-spline-Z", +    "spline-yaw",     "alt-spline-yaw", +    "spline-pitch",   "alt-spline-pitch", +    "spline-roll",    "alt-spline-roll", +}; -                settings.beginGroup(QString("Curves-%1").arg(name)); +static QList<QList<QPointF>> get_old_splines() +{ +    QList<QList<QPointF>> ret; -                const int max = settings.value("point-count", 0).toInt(); +    return group::with_settings_object([&](QSettings& settings) { +        for (const char* name : old_names) +        { +            QList<QPointF> points; -                for (int i = 0; i < max; i++) -                { -                    QPointF new_point(settings.value(QString("point-%1-x").arg(i), 0).toDouble(), -                                      settings.value(QString("point-%1-y").arg(i), 0).toDouble()); +            settings.beginGroup(QString("Curves-%1").arg(name)); -                    points.append(new_point); -                } +            const int max = settings.value("point-count", 0).toInt(); -                settings.endGroup(); +            for (int i = 0; i < max; i++) +            { +                QPointF new_point(settings.value(QString("point-%1-x").arg(i), 0).toDouble(), +                                  settings.value(QString("point-%1-y").arg(i), 0).toDouble()); -                ret.append(points); +                points.append(new_point);              } -            return ret; -        }); -    } +            settings.endGroup(); + +            ret.append(points); +        } + +        return ret; +    }); +}; +struct mappings_from_2_3_0_rc11 : migration +{      QString unique_date() const override { return "20160909_00"; }      QString name() const override { return "mappings to new layout"; } -    static Mappings get_new_mappings() -    { -        main_settings s; -        return Mappings(s.all_axis_opts); -    } -      bool should_run() const override -    { -        Mappings m = get_new_mappings(); - -        // run only if no new splines were set -        for (int i = 0; i < 6; i++) -            if (m(i).spline_main.get_point_count() || m(i).spline_alt.get_point_count()) +    {         +        for (const char* name : new_names) +        { +            // run only if no new splines were set +            auto b = make_bundle(name); +            if (b->contains("points"))                  return false; -        // run only if old splines exist -        for (const QList<QPointF>& points : get_old_splines()) -            if (points.size()) -                return true; +            // run only if old splines exist +            for (const QList<QPointF>& points : get_old_splines()) +                if (points.size()) +                    return true; +        }          // no splines exit at all          return false;      } +      void run() override -    { -        const QList<QList<QPointF>> old_mappings = get_old_splines(); -        Mappings m = get_new_mappings(); +    {         +        group::with_settings_object([this](QSettings&) { +            const QList<QList<QPointF>> old_mappings = get_old_splines(); -        for (int i = 0; i < 12; i++) -        { -            spline& spl = (i % 2) == 0 ? m(i / 2).spline_main : m(i / 2).spline_alt; -            spl.clear(); -            const QList<QPointF>& points = old_mappings[i]; -            for (const QPointF& pt : points) -                spl.add_point(pt); -            spl.save(); -        } +            for (int i = 0; i < 12; i++) +            { +                auto b = make_bundle(new_names[i]); +                if (b->contains("points")) +                    continue; +                value<QList<QPointF>> new_value { b, "points", {} }; +                new_value = old_mappings[i]; +                b->save(); +            } +        });      }  }; diff --git a/migration/20160906_01-axis-signs.cpp b/migration/20160906_01-axis-signs.cpp index 0934990d..6dfa0d7c 100644 --- a/migration/20160906_01-axis-signs.cpp +++ b/migration/20160906_01-axis-signs.cpp @@ -8,7 +8,6 @@  #include "migration.hpp"  #include "options/options.hpp" -#include "logic/main-settings.hpp"  #include <QString>  #include <QVariant> diff --git a/migration/20160917_00-accela.cpp b/migration/20160917_00-accela.cpp deleted file mode 100644 index 33d85273..00000000 --- a/migration/20160917_00-accela.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* 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 "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"; - -    struct map_ { map s[8]; }; - -    static map_ make_settings(settings_accela& s) -    { -        map_ ret -        { -            { -                { "rotation-threshold", 4, 1, &s.rot_sensitivity }, -                { "translation-threshold", 4, 1, &s.pos_sensitivity }, -                { "rotation-deadzone", 4, 0, &s.rot_deadzone }, -                { "translation-deadzone", 4, 0, &s.pos_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; -        } - -        new_b->save(); -    } -}; - -// odr -constexpr settings_accela::gains settings_accela::rot_gains[16]; -constexpr settings_accela::gains settings_accela::pos_gains[16]; - -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); | 
