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

Annotation of /linuxsampler/trunk/src/engines/AbstractEngine.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2559 - (hide annotations) (download) (as text)
Sun May 18 17:38:25 2014 UTC (9 years, 11 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 9603 byte(s)
* Aftertouch: extended API to explicitly handle channel pressure and
  polyphonic key pressure events (so far polyphonic pressure was not
  supported at all, and channel pressure was rerouted as CC128 but not
  used so far).
* Gig Engine: Fixed support for 'aftertouch' attenuation controller.
* Bumped version (1.0.0.svn39).

1 iliev 2012 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * Copyright (C) 2003,2004 by Benno Senoner and Christian Schoenebeck *
6 persson 2072 * Copyright (C) 2005-2008 Christian Schoenebeck *
7 persson 2427 * Copyright (C) 2009-2013 Christian Schoenebeck and Grigor Iliev *
8 iliev 2012 * *
9     * This program is free software; you can redistribute it and/or modify *
10     * it under the terms of the GNU General Public License as published by *
11     * the Free Software Foundation; either version 2 of the License, or *
12     * (at your option) any later version. *
13     * *
14     * This program is distributed in the hope that it will be useful, *
15     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17     * GNU General Public License for more details. *
18     * *
19     * You should have received a copy of the GNU General Public License *
20     * along with this program; if not, write to the Free Software *
21     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
22     * MA 02111-1307 USA *
23     ***************************************************************************/
24    
25     #ifndef __LS_ABSTRACTENGINE_H__
26     #define __LS_ABSTRACTENGINE_H__
27    
28     #include "Engine.h"
29     #include "../common/ArrayList.h"
30     #include "../common/atomic.h"
31     #include "../common/ConditionServer.h"
32     #include "../common/Pool.h"
33     #include "../common/RingBuffer.h"
34 schoenebeck 2448 #include "../common/ChangeFlagRelaxed.h"
35 iliev 2012 #include "../drivers/audio/AudioOutputDevice.h"
36     #include "common/Event.h"
37 iliev 2296 #include "common/SignalUnitRack.h"
38 iliev 2012
39     namespace LinuxSampler {
40    
41     class AbstractEngineChannel;
42    
43     class AbstractEngine: public Engine {
44    
45     public:
46     enum Format { GIG = 1, SF2, SFZ };
47     static String GetFormatString(Format f);
48     static AbstractEngine* AcquireEngine(AbstractEngineChannel* pChannel, AudioOutputDevice* pDevice);
49     static void FreeEngine(AbstractEngineChannel* pChannel, AudioOutputDevice* pDevice);
50    
51     AbstractEngine();
52     virtual ~AbstractEngine();
53    
54     // implementation of abstract methods derived from class 'LinuxSampler::Engine'
55 schoenebeck 2434 virtual void SendSysex(void* pData, uint Size, MidiInputPort* pSender) OVERRIDE;
56     virtual void Reset() OVERRIDE;
57     virtual void Enable() OVERRIDE;
58     virtual void Disable() OVERRIDE;
59     virtual uint VoiceCount() OVERRIDE;
60     virtual uint VoiceCountMax() OVERRIDE;
61     virtual String EngineName() OVERRIDE;
62 schoenebeck 2448 virtual void AdjustScaleTuning(const int8_t ScaleTunes[12]) OVERRIDE;
63     virtual void GetScaleTuning(int8_t* pScaleTunes) OVERRIDE;
64     virtual void ResetScaleTuning() OVERRIDE;
65 iliev 2012
66     virtual Format GetEngineFormat() = 0;
67     virtual void Connect(AudioOutputDevice* pAudioOut) = 0;
68     virtual void DisableAndLock();
69    
70 persson 2427 void SetVoiceCount(uint Count);
71 iliev 2297
72     float Random() {
73     RandomSeed = RandomSeed * 1103515245 + 12345; // classic pseudo random number generator
74     return RandomSeed / 4294967296.0f;
75     }
76 persson 2427
77     // Simple array wrapper just to make sure memory is freed
78     // when liblinuxsampler is unloaded
79 iliev 2012 class FloatTable {
80     private:
81     const float* array;
82     public:
83     FloatTable(const float* array) : array(array) { }
84     ~FloatTable() { delete[] array; }
85     const float& operator[](int i) const { return array[i]; }
86     };
87    
88     static const FloatTable VolumeCurve; ///< Table that maps volume control change values 0..127 to amplitude. Unity gain is at 90.
89     static const FloatTable PanCurve; ///< Table that maps pan control change values 0..128 to right channel amplitude. Unity gain is at 64 (center).
90     static const FloatTable CrossfadeCurve; ///< Table that maps crossfade control change values 0..127 to amplitude. Unity gain is at 127.
91    
92     AudioOutputDevice* pAudioOutputDevice;
93 schoenebeck 2121
94     //TODO: should be protected
95     AudioChannel* pDedicatedVoiceChannelLeft; ///< encapsulates a special audio rendering buffer (left) for rendering and routing audio on a per voice basis (this is a very special case and only used for voices which lie on a note which was set with individual, dedicated FX send level)
96     AudioChannel* pDedicatedVoiceChannelRight; ///< encapsulates a special audio rendering buffer (right) for rendering and routing audio on a per voice basis (this is a very special case and only used for voices which lie on a note which was set with individual, dedicated FX send level)
97 iliev 2012
98 iliev 2015 friend class AbstractVoice;
99 iliev 2012 friend class AbstractEngineChannel;
100     template<class V, class R, class I> friend class EngineChannelBase;
101 iliev 2015 template<class EC, class R, class S, class D> friend class VoiceBase;
102 iliev 2012
103     protected:
104     ArrayList<EngineChannel*> engineChannels; ///< All engine channels of a Engine instance.
105     ConditionServer EngineDisabled;
106     int8_t ScaleTuning[12]; ///< contains optional detune factors (-64..+63 cents) for all 12 semitones of an octave
107 schoenebeck 2448 ChangeFlagRelaxed ScaleTuningChanged; ///< Boolean flag indicating whenever ScaleTuning has been modified by a foreign thread (i.e. by API).
108 iliev 2012 RingBuffer<Event,false>* pEventQueue; ///< Input event queue for engine global events (e.g. SysEx messages).
109     EventGenerator* pEventGenerator;
110     RTList<Event>* pGlobalEvents; ///< All engine global events for the current audio fragment (usually only SysEx messages).
111     Pool<Event>* pEventPool; ///< Contains all Event objects that can be used.
112 iliev 2027 RingBuffer<uint8_t,false>* pSysexBuffer; ///< Input buffer for MIDI system exclusive messages.
113 iliev 2012 uint SampleRate; ///< Sample rate of the engines output audio signal (in Hz)
114     uint MaxSamplesPerCycle; ///< Size of each audio output buffer
115 iliev 2027 unsigned long FrameTime; ///< Time in frames of the start of the current audio fragment
116 iliev 2012 int ActiveVoiceCountMax; ///< the maximum voice usage since application start
117 iliev 2027 atomic_t ActiveVoiceCount; ///< number of currently active voices
118     int VoiceSpawnsLeft; ///< We only allow CONFIG_MAX_VOICES voices to be spawned per audio fragment, we use this variable to ensure this limit.
119 iliev 2012
120     void RouteAudio(EngineChannel* pEngineChannel, uint Samples);
121 schoenebeck 2121 void RouteDedicatedVoiceChannels(EngineChannel* pEngineChannel, optional<float> FxSendLevels[2], uint Samples);
122 iliev 2012 void ClearEventLists();
123     void ImportEvents(uint Samples);
124     void ProcessSysex(Pool<Event>::Iterator& itSysexEvent);
125     void ProcessPitchbend(AbstractEngineChannel* pEngineChannel, Pool<Event>::Iterator& itPitchbendEvent);
126    
127     void ProcessFxSendControllers (
128     AbstractEngineChannel* pEngineChannel,
129     Pool<Event>::Iterator& itControlChangeEvent
130     );
131    
132     uint8_t GSCheckSum(const RingBuffer<uint8_t,false>::NonVolatileReader AddrReader, uint DataSize);
133    
134     virtual void ResetInternal() = 0;
135     virtual void KillAllVoices(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itKillEvent) = 0;
136     virtual void ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) = 0;
137     virtual void ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent) = 0;
138     virtual void ProcessControlChange(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itControlChangeEvent) = 0;
139 schoenebeck 2559 virtual void ProcessChannelPressure(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itChannelPressureEvent) = 0;
140     virtual void ProcessPolyphonicKeyPressure(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNotePressureEvent) = 0;
141 iliev 2015 virtual int GetMinFadeOutSamples() = 0;
142 iliev 2012
143     private:
144     static std::map<Format, std::map<AudioOutputDevice*,AbstractEngine*> > engines;
145 persson 2072 uint32_t RandomSeed; ///< State of the random number generator used by the random dimension.
146 iliev 2012
147     static float* InitVolumeCurve();
148     static float* InitPanCurve();
149     static float* InitCrossfadeCurve();
150     static float* InitCurve(const float* segments, int size = 128);
151    
152 schoenebeck 2121 bool RouteFxSend(FxSend* pFxSend, AudioChannel* ppSource[2], float FxSendLevel, uint Samples);
153 iliev 2012 };
154    
155     } // namespace LinuxSampler
156    
157     #endif /* __LS_ABSTRACTENGINE_H__ */
158    

  ViewVC Help
Powered by ViewVC