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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 392 - (hide annotations) (download) (as text)
Sat Feb 19 02:40:24 2005 UTC (19 years, 2 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 11901 byte(s)
* fixed possibility that memory got not locked
* immediately set instrument status when calling LOAD INSTUMENT NON_MODAL

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 53 * *
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_GIG_ENGINE_H__
24     #define __LS_GIG_ENGINE_H__
25    
26     #include "../../common/global.h"
27    
28     #if DEBUG_HEADERS
29     # warning Engine.h included
30     #endif // DEBUG_HEADERS
31    
32 schoenebeck 239 #include <map>
33    
34 schoenebeck 53 #include "../../common/RingBuffer.h"
35 schoenebeck 271 #include "../../common/Pool.h"
36 schoenebeck 53 #include "../../common/ConditionServer.h"
37     #include "../common/Engine.h"
38     #include "../common/Event.h"
39 schoenebeck 80 #include "../common/BiquadFilter.h"
40 schoenebeck 53 #include "../../lib/fileloader/libgig/gig.h"
41     #include "InstrumentResourceManager.h"
42     #include "../../network/lscp.h"
43    
44     #define PITCHBEND_SEMITONES 12
45 schoenebeck 80 #define MAX_AUDIO_VOICES 128
46 schoenebeck 244 #define SYSEX_BUFFER_SIZE 2048 // 2kB
47 schoenebeck 250 #define VOICE_STEAL_ALGORITHM voice_steal_algo_oldestkey ///< @see voice_steal_algo_t for available voice stealing algorithms
48 schoenebeck 53
49     namespace LinuxSampler { namespace gig {
50    
51 schoenebeck 239 using std::map;
52    
53 schoenebeck 53 // just symbol prototyping
54     class Voice;
55     class DiskThread;
56     class InstrumentResourceManager;
57    
58     /**
59     * Sampler engine for the Gigasampler format.
60     */
61 capela 268 class Engine : public LinuxSampler::Engine, public InstrumentConsumer {
62 schoenebeck 53 public:
63 schoenebeck 250 // types
64     enum voice_steal_algo_t {
65     voice_steal_algo_none,
66     voice_steal_algo_keymask,
67     voice_steal_algo_oldestkey
68     };
69    
70 schoenebeck 53 // methods
71     Engine();
72     ~Engine();
73    
74     // abstract methods derived from class 'LinuxSampler::Engine'
75 schoenebeck 392 virtual void PrepareLoadInstrument(const char* FileName, uint Instrument);
76     virtual void LoadInstrument();
77 schoenebeck 53 virtual void Reset();
78     virtual void Enable();
79     virtual void Disable();
80     virtual void SendNoteOn(uint8_t Key, uint8_t Velocity);
81     virtual void SendNoteOff(uint8_t Key, uint8_t Velocity);
82     virtual void SendPitchbend(int Pitch);
83     virtual void SendControlChange(uint8_t Controller, uint8_t Value);
84 schoenebeck 244 virtual void SendSysex(void* pData, uint Size);
85 schoenebeck 53 virtual float Volume();
86     virtual void Volume(float f);
87 schoenebeck 225 virtual uint Channels();
88 schoenebeck 53 virtual void Connect(AudioOutputDevice* pAudioOut);
89     virtual void DisconnectAudioOutputDevice();
90 schoenebeck 225 virtual void SetOutputChannel(uint EngineAudioChannel, uint AudioDeviceChannel);
91     virtual int OutputChannel(uint EngineAudioChannel);
92 schoenebeck 53 virtual int RenderAudio(uint Samples);
93     virtual uint VoiceCount();
94     virtual uint VoiceCountMax();
95     virtual bool DiskStreamSupported();
96     virtual uint DiskStreamCount();
97     virtual uint DiskStreamCountMax();
98     virtual String DiskStreamBufferFillBytes();
99     virtual String DiskStreamBufferFillPercentage();
100     virtual String Description();
101     virtual String Version();
102 senkov 112 virtual String EngineName();
103     virtual String InstrumentFileName();
104 senkov 376 virtual String InstrumentName();
105 senkov 112 virtual int InstrumentIndex();
106 capela 133 virtual int InstrumentStatus();
107 schoenebeck 53
108     // abstract methods derived from interface class 'InstrumentConsumer'
109     virtual void ResourceToBeUpdated(::gig::Instrument* pResource, void*& pUpdateArg);
110     virtual void ResourceUpdated(::gig::Instrument* pOldResource, ::gig::Instrument* pNewResource, void* pUpdateArg);
111 schoenebeck 319 //protected:
112 schoenebeck 53 struct midi_key_info_t {
113 schoenebeck 271 RTList<Voice>* pActiveVoices; ///< Contains the active voices associated with the MIDI key.
114 schoenebeck 242 bool KeyPressed; ///< Is true if the respective MIDI key is currently pressed.
115     bool Active; ///< If the key contains active voices.
116     bool ReleaseTrigger; ///< If we have to launch release triggered voice(s) when the key is released
117 schoenebeck 271 Pool<uint>::Iterator itSelf; ///< hack to allow fast deallocation of the key from the list of active keys
118     RTList<Event>* pEvents; ///< Key specific events (only Note-on, Note-off and sustain pedal currently)
119 schoenebeck 53 };
120    
121     static InstrumentResourceManager Instruments;
122    
123     AudioOutputDevice* pAudioOutputDevice;
124 schoenebeck 225 float* pOutputLeft; ///< Audio output channel buffer (left)
125     float* pOutputRight; ///< Audio output channel buffer (right)
126     int AudioDeviceChannelLeft; ///< audio device channel number to which the left channel is connected to
127     int AudioDeviceChannelRight; ///< audio device channel number to which the right channel is connected to
128     uint SampleRate; ///< Sample rate of the engines output audio signal (in Hz)
129     uint MaxSamplesPerCycle; ///< Size of each audio output buffer
130 schoenebeck 53 DiskThread* pDiskThread;
131     uint8_t ControllerTable[128]; ///< Reflects the current values (0-127) of all MIDI controllers for this engine / sampler channel.
132     RingBuffer<Event>* pEventQueue; ///< Input event queue.
133 schoenebeck 244 RingBuffer<uint8_t>* pSysexBuffer; ///< Input buffer for MIDI system exclusive messages.
134 schoenebeck 53 midi_key_info_t pMIDIKeyInfo[128]; ///< Contains all active voices sorted by MIDI key number and other informations to the respective MIDI key
135 schoenebeck 271 Pool<Voice>* pVoicePool; ///< Contains all voices that can be activated.
136     Pool<uint>* pActiveKeys; ///< Holds all keys in it's allocation list with active voices.
137     Pool<Event>* pEventPool; ///< Contains all Event objects that can be used.
138 schoenebeck 53 EventGenerator* pEventGenerator;
139 schoenebeck 271 RTList<Event>* pVoiceStealingQueue; ///< All voice-launching events which had to be postponed due to free voice shortage.
140     RTList<Event>* pEvents; ///< All events for the current audio fragment.
141     RTList<Event>* pCCEvents; ///< All control change events for the current audio fragment.
142     RTList<Event>* pSynthesisEvents[Event::destination_count]; ///< Events directly affecting synthesis parameter (like pitch, volume and filter).
143 schoenebeck 53 float* pSynthesisParameters[Event::destination_count]; ///< Matrix with final synthesis parameters for the current audio fragment which will be used in the main synthesis loop.
144 schoenebeck 80 biquad_param_t* pBasicFilterParameters; ///< Biquad parameters of the basic bandpass filter.
145     biquad_param_t* pMainFilterParameters; ///< Main biquad parameters of the individual filter (lowpass / bandpass / highpass).
146 schoenebeck 239 map<uint,uint*> ActiveKeyGroups; ///< Contains active keys (in case they belong to a key group) ordered by key group ID.
147 schoenebeck 53 RIFF::File* pRIFF;
148     ::gig::File* pGig;
149     ::gig::Instrument* pInstrument;
150     bool SustainPedal; ///< true if sustain pedal is down
151     double GlobalVolume; ///< overall volume (a value < 1.0 means attenuation, a value > 1.0 means amplification)
152     int Pitch; ///< Current (absolute) MIDI pitch value.
153 schoenebeck 354 int CurrentKeyDimension; ///< Current value (0-127) for the keyboard dimension, altered by pressing a keyswitching key.
154 schoenebeck 53 int ActiveVoiceCount; ///< number of currently active voices
155     int ActiveVoiceCountMax; ///< the maximum voice usage since application start
156     bool SuspensionRequested;
157     ConditionServer EngineDisabled;
158 senkov 112 String InstrumentFile;
159     int InstrumentIdx;
160 senkov 376 String InstrumentIdxName;
161 capela 133 int InstrumentStat;
162 schoenebeck 244 int8_t ScaleTuning[12]; ///< contains optional detune factors (-64..+63 cents) for all 12 semitones of an octave
163 schoenebeck 271 RTList<Voice>::Iterator itLastStolenVoice; ///< Only for voice stealing: points to the last voice which was theft in current audio fragment, NULL otherwise.
164     RTList<uint>::Iterator iuiLastStolenKey; ///< Only for voice stealing: key number of last key on which the last voice was theft in current audio fragment, NULL otherwise.
165 schoenebeck 285 int MaxFadeOutPos; ///< The last position in an audio fragment to allow a instant fade out (e.g. for voice stealing) without leading to clicks.
166 schoenebeck 53
167 schoenebeck 271 void ProcessNoteOn(Pool<Event>::Iterator& itNoteOnEvent);
168     void ProcessNoteOff(Pool<Event>::Iterator& itNoteOffEvent);
169     void ProcessPitchbend(Pool<Event>::Iterator& itPitchbendEvent);
170     void ProcessControlChange(Pool<Event>::Iterator& itControlChangeEvent);
171     void ProcessSysex(Pool<Event>::Iterator& itSysexEvent);
172 schoenebeck 287 Pool<Voice>::Iterator LaunchVoice(Pool<Event>::Iterator& itNoteOnEvent, int iLayer, bool ReleaseTriggerVoice, bool VoiceStealing);
173 schoenebeck 285 void StealVoice(Pool<Event>::Iterator& itNoteOnEvent);
174     void FreeVoice(Pool<Voice>::Iterator& itVoice);
175 schoenebeck 287 void FreeKey(midi_key_info_t* pKey);
176 schoenebeck 53 void ResetSynthesisParameters(Event::destination_t dst, float val);
177     void ResetInternal();
178    
179     friend class Voice;
180     friend class EGADSR;
181     friend class EGDecay;
182     friend class VCAManipulator;
183     friend class VCFCManipulator;
184     friend class VCOManipulator;
185     friend class InstrumentResourceManager;
186     private:
187 schoenebeck 244 void DisableAndLock();
188     uint8_t GSCheckSum(const RingBuffer<uint8_t>::NonVolatileReader AddrReader, uint DataSize);
189     void AdjustScale(int8_t ScaleTunes[12]);
190 schoenebeck 53 };
191    
192     }} // namespace LinuxSampler::gig
193    
194     #endif // __LS_GIG_ENGINE_H__

  ViewVC Help
Powered by ViewVC