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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 239 - (show annotations) (download) (as text)
Sun Sep 12 14:48:19 2004 UTC (16 years, 1 month ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 9600 byte(s)
* implemented key groups (a.k.a exclusive groups) which is important for
  drum patches and monphonic instruments
* src/engines/gig/Engine.cpp: bugfix in ProcessNoteOn() - did not always
  stick the note on event to the respective key's own event list although
  e.g. the EGADRS expects it to find there

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
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_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 #include <map>
33
34 #include "../../common/RingBuffer.h"
35 #include "../../common/RTELMemoryPool.h"
36 #include "../../common/ConditionServer.h"
37 #include "../common/Engine.h"
38 #include "../common/Event.h"
39 #include "../common/BiquadFilter.h"
40 #include "../../lib/fileloader/libgig/gig.h"
41 #include "InstrumentResourceManager.h"
42 #include "../../network/lscp.h"
43
44 #define PITCHBEND_SEMITONES 12
45 #define MAX_AUDIO_VOICES 128
46
47 namespace LinuxSampler { namespace gig {
48
49 using std::map;
50
51 // just symbol prototyping
52 class Voice;
53 class DiskThread;
54 class InstrumentResourceManager;
55
56 /**
57 * Sampler engine for the Gigasampler format.
58 */
59 class gig::Engine : public LinuxSampler::Engine, public InstrumentConsumer {
60 public:
61 // methods
62 Engine();
63 ~Engine();
64
65 // abstract methods derived from class 'LinuxSampler::Engine'
66 virtual void LoadInstrument(const char* FileName, uint Instrument);
67 virtual void Reset();
68 virtual void Enable();
69 virtual void Disable();
70 virtual void SendNoteOn(uint8_t Key, uint8_t Velocity);
71 virtual void SendNoteOff(uint8_t Key, uint8_t Velocity);
72 virtual void SendPitchbend(int Pitch);
73 virtual void SendControlChange(uint8_t Controller, uint8_t Value);
74 virtual float Volume();
75 virtual void Volume(float f);
76 virtual uint Channels();
77 virtual void Connect(AudioOutputDevice* pAudioOut);
78 virtual void DisconnectAudioOutputDevice();
79 virtual void SetOutputChannel(uint EngineAudioChannel, uint AudioDeviceChannel);
80 virtual int OutputChannel(uint EngineAudioChannel);
81 virtual int RenderAudio(uint Samples);
82 virtual uint VoiceCount();
83 virtual uint VoiceCountMax();
84 virtual bool DiskStreamSupported();
85 virtual uint DiskStreamCount();
86 virtual uint DiskStreamCountMax();
87 virtual String DiskStreamBufferFillBytes();
88 virtual String DiskStreamBufferFillPercentage();
89 virtual String Description();
90 virtual String Version();
91 virtual String EngineName();
92 virtual String InstrumentFileName();
93 virtual int InstrumentIndex();
94 virtual int InstrumentStatus();
95
96 // abstract methods derived from interface class 'InstrumentConsumer'
97 virtual void ResourceToBeUpdated(::gig::Instrument* pResource, void*& pUpdateArg);
98 virtual void ResourceUpdated(::gig::Instrument* pOldResource, ::gig::Instrument* pNewResource, void* pUpdateArg);
99 protected:
100 struct midi_key_info_t {
101 RTEList<Voice>* pActiveVoices; ///< Contains the active voices associated with the MIDI key.
102 bool KeyPressed; ///< Is true if the respective MIDI key is currently pressed.
103 bool Active; ///< If the key contains active voices.
104 uint* pSelf; ///< hack to allow fast deallocation of the key from the list of active keys
105 RTEList<Event>* pEvents; ///< Key specific events (only Note-on, Note-off and sustain pedal currently)
106 };
107
108 static InstrumentResourceManager Instruments;
109
110 AudioOutputDevice* pAudioOutputDevice;
111 float* pOutputLeft; ///< Audio output channel buffer (left)
112 float* pOutputRight; ///< Audio output channel buffer (right)
113 int AudioDeviceChannelLeft; ///< audio device channel number to which the left channel is connected to
114 int AudioDeviceChannelRight; ///< audio device channel number to which the right channel is connected to
115 uint SampleRate; ///< Sample rate of the engines output audio signal (in Hz)
116 uint MaxSamplesPerCycle; ///< Size of each audio output buffer
117 DiskThread* pDiskThread;
118 uint8_t ControllerTable[128]; ///< Reflects the current values (0-127) of all MIDI controllers for this engine / sampler channel.
119 RingBuffer<Event>* pEventQueue; ///< Input event queue.
120 midi_key_info_t pMIDIKeyInfo[128]; ///< Contains all active voices sorted by MIDI key number and other informations to the respective MIDI key
121 RTELMemoryPool<Voice>* pVoicePool; ///< Contains all voices that can be activated.
122 RTELMemoryPool<uint>* pActiveKeys; ///< Holds all keys in it's allocation list with active voices.
123 RTELMemoryPool<Event>* pEventPool; ///< Contains all Event objects that can be used.
124 EventGenerator* pEventGenerator;
125 RTEList<Event>* pEvents; ///< All events for the current audio fragment.
126 RTEList<Event>* pCCEvents; ///< All control change events for the current audio fragment.
127 RTEList<Event>* pSynthesisEvents[Event::destination_count]; ///< Events directly affecting synthesis parameter (like pitch, volume and filter).
128 float* pSynthesisParameters[Event::destination_count]; ///< Matrix with final synthesis parameters for the current audio fragment which will be used in the main synthesis loop.
129 biquad_param_t* pBasicFilterParameters; ///< Biquad parameters of the basic bandpass filter.
130 biquad_param_t* pMainFilterParameters; ///< Main biquad parameters of the individual filter (lowpass / bandpass / highpass).
131 map<uint,uint*> ActiveKeyGroups; ///< Contains active keys (in case they belong to a key group) ordered by key group ID.
132 RIFF::File* pRIFF;
133 ::gig::File* pGig;
134 ::gig::Instrument* pInstrument;
135 bool SustainPedal; ///< true if sustain pedal is down
136 double GlobalVolume; ///< overall volume (a value < 1.0 means attenuation, a value > 1.0 means amplification)
137 int Pitch; ///< Current (absolute) MIDI pitch value.
138 int ActiveVoiceCount; ///< number of currently active voices
139 int ActiveVoiceCountMax; ///< the maximum voice usage since application start
140 bool SuspensionRequested;
141 ConditionServer EngineDisabled;
142 String InstrumentFile;
143 int InstrumentIdx;
144 int InstrumentStat;
145
146 void ProcessNoteOn(Event* pNoteOnEvent);
147 void ProcessNoteOff(Event* pNoteOffEvent);
148 void ProcessPitchbend(Event* pPitchbendEvent);
149 void ProcessControlChange(Event* pControlChangeEvent);
150 void LaunchVoice(Event* pNoteOnEvent, int iLayer = 0);
151 void KillVoiceImmediately(Voice* pVoice);
152 void ResetSynthesisParameters(Event::destination_t dst, float val);
153 void ResetInternal();
154
155 friend class Voice;
156 friend class EGADSR;
157 friend class EGDecay;
158 friend class VCAManipulator;
159 friend class VCFCManipulator;
160 friend class VCOManipulator;
161 friend class InstrumentResourceManager;
162 private:
163 void DisableAndLock();
164 };
165
166 }} // namespace LinuxSampler::gig
167
168 #endif // __LS_GIG_ENGINE_H__

  ViewVC Help
Powered by ViewVC