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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2072 by persson, Sat Mar 20 11:37:52 2010 UTC revision 2600 by schoenebeck, Sat Jun 7 00:16:03 2014 UTC
# Line 4  Line 4 
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003,2004 by Benno Senoner and Christian Schoenebeck    *   *   Copyright (C) 2003,2004 by Benno Senoner and Christian Schoenebeck    *
6   *   Copyright (C) 2005-2008 Christian Schoenebeck                         *   *   Copyright (C) 2005-2008 Christian Schoenebeck                         *
7   *   Copyright (C) 2009-2010 Christian Schoenebeck and Grigor Iliev        *   *   Copyright (C) 2009-2013 Christian Schoenebeck and Grigor Iliev        *
8   *                                                                         *   *                                                                         *
9   *   This program is free software; you can redistribute it and/or modify  *   *   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  *   *   it under the terms of the GNU General Public License as published by  *
# Line 31  Line 31 
31  #include "../common/ConditionServer.h"  #include "../common/ConditionServer.h"
32  #include "../common/Pool.h"  #include "../common/Pool.h"
33  #include "../common/RingBuffer.h"  #include "../common/RingBuffer.h"
34    #include "../common/ChangeFlagRelaxed.h"
35    #include "../common/ResourceManager.h"
36  #include "../drivers/audio/AudioOutputDevice.h"  #include "../drivers/audio/AudioOutputDevice.h"
37  #include "common/Event.h"  #include "common/Event.h"
38    #include "common/SignalUnitRack.h"
39    #include "common/InstrumentScriptVM.h"
40    
41  namespace LinuxSampler {  namespace LinuxSampler {
42    
# Line 50  namespace LinuxSampler { Line 54  namespace LinuxSampler {
54              virtual ~AbstractEngine();              virtual ~AbstractEngine();
55    
56              // implementation of abstract methods derived from class 'LinuxSampler::Engine'              // implementation of abstract methods derived from class 'LinuxSampler::Engine'
57              virtual void   SendSysex(void* pData, uint Size, MidiInputPort* pSender);              virtual void   SendSysex(void* pData, uint Size, MidiInputPort* pSender) OVERRIDE;
58              virtual void   Reset();              virtual void   Reset() OVERRIDE;
59              virtual void   Enable();              virtual void   Enable() OVERRIDE;
60              virtual void   Disable();              virtual void   Disable() OVERRIDE;
61              virtual uint   VoiceCount();              virtual uint   VoiceCount() OVERRIDE;
62              virtual uint   VoiceCountMax();              virtual uint   VoiceCountMax() OVERRIDE;
63              virtual String EngineName();              virtual String EngineName() OVERRIDE;
64                virtual void   AdjustScaleTuning(const int8_t ScaleTunes[12]) OVERRIDE;
65                virtual void   GetScaleTuning(int8_t* pScaleTunes) OVERRIDE;
66                virtual void   ResetScaleTuning() OVERRIDE;
67    
68              virtual Format GetEngineFormat() = 0;              virtual Format GetEngineFormat() = 0;
69              virtual void   Connect(AudioOutputDevice* pAudioOut) = 0;              virtual void   Connect(AudioOutputDevice* pAudioOut) = 0;
70              virtual void   DisableAndLock();              virtual void   DisableAndLock();
71    
72              void SetVoiceCount(uint Count);// Simple array wrapper just to make sure memory is freed              void SetVoiceCount(uint Count);
73    
74                /**
75                 * Returns event with the given event ID.
76                 */
77                RTList<Event>::Iterator EventByID(int id) {
78                    return pEventPool->fromID(id);
79                }
80    
81                float Random() {
82                    RandomSeed = RandomSeed * 1103515245 + 12345; // classic pseudo random number generator
83                    return RandomSeed / 4294967296.0f;
84                }
85    
86                // Simple array wrapper just to make sure memory is freed
87              // when liblinuxsampler is unloaded              // when liblinuxsampler is unloaded
88              class FloatTable {              class FloatTable {
89              private:              private:
# Line 78  namespace LinuxSampler { Line 99  namespace LinuxSampler {
99              static const FloatTable CrossfadeCurve; ///< Table that maps crossfade control change values 0..127 to amplitude. Unity gain is at 127.              static const FloatTable CrossfadeCurve; ///< Table that maps crossfade control change values 0..127 to amplitude. Unity gain is at 127.
100    
101              AudioOutputDevice* pAudioOutputDevice;              AudioOutputDevice* pAudioOutputDevice;
102                
103                //TODO: should be protected
104                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)
105                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)
106    
107                typedef ResourceConsumer<VMParserContext> ScriptConsumer;
108    
109                class ScriptResourceManager : public ResourceManager<String, VMParserContext> {
110                    protected:
111                        // implementation of derived abstract methods from 'ResourceManager'
112                        virtual VMParserContext* Create(String Key, ScriptConsumer* pConsumer, void*& pArg);
113                        virtual void         Destroy(VMParserContext* pResource, void* pArg);
114                        virtual void         OnBorrow(VMParserContext* pResource, ScriptConsumer* pConsumer, void*& pArg) {} // ignore
115                    public:
116                        ScriptResourceManager(AbstractEngine* parent) : parent(parent) {}
117                        virtual ~ScriptResourceManager() {}
118                    private:
119                        AbstractEngine* parent;
120                } scripts;
121    
122              friend class AbstractVoice;              friend class AbstractVoice;
123              friend class AbstractEngineChannel;              friend class AbstractEngineChannel;
# Line 88  namespace LinuxSampler { Line 128  namespace LinuxSampler {
128              ArrayList<EngineChannel*>  engineChannels; ///< All engine channels of a Engine instance.              ArrayList<EngineChannel*>  engineChannels; ///< All engine channels of a Engine instance.
129              ConditionServer            EngineDisabled;              ConditionServer            EngineDisabled;
130              int8_t                     ScaleTuning[12];    ///< contains optional detune factors (-64..+63 cents) for all 12 semitones of an octave              int8_t                     ScaleTuning[12];    ///< contains optional detune factors (-64..+63 cents) for all 12 semitones of an octave
131                ChangeFlagRelaxed          ScaleTuningChanged; ///< Boolean flag indicating whenever ScaleTuning has been modified by a foreign thread (i.e. by API).
132              RingBuffer<Event,false>*   pEventQueue;        ///< Input event queue for engine global events (e.g. SysEx messages).              RingBuffer<Event,false>*   pEventQueue;        ///< Input event queue for engine global events (e.g. SysEx messages).
133              EventGenerator*            pEventGenerator;              EventGenerator*            pEventGenerator;
134              RTList<Event>*             pGlobalEvents;         ///< All engine global events for the current audio fragment (usually only SysEx messages).              RTList<Event>*             pGlobalEvents;         ///< All engine global events for the current audio fragment (usually only SysEx messages).
# Line 99  namespace LinuxSampler { Line 140  namespace LinuxSampler {
140              int                        ActiveVoiceCountMax;   ///< the maximum voice usage since application start              int                        ActiveVoiceCountMax;   ///< the maximum voice usage since application start
141              atomic_t                   ActiveVoiceCount;      ///< number of currently active voices              atomic_t                   ActiveVoiceCount;      ///< number of currently active voices
142              int                        VoiceSpawnsLeft;       ///< We only allow CONFIG_MAX_VOICES voices to be spawned per audio fragment, we use this variable to ensure this limit.              int                        VoiceSpawnsLeft;       ///< We only allow CONFIG_MAX_VOICES voices to be spawned per audio fragment, we use this variable to ensure this limit.
143                InstrumentScriptVM*        pScriptVM; ///< Real-time instrument script virtual machine runner for this engine.
144    
145              void RouteAudio(EngineChannel* pEngineChannel, uint Samples);              void RouteAudio(EngineChannel* pEngineChannel, uint Samples);
146                void RouteDedicatedVoiceChannels(EngineChannel* pEngineChannel, optional<float> FxSendLevels[2], uint Samples);
147              void ClearEventLists();              void ClearEventLists();
148              void ImportEvents(uint Samples);              void ImportEvents(uint Samples);
149              void ProcessSysex(Pool<Event>::Iterator& itSysexEvent);              void ProcessSysex(Pool<Event>::Iterator& itSysexEvent);
             void ResetScaleTuning();  
150              void ProcessPitchbend(AbstractEngineChannel* pEngineChannel, Pool<Event>::Iterator& itPitchbendEvent);              void ProcessPitchbend(AbstractEngineChannel* pEngineChannel, Pool<Event>::Iterator& itPitchbendEvent);
151    
152              void ProcessFxSendControllers (              void ProcessFxSendControllers (
# Line 114  namespace LinuxSampler { Line 156  namespace LinuxSampler {
156    
157              uint8_t GSCheckSum(const RingBuffer<uint8_t,false>::NonVolatileReader AddrReader, uint DataSize);              uint8_t GSCheckSum(const RingBuffer<uint8_t,false>::NonVolatileReader AddrReader, uint DataSize);
158    
             float Random() {  
                 RandomSeed = RandomSeed * 1103515245 + 12345; // classic pseudo random number generator  
                 return RandomSeed / 4294967296.0f;  
             }  
   
159              virtual void ResetInternal() = 0;              virtual void ResetInternal() = 0;
160              virtual void KillAllVoices(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itKillEvent) = 0;              virtual void KillAllVoices(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itKillEvent) = 0;
161              virtual void ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) = 0;              virtual void ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) = 0;
162              virtual void ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent) = 0;              virtual void ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent) = 0;
163              virtual void ProcessControlChange(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itControlChangeEvent) = 0;              virtual void ProcessControlChange(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itControlChangeEvent) = 0;
164                virtual void ProcessChannelPressure(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itChannelPressureEvent) = 0;
165                virtual void ProcessPolyphonicKeyPressure(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNotePressureEvent) = 0;
166              virtual int  GetMinFadeOutSamples() = 0;              virtual int  GetMinFadeOutSamples() = 0;
167                virtual InstrumentScriptVM* CreateInstrumentScriptVM();
168    
169          private:          private:
170              static std::map<Format, std::map<AudioOutputDevice*,AbstractEngine*> > engines;              static std::map<Format, std::map<AudioOutputDevice*,AbstractEngine*> > engines;
# Line 135  namespace LinuxSampler { Line 175  namespace LinuxSampler {
175              static float* InitCrossfadeCurve();              static float* InitCrossfadeCurve();
176              static float* InitCurve(const float* segments, int size = 128);              static float* InitCurve(const float* segments, int size = 128);
177    
178              void AdjustScale(int8_t ScaleTunes[12]);              bool RouteFxSend(FxSend* pFxSend, AudioChannel* ppSource[2], float FxSendLevel, uint Samples);
179      };      };
180    
181  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.2072  
changed lines
  Added in v.2600

  ViewVC Help
Powered by ViewVC