1 //============================================================================= 2 // MuseScore 3 // Music Composition & Notation 4 // 5 // Copyright (C) 2020 MuseScore BVBA 6 // 7 // This program is free software; you can redistribute it and/or modify 8 // it under the terms of the GNU General Public License version 2 9 // as published by the Free Software Foundation and appearing in 10 // the file LICENCE.GPL 11 //============================================================================= 12 13 #ifndef __EASEINOUT_H__ 14 #define __EASEINOUT_H__ 15 16 namespace Ms { 17 18 //--------------------------------------------------------- 19 // @@ EaseInOut 20 /// \brief Specialized transfer curve using an underlying Bezier curve. 21 /// 22 /// The second and third control points of the Bezier curve are moveable 23 /// along the x axis according to two parameters 'EaseIn' and 'EaseOut', 24 /// which results in a transfer curve that goes from a straight line to an S 25 /// shaped curve. 26 //--------------------------------------------------------- 27 28 class EaseInOut final { 29 qreal _easeIn; 30 qreal _easeOut; 31 32 public: EaseInOut()33 EaseInOut() : _easeIn(0.0), _easeOut(1.0) {} EaseInOut(qreal easeIn,qreal easeOut)34 EaseInOut(qreal easeIn, qreal easeOut) : _easeIn(easeIn), _easeOut(easeOut) {} 35 SetEases(qreal easeIn,qreal easeOut)36 void SetEases(qreal easeIn, qreal easeOut) { _easeIn = easeIn; _easeOut = easeOut; } EvalX(const qreal t)37 qreal EvalX(const qreal t) const { qreal tCompl = 1.0 - t; return (3.0 * _easeIn * tCompl * tCompl + (3.0 - 3.0 * _easeOut * tCompl - 2.0 * t) * t) * t; } EvalY(const qreal t)38 qreal EvalY(const qreal t) const { return -(t * t) * (2.0 * t - 3.0); } Eval(const qreal t)39 QPointF Eval(const qreal t) const { return {EvalX(t), EvalY(t)}; } 40 qreal tFromX(const qreal x) const; 41 qreal tFromY(const qreal y) const; YfromX(const qreal x)42 qreal YfromX(const qreal x) const { return EvalY(tFromX(x)); } XfromY(const qreal y)43 qreal XfromY(const qreal y) const { return EvalX(tFromY(y)); } 44 void timeList(const int nbNotes, const int duration, QList<int>* times) const; 45 }; 46 47 } // namespace Ms 48 #endif