LCOV - code coverage report
Current view: top level - src/engraving/compat/midi - easeinout.h Coverage Total Hit
Test: filtered_coverage.info Lines: 33.3 % 6 2
Test Date: 2026-11-05 04:07:02

            Line data    Source code
       1              : /*
       2              :  * SPDX-License-Identifier: GPL-3.0-only
       3              :  * MuseScore-Studio-CLA-applies
       4              :  *
       5              :  * MuseScore Studio
       6              :  * Music Composition & Notation
       7              :  *
       8              :  * Copyright (C) 2021 MuseScore Limited and others
       9              :  *
      10              :  * This program is free software: you can redistribute it and/or modify
      11              :  * it under the terms of the GNU General Public License version 3 as
      12              :  * published by the Free Software Foundation.
      13              :  *
      14              :  * This program is distributed in the hope that it will be useful,
      15              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      16              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17              :  * GNU General Public License for more details.
      18              :  *
      19              :  * You should have received a copy of the GNU General Public License
      20              :  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
      21              :  */
      22              : 
      23              : #ifndef MU_ENGRAVING_EASEINOUT_H
      24              : #define MU_ENGRAVING_EASEINOUT_H
      25              : 
      26              : #include <vector>
      27              : 
      28              : #include "draw/types/geometry.h"
      29              : 
      30              : namespace mu::engraving {
      31              : //---------------------------------------------------------
      32              : //   @@ EaseInOut
      33              : ///   \brief Specialized transfer curve using an underlying Bezier curve.
      34              : ///
      35              : ///   The second and third control points of the Bezier curve are moveable
      36              : ///   along the x axis according to two parameters 'EaseIn' and 'EaseOut',
      37              : ///   which results in a transfer curve that goes from a straight line to an S
      38              : ///   shaped curve.
      39              : //---------------------------------------------------------
      40              : 
      41              : class EaseInOut final
      42              : {
      43              : public:
      44              :     EaseInOut()
      45              :         : m_easeIn(0.0), m_easeOut(1.0) {}
      46            4 :     EaseInOut(double easeIn, double easeOut)
      47            4 :         : m_easeIn(easeIn), m_easeOut(easeOut) {}
      48              : 
      49              :     void SetEases(double easeIn, double easeOut) { m_easeIn = easeIn; m_easeOut = easeOut; }
      50            0 :     double EvalX(const double t) const
      51              :     {
      52            0 :         double tCompl = 1.0 - t;
      53            0 :         return (3.0 * m_easeIn * tCompl * tCompl + (3.0 - 3.0 * m_easeOut * tCompl - 2.0 * t) * t) * t;
      54              :     }
      55              : 
      56              :     double EvalY(const double t) const { return -(t * t) * (2.0 * t - 3.0); }
      57              :     muse::PointF Eval(const double t) const { return { EvalX(t), EvalY(t) }; }
      58              :     double tFromX(const double x) const;
      59              :     double tFromY(const double y) const;
      60              :     double YfromX(const double x) const { return EvalY(tFromX(x)); }
      61            0 :     double XfromY(const double y) const { return EvalX(tFromY(y)); }
      62              :     void timeList(const int nbNotes, const int duration, std::vector<int>* times) const;
      63              : 
      64              : private:
      65              :     double m_easeIn = 0.0;
      66              :     double m_easeOut = 0.0;
      67              : };
      68              : } // namespace mu::engraving
      69              : #endif
        

Generated by: LCOV version 2.0-1