/[svn]/linuxsampler/trunk/src/engines/common/Fade.h
ViewVC logotype

Annotation of /linuxsampler/trunk/src/engines/common/Fade.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3561 - (hide annotations) (download) (as text)
Fri Aug 23 11:44:00 2019 UTC (4 years, 8 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 2992 byte(s)
NKSP: Added standard units support for numbers and final "!" operator:

* NKSP strictness: Variable names, function names and preprocessor condition
  names must start with a regular character (a-z or A-Z); starting them with
  a digit or underscore is no longer allowed.

* NKSP parser fix: equal comparison operator "=" and not equal comparison
  operator "#" must only accept integer operands.

* NKSP language: Implemented support for standard units like Hertz, seconds,
  Bel including support for metric unit prefixes; so one can now e.g.
  conveniently use numbers in scripts like "5us" meaning "5 microseconds",
  or e.g. "12kHz" meaning "12 kilo Hertz", or e.g. "-14mdB" meaning
  "minus 14 Millidecibel", or e.g. "28c" meaning "28 cents" (for tuning).

* NKSP language: Introduced "final" operator "!" which is specifically
  intended for synthesis parameter values to denote that the synthesis
  parameter value is intended to be the "final" value for that synthesis
  parameter that should explicitly be used by the engine and thus causing
  the sampler engine to ignore all other modulation sources for the same
  synthesis parameter (like e.g. LFO, EG); by simply prefixing a value,
  variable or formula with this new "!" operator the expression is marked as
  being "final".

* Bumped version (2.1.1.svn4).

1 schoenebeck 3246 /*
2 schoenebeck 3561 * Copyright (c) 2017 - 2019 Christian Schoenebeck
3 schoenebeck 3246 *
4     * http://www.linuxsampler.org
5     *
6     * This file is part of LinuxSampler and released under the same terms.
7     * See README file for details.
8     */
9    
10     #ifndef LS_FADE_H
11     #define LS_FADE_H
12    
13     #include "EaseInEaseOut.h"
14    
15     namespace LinuxSampler {
16    
17     #define DEFAULT_FADE_CURVE FADE_CURVE_EASE_IN_EASE_OUT
18    
19     enum fade_curve_t {
20     FADE_CURVE_LINEAR,
21     FADE_CURVE_EASE_IN_EASE_OUT,
22     };
23    
24     /** @brief Fades a value with a selected curve.
25     *
26     * Implements a smoothed transition from one value to another value in a
27     * requested amount of time, either with an ease-in and ease-out algorithm
28     * (default), or linear.
29     */
30     class Fade : public EaseInEaseOut {
31     public:
32     Fade() : EaseInEaseOut() {
33     curveType = DEFAULT_FADE_CURVE;
34 schoenebeck 3561 Final = false;
35 schoenebeck 3246 }
36    
37     /**
38     * Select another curve type for this Fade and immediately prepare this
39     * Fade for operation with the new curve type.
40     */
41     void setCurve(fade_curve_t curve, float sampleRate) {
42     curveType = curve;
43     fadeTo(endValue, duration, sampleRate);
44     }
45    
46     /**
47     * Only set the new curve type. It is your responsibility to prepare this
48     * Fade for subsequent operation, i.e. by calling fadeTo() afterwards,
49     * otherwise the result of render() calls will be undefined.
50     */
51     void setCurveOnly(fade_curve_t curve) {
52     curveType = curve;
53     }
54    
55     /**
56     * Fade the current value in @duration seconds to the new value reflected
57     * by @a endValue, assuming the given @a sampleRate.
58     */
59     void fadeTo(float endValue, float duration, float sampleRate) {
60     if (curveType == FADE_CURVE_EASE_IN_EASE_OUT)
61     return EaseInEaseOut::fadeTo(endValue, duration, sampleRate);
62     else {
63     if (duration <= 0.f) {
64     setCurrentValue(endValue);
65     return;
66     }
67     this->endValue = endValue;
68     steps = duration * sampleRate;
69     c = (endValue - value) / float(steps);
70     }
71     }
72    
73     /**
74     * Fade the current value in the currently set default duration to the new
75     * value reflected by @a endValue, assuming the given @a sampleRate.
76     */
77     void fadeTo(float endValue, float sampleRate) {
78     fadeTo(endValue, duration, sampleRate);
79     }
80    
81     /**
82     * Proceed transition by exactly one sample point and return the current
83     * smoothed value at this stage.
84     */
85     inline float render() {
86     if (curveType == FADE_CURVE_EASE_IN_EASE_OUT)
87     return EaseInEaseOut::render();
88     if (!steps) return endValue;
89     --steps;
90     value += c;
91     return value;
92     }
93    
94 schoenebeck 3561 inline void setFinal(bool b) {
95     Final = b;
96     }
97    
98     template<typename T>
99     inline void applyTo(T& dst) {
100     if (Final)
101     dst = currentValue();
102     else
103     dst *= currentValue();
104     }
105    
106 schoenebeck 3246 private:
107     fade_curve_t curveType;
108 schoenebeck 3561 bool Final;
109 schoenebeck 3246 };
110    
111     } // namespace LinuxSampler
112    
113     #endif // LS_FADE_H

  ViewVC Help
Powered by ViewVC