1 /***************************************************************************
2  *                                                                         *
3  *   LinuxSampler - modular, streaming capable sampler                     *
4  *                                                                         *
5  *   Copyright (C) 2011 - 2012 Grigor Iliev                                *
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 as published by  *
9  *   the Free Software Foundation; either version 2 of the License, or     *
10  *   (at your option) any later version.                                   *
11  *                                                                         *
12  *   This program is distributed in the hope that it will be useful,       *
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
15  *   GNU General Public License for more details.                          *
16  *                                                                         *
17  *   You should have received a copy of the GNU General Public License     *
18  *   along with this program; if not, write to the Free Software           *
19  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *
20  *   MA  02111-1307  USA                                                   *
21  ***************************************************************************/
22 
23 #ifndef __LS_SF2SIGNALUNITRACK_H__
24 #define	__LS_SF2SIGNALUNITRACK_H__
25 
26 #include "../common/SignalUnitRack.h"
27 #include "../sfz/EGADSR.h"
28 #include "../common/AbstractVoice.h"
29 
30 namespace LinuxSampler { namespace sf2 {
31     const int MaxUnitCount = 5;
32 
33     class Voice;
34     class SF2SignalUnitRack;
35 
36     class SFSignalUnit: public SignalUnit {
37         public:
38             Voice* pVoice;
39 
40             SFSignalUnit(SF2SignalUnitRack* rack);
41     };
42 
43     class EGUnit : public SFSignalUnit, public ::LinuxSampler::sfz::EGADSR {
44         public:
EGUnit(SF2SignalUnitRack * rack)45             EGUnit(SF2SignalUnitRack* rack): SFSignalUnit(rack) { }
46 
Active()47             virtual bool  Active() OVERRIDE { return active(); }
GetLevel()48             virtual float GetLevel() OVERRIDE { return getLevel(); }
49             virtual void  EnterReleaseStage() OVERRIDE;
50             virtual void  CancelRelease() OVERRIDE;
51     };
52 
53     class VolEGUnit : public EGUnit {
54         public:
VolEGUnit(SF2SignalUnitRack * rack)55             VolEGUnit(SF2SignalUnitRack* rack): EGUnit(rack) { }
56 
57             virtual void  Trigger() OVERRIDE;
58             virtual void  Increment() OVERRIDE;
59     };
60 
61     class ModEGUnit : public EGUnit {
62         public:
ModEGUnit(SF2SignalUnitRack * rack)63             ModEGUnit(SF2SignalUnitRack* rack): EGUnit(rack) { }
64 
65             virtual void  Trigger() OVERRIDE;
66             virtual void  Increment() OVERRIDE;
67     };
68 
69     class ModLfoUnit : public SFSignalUnit, public LFOTriangleSigned {
70         public:
ModLfoUnit(SF2SignalUnitRack * rack)71             ModLfoUnit(SF2SignalUnitRack* rack): SFSignalUnit(rack), LFOTriangleSigned(1200.0f) { }
Active()72             virtual bool  Active() OVERRIDE { return true; }
73             virtual void  Trigger() OVERRIDE;
74             virtual void  Increment() OVERRIDE;
GetLevel()75             virtual float GetLevel() OVERRIDE { return Level; }
76     };
77 
78     class VibLfoUnit : public SFSignalUnit, public LFOTriangleSigned {
79         public:
VibLfoUnit(SF2SignalUnitRack * rack)80             VibLfoUnit(SF2SignalUnitRack* rack): SFSignalUnit(rack), LFOTriangleSigned(1200.0f) { }
Active()81             virtual bool  Active() OVERRIDE { return true; }
82             virtual void  Trigger() OVERRIDE;
83             virtual void  Increment() OVERRIDE;
GetLevel()84             virtual float GetLevel() OVERRIDE { return Level; }
85     };
86 
87     class EndpointUnit : public EndpointSignalUnit {
88         public:
89             Voice* pVoice;
90 
91             Parameter *prmVolEg, *prmModEgPitch, *prmModEgCutoff, *prmModLfoVol,
92                       *prmModLfoPitch, *prmModLfoCutoff, *prmVibLfo;
93 
94             EndpointUnit(SF2SignalUnitRack* rack);
95 
96             virtual void Trigger() OVERRIDE;
97 
98             /** The endpoint should be active until the volume EG is active. */
99             virtual bool Active() OVERRIDE;
100 
101             virtual float GetVolume() OVERRIDE;
102             virtual float GetFilterCutoff() OVERRIDE;
103             virtual float GetPitch() OVERRIDE;
104             virtual float GetResonance() OVERRIDE;
GetPan()105             virtual float GetPan() OVERRIDE { return 0; }
CalculatePan(int pan)106             virtual uint8_t CalculatePan(int pan) OVERRIDE { return pan; }
107     };
108 
109     class SF2SignalUnitRack : public SignalUnitRack {
110         private:
111             VolEGUnit     suVolEG;
112             ModEGUnit     suModEG;
113             ModLfoUnit    suModLfo;
114             VibLfoUnit    suVibLfo;
115             EndpointUnit  suEndpoint;
116 
117 
118         public:
119             Voice* const pVoice;
120 
121             /**
122              * @param Voice The voice to which this rack belongs.
123              */
124             SF2SignalUnitRack(Voice* Voice);
125 
126             virtual EndpointSignalUnit* GetEndpointUnit() OVERRIDE;
127             virtual void EnterFadeOutStage() OVERRIDE;
128             virtual void EnterFadeOutStage(int maxFadeOutSteps) OVERRIDE;
129 
130             void CalculateFadeOutCoeff(float FadeOutTime, float SampleRate);
131 
UpdateEqSettings(EqSupport * pEqSupport)132             virtual void UpdateEqSettings(EqSupport* pEqSupport) OVERRIDE { }
133     };
134 
135 }} // namespace LinuxSampler::sf2
136 
137 #endif	/* __LS_SF2SIGNALUNITRACK_H__ */
138