/[svn]/linuxsampler/trunk/src/engines/gig/EGADSR.h
ViewVC logotype

Annotation of /linuxsampler/trunk/src/engines/gig/EGADSR.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3328 - (hide annotations) (download) (as text)
Sun Jul 23 18:27:29 2017 UTC (6 years, 10 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 6521 byte(s)
* gig Engine: Added support for controlling whether the individual
  EGADSR stages may be aborted (as LinuxSampler extension to the
  original GigaStudio 4 format).
* Bumped version (2.0.0.svn73).

1 schoenebeck 53 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5 schoenebeck 56 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 3328 * Copyright (C) 2005 - 2017 Christian Schoenebeck *
7 schoenebeck 53 * *
8     * This program is free software; you can redistribute it and/or modify *
9     * it under the terms of the GNU General Public License as published by *
10     * the Free Software Foundation; either version 2 of the License, or *
11     * (at your option) any later version. *
12     * *
13     * This program is distributed in the hope that it will be useful, *
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16     * GNU General Public License for more details. *
17     * *
18     * You should have received a copy of the GNU General Public License *
19     * along with this program; if not, write to the Free Software *
20     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21     * MA 02111-1307 USA *
22     ***************************************************************************/
23    
24     #ifndef __LS_GIG_EGADSR_H__
25     #define __LS_GIG_EGADSR_H__
26    
27 persson 2055 #include "../common/EG.h"
28 schoenebeck 53
29     namespace LinuxSampler { namespace gig {
30    
31     /**
32     * ADSR Envelope Generator
33     *
34     * Envelope Generator with stage 'Attack', 'Attack_Hold', 'Decay_1',
35     * 'Decay_2', 'Sustain' and 'Release' for modulating arbitrary synthesis
36     * parameters.
37     */
38 persson 2055 class EGADSR : public EG {
39 schoenebeck 53 public:
40 schoenebeck 3328 EGADSR();
41 schoenebeck 738
42     /**
43     * Will be called by the voice when the key / voice was triggered.
44     *
45     * @param PreAttack - Preattack value for the envelope
46     * (0 - 1000 permille)
47     * @param AttackTime - Attack time for the envelope
48     * (0.000 - 60.000s)
49     * @param HoldAttack - if true, Decay1 will be postponed until the
50     * sample reached the sample loop start.
51     * @param Decay1Time - Decay1 time of the sample amplitude EG
52     * (0.000 - 60.000s)
53     * @param Decay2Time - only if !InfiniteSustain: 2nd decay stage
54     * time of the sample amplitude EG
55     * (0.000 - 60.000s)
56     * @param InfiniteSustain - if true, instead of going into Decay2
57     * stage, Decay1 level will be hold until note
58     * will be released
59     * @param SustainLevel - Sustain level of the sample amplitude EG
60     * (0 - 1000 permille)
61     * @param ReleaseTIme - Release time for the envelope
62     * (0.000 - 60.000s)
63     * @param Volume - volume the sample will be played at
64     * (0.0 - 1.0) - used when calculating the
65     * exponential curve parameters.
66     * @param SampleRate - sample rate of used audio output driver
67     */
68 persson 783 void trigger(uint PreAttack, float AttackTime, bool HoldAttack, float Decay1Time, double Decay2Time, bool InfiniteSustain, uint SustainLevel, float ReleaseTime, float Volume, uint SampleRate); //FIXME: we should better use 'float' for SampleRate
69 schoenebeck 738
70 schoenebeck 3328 void setStateOptions(bool AttackCancel, bool AttackHoldCancel, bool Decay1Cancel, bool Decay2Cancel, bool ReleaseCancel);
71    
72 schoenebeck 738 /**
73     * Should be called to inform the EG about an external event and
74     * also whenever an envelope stage is completed. This will handle
75     * the envelope's transition to the respective next stage.
76     *
77     * @param Event - what happened
78     */
79 persson 783 void update(event_t Event, uint SampleRate);
80 schoenebeck 738
81     private:
82    
83 schoenebeck 53 enum stage_t {
84     stage_attack,
85     stage_attack_hold,
86 schoenebeck 738 stage_decay1_part1,
87 persson 614 stage_decay1_part2,
88 schoenebeck 53 stage_decay2,
89     stage_sustain,
90 schoenebeck 738 stage_release_part1,
91 persson 614 stage_release_part2,
92 schoenebeck 252 stage_fadeout,
93 schoenebeck 53 stage_end
94     };
95    
96 schoenebeck 738 stage_t Stage;
97 schoenebeck 3328 event_t PostponedEvent; ///< Only if *Cancel variable below is set to to false in the respective EG stage: holds the transition event type for processing after that current stage completed its full duration.
98 schoenebeck 738 bool HoldAttack;
99     bool InfiniteSustain;
100 schoenebeck 3328 bool AttackCancel; ///< Whether the "attack" stage is cancelled when receiving a note-off.
101     bool AttackHoldCancel; ///< Whether the "attack hold" stage is cancelled when receiving a note-off.
102     bool Decay1Cancel; ///< Whether the "decay 1" stage is cancelled when receiving a note-off.
103     bool Decay2Cancel; ///< Whether the "decay 2" stage is cancelled when receiving a note-off.
104     bool ReleaseCancel; ///< Whether the "release" stage is cancelled when receiving a note-on.
105 schoenebeck 738 float Decay1Time;
106     float Decay1Level2;
107     float Decay1Slope;
108     float Decay2Time;
109     float SustainLevel;
110     float ReleaseCoeff;
111     float ReleaseCoeff2;
112     float ReleaseCoeff3;
113     float ReleaseLevel2;
114     float ReleaseSlope;
115     float invVolume;
116     float ExpOffset;
117    
118 schoenebeck 3328 void enterNextStageForReleaseEvent(uint SampleRate);
119 persson 783 void enterAttackStage(const uint PreAttack, const float AttackTime, const uint SampleRate);
120     void enterAttackHoldStage();
121 schoenebeck 738 void enterDecay1Part1Stage(const uint SampleRate);
122 persson 768 void enterDecay1Part2Stage(const uint SampleRate);
123 schoenebeck 738 void enterDecay2Stage(const uint SampleRate);
124     void enterSustainStage();
125     void enterReleasePart1Stage();
126     void enterReleasePart2Stage();
127 schoenebeck 53 };
128    
129     }} // namespace LinuxSampler::gig
130    
131     #endif // __LS_GIG_EGADSR_H__

  ViewVC Help
Powered by ViewVC