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

Contents of /linuxsampler/trunk/src/engines/gig/Voice.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3444 - (show annotations) (download) (as text)
Sun Dec 23 19:32:11 2018 UTC (3 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 7565 byte(s)
* Only play release trigger samples on sustain pedal up if this behaviour
  was explicitly requested by the instrument (otherwise only on note-off).
* Bumped version (2.1.0.svn2).

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 * Copyright (C) 2005 - 2008 Christian Schoenebeck *
7 * Copyright (C) 2009 Christian Schoenebeck and Grigor Iliev *
8 * Copyright (C) 2010 - 2016 Christian Schoenebeck and Andreas Persson *
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 as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the Free Software *
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
23 * MA 02111-1307 USA *
24 ***************************************************************************/
25
26 #ifndef __LS_GIG_VOICE_H__
27 #define __LS_GIG_VOICE_H__
28
29 #include "../../common/global_private.h"
30
31 #if AC_APPLE_UNIVERSAL_BUILD
32 # include <libgig/gig.h>
33 #else
34 # include <gig.h>
35 #endif
36
37 #include "../../common/RTMath.h"
38 #include "../../common/Pool.h"
39 #include "../../drivers/audio/AudioOutputDevice.h"
40 #include "Stream.h"
41 #include "DiskThread.h"
42 #include "EGADSR.h"
43 #include "EGDecay.h"
44 #include "Filter.h"
45 #include "../common/VoiceBase.h"
46 #include "SynthesisParam.h"
47 #include "SmoothVolume.h"
48 #include "EngineChannel.h"
49
50 namespace LinuxSampler { namespace gig {
51 class Engine;
52 class EngineChannel;
53
54 /** Gig Voice
55 *
56 * Renders a voice for the Gigasampler format.
57 */
58 class Voice : public LinuxSampler::VoiceBase<EngineChannel, ::gig::DimensionRegion, ::gig::Sample, DiskThread> {
59 public:
60 Voice();
61 virtual ~Voice();
62 void SetOutput(AudioOutputDevice* pAudioOutputDevice);
63 void SetEngine(LinuxSampler::Engine* pEngine);
64 void CalculateFadeOutCoeff(float FadeOutTime, float SampleRate);
65 virtual release_trigger_t GetReleaseTriggerFlags() OVERRIDE;
66
67 protected:
68 virtual SampleInfo GetSampleInfo() OVERRIDE;
69 virtual RegionInfo GetRegionInfo() OVERRIDE;
70 virtual InstrumentInfo GetInstrumentInfo() OVERRIDE;
71 virtual double CalculateCrossfadeVolume(uint8_t MIDIKeyVelocity) OVERRIDE;
72 virtual AbstractEngine* GetEngine() OVERRIDE { return (AbstractEngine*)pEngine; }
73 virtual double GetEG1ControllerValue(uint8_t MIDIKeyVelocity) OVERRIDE;
74 virtual EGInfo CalculateEG1ControllerInfluence(double eg1ControllerValue) OVERRIDE;
75 virtual void TriggerEG1(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) OVERRIDE;
76 virtual double GetEG2ControllerValue(uint8_t MIDIKeyVelocity) OVERRIDE;
77 virtual EGInfo CalculateEG2ControllerInfluence(double eg2ControllerValue) OVERRIDE;
78 virtual void TriggerEG2(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) OVERRIDE;
79 virtual void InitLFO1() OVERRIDE;
80 virtual void InitLFO2() OVERRIDE;
81 virtual void InitLFO3() OVERRIDE;
82 virtual float CalculateCutoffBase(uint8_t MIDIKeyVelocity) OVERRIDE;
83 virtual float CalculateFinalCutoff(float cutoffBase) OVERRIDE;
84 virtual uint8_t GetVCFCutoffCtrl() OVERRIDE;
85 virtual uint8_t GetVCFResonanceCtrl() OVERRIDE;
86 virtual void ProcessCCEvent(RTList<Event>::Iterator& itEvent) OVERRIDE;
87 virtual void ProcessChannelPressureEvent(RTList<Event>::Iterator& itEvent) OVERRIDE;
88 virtual void ProcessPolyphonicKeyPressureEvent(RTList<Event>::Iterator& itEvent) OVERRIDE;
89 virtual void ProcessCutoffEvent(RTList<Event>::Iterator& itEvent) OVERRIDE;
90 virtual double GetVelocityAttenuation(uint8_t MIDIKeyVelocity) OVERRIDE;
91 virtual double GetVelocityRelease(uint8_t MIDIKeyVelocity) OVERRIDE;
92 virtual double GetSampleAttenuation() OVERRIDE;
93 virtual void ProcessGroupEvent(RTList<Event>::Iterator& itEvent) OVERRIDE;
94 virtual int CalculatePan(uint8_t pan) OVERRIDE;
95
96 private:
97 EGADSR EG1;
98 EGADSR EG2;
99
100 public: // FIXME: just made public for debugging (sanity check in Engine::RenderAudio()), should be changed to private before the final release
101 // Attributes
102 Engine* pEngine; ///< Pointer to the sampler engine, to be able to access the event lists.
103 //uint LoopCyclesLeft; ///< In case there is a RAMLoop and it's not an endless loop; reflects number of loop cycles left to be passed
104
105 // Static Methods
106 static float CalculateFilterCutoffCoeff();
107
108 // Methods
109 void ProcessEvents(uint Samples);
110 void processCrossFadeEvent(RTList<Event>::Iterator& itEvent);
111
112 EngineChannel* GetGigEngineChannel();
113
114 protected:
115 virtual uint8_t CrossfadeAttenuation(uint8_t& CrossfadeControllerValue) OVERRIDE {
116 uint8_t c = std::max(CrossfadeControllerValue, pRegion->AttenuationControllerThreshold);
117 c = (!pRegion->Crossfade.out_end) ? c /* 0,0,0,0 means no crossfade defined */
118 : (c < pRegion->Crossfade.in_end) ?
119 ((c <= pRegion->Crossfade.in_start) ? 0
120 : 127 * (c - pRegion->Crossfade.in_start) / (pRegion->Crossfade.in_end - pRegion->Crossfade.in_start))
121 : (c <= pRegion->Crossfade.out_start) ? 127
122 : (c < pRegion->Crossfade.out_end) ? 127 * (pRegion->Crossfade.out_end - c) / (pRegion->Crossfade.out_end - pRegion->Crossfade.out_start)
123 : 0;
124 return pRegion->InvertAttenuationController ? 127 - c : c;
125 }
126
127 inline float Constrain(float ValueToCheck, float Min, float Max) {
128 if (ValueToCheck > Max) ValueToCheck = Max;
129 else if (ValueToCheck < Min) ValueToCheck = Min;
130 return ValueToCheck;
131 }
132 };
133
134 }} // namespace LinuxSampler::gig
135
136 #endif // __LS_GIG_VOICE_H__

  ViewVC Help
Powered by ViewVC